From 6a9ffae25de1dc7cb94ac2796cd27e58df6c1d41 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 3 Apr 2015 08:31:50 +0200 Subject: [PATCH] New tests and factories. --- composer.json | 4 +- composer.lock | 121 +++++++++++++++++++- tests/controllers/AccountControllerTest.php | 23 ++-- tests/factories/all.php | 35 ++++++ 4 files changed, 169 insertions(+), 14 deletions(-) create mode 100644 tests/factories/all.php diff --git a/composer.json b/composer.json index 6f7c67a54c..c9459d4f3f 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,9 @@ "phpunit/phpunit": "~4.0", "phpspec/phpspec": "~2.1", "satooshi/php-coveralls": "0.6.1", - "mockery/mockery": "0.9.*" + "mockery/mockery": "0.9.*", + "league/factory-muffin": "~2.1" + }, "autoload": { diff --git a/composer.lock b/composer.lock index 02f5c8cbc7..889d37ed8f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "ef4d2cfd4c5768b32c52a1738045d66c", + "hash": "0d43c4c85607c5cdc901cde2d18b75d5", "packages": [ { "name": "classpreloader/classpreloader", @@ -945,16 +945,16 @@ }, { "name": "laravel/framework", - "version": "v5.0.25", + "version": "v5.0.26", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "c6f290f3ccbff16749a50f125c407ae7a492ad32" + "reference": "8e53c33e144f94032cc6ecbfee0be2a96ed63be0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/c6f290f3ccbff16749a50f125c407ae7a492ad32", - "reference": "c6f290f3ccbff16749a50f125c407ae7a492ad32", + "url": "https://api.github.com/repos/laravel/framework/zipball/8e53c33e144f94032cc6ecbfee0be2a96ed63be0", + "reference": "8e53c33e144f94032cc6ecbfee0be2a96ed63be0", "shasum": "" }, "require": { @@ -1067,7 +1067,7 @@ "framework", "laravel" ], - "time": "2015-04-02 18:42:46" + "time": "2015-04-03 02:58:05" }, { "name": "league/commonmark", @@ -2572,6 +2572,54 @@ ], "time": "2014-10-13 12:58:55" }, + { + "name": "fzaninotto/faker", + "version": "v1.4.0", + "source": { + "type": "git", + "url": "https://github.com/fzaninotto/Faker.git", + "reference": "010c7efedd88bf31141a02719f51fb44c732d5a0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/010c7efedd88bf31141a02719f51fb44c732d5a0", + "reference": "010c7efedd88bf31141a02719f51fb44c732d5a0", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.0", + "squizlabs/php_codesniffer": "~1.5" + }, + "type": "library", + "extra": { + "branch-alias": [] + }, + "autoload": { + "psr-0": { + "Faker": "src/", + "Faker\\PHPUnit": "test/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "François Zaninotto" + } + ], + "description": "Faker is a PHP library that generates fake data for you.", + "keywords": [ + "data", + "faker", + "fixtures" + ], + "time": "2014-06-04 14:43:02" + }, { "name": "guzzle/guzzle", "version": "v3.9.3", @@ -2712,6 +2760,67 @@ ], "time": "2015-01-20 19:34:09" }, + { + "name": "league/factory-muffin", + "version": "v2.1.1", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/factory-muffin.git", + "reference": "91f0adcdac6b5f7bf2277ac2c90f94352afe65de" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/factory-muffin/zipball/91f0adcdac6b5f7bf2277ac2c90f94352afe65de", + "reference": "91f0adcdac6b5f7bf2277ac2c90f94352afe65de", + "shasum": "" + }, + "require": { + "fzaninotto/faker": "1.4.*", + "php": ">=5.3.3" + }, + "replace": { + "zizaco/factory-muff": "self.version" + }, + "require-dev": { + "illuminate/database": "~4.1", + "phpunit/phpunit": "~4.0" + }, + "suggest": { + "illuminate/database": "Factory Muffin works well with eloquent models." + }, + "type": "library", + "autoload": { + "psr-4": { + "League\\FactoryMuffin\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "graham@mineuk.com" + }, + { + "name": "Zizaco Zizuini", + "email": "zizaco@gmail.com" + }, + { + "name": "Scott Robertson", + "email": "scottymeuk@gmail.com" + } + ], + "description": "The goal of this package is to enable the rapid creation of objects for the purpose of testing.", + "homepage": "http://factory-muffin.thephpleague.com/", + "keywords": [ + "factory", + "laravel", + "testing" + ], + "time": "2014-09-18 18:29:06" + }, { "name": "maximebf/debugbar", "version": "v1.10.4", diff --git a/tests/controllers/AccountControllerTest.php b/tests/controllers/AccountControllerTest.php index e25811193d..6f12ff3a80 100644 --- a/tests/controllers/AccountControllerTest.php +++ b/tests/controllers/AccountControllerTest.php @@ -1,6 +1,8 @@ be(new FireflyIII\User); - - $pref = new Preference; + $pref = FactoryMuffin::create('FireflyIII\Models\Preference'); $pref->data = '1M'; + $this->be($pref->user); + // CURRENCY: $currency = new TransactionCurrency; @@ -42,9 +43,8 @@ class AccountControllerTest extends TestCase Preferences::shouldReceive('get', 'viewRange')->andReturn($pref); Amount::shouldReceive('getDefaultCurrency')->andReturn($currency); Amount::shouldReceive('getAllCurrencies')->andReturn([$currency]); - // get all currencires? - $response = $this->call('GET', '/accounts/create/asset'); + $this->call('GET', '/accounts/create/asset'); $this->assertResponseOk(); @@ -56,7 +56,16 @@ class AccountControllerTest extends TestCase public function testDelete() { - $this->markTestIncomplete(); + // fake an account. + $account = FactoryMuffin::create('FireflyIII\Models\Account'); + $account->accountType->type = 'Asset account'; + $account->accountType->save(); + + $this->be($account->user); + $this->call('GET', '/accounts/delete/' . $account->id); + $this->assertResponseOk(); + $this->assertViewHas('subTitle', 'Delete ' . strtolower(e($account->accountType->type)) . ' "' . e($account->name) . '"'); + } public function testDestroy() diff --git a/tests/factories/all.php b/tests/factories/all.php new file mode 100644 index 0000000000..190bb559e6 --- /dev/null +++ b/tests/factories/all.php @@ -0,0 +1,35 @@ + 'factory|FireflyIII\User', + 'account_type_id' => 'factory|FireflyIII\Models\AccountType', + 'name' => 'word', + 'active' => 'boolean', + 'encrypted' => 'boolean', + 'virtual_balance' => 0 + ] +); + +FactoryMuffin::define( + 'FireflyIII\Models\Preference', [ + 'name' => 'word', + 'data' => 'sentence', + 'user_id' => 'factory|FireflyIII\User', + ] +); + +FactoryMuffin::define( + 'FireflyIII\Models\AccountType', [ + 'type' => 'word', + 'editable' => 1, + ] +); + +FactoryMuffin::define( + 'FireflyIII\User', [ + 'email' => 'email', + 'password' => bcrypt('james'), + ] +); \ No newline at end of file