From a2bf6859013d2f24c90b64469668b7dc4729476c Mon Sep 17 00:00:00 2001 From: Daniel Meltzer Date: Wed, 18 Jan 2017 18:50:33 -0600 Subject: [PATCH] Seeds and tests (#3210) * Update composer phpcs * Fix failing model validation in the database seeders. Should make travis happy. Also fix a few test issues --- composer.lock | 56 ++++++++++++++--------------- database/factories/ModelFactory.php | 33 +++-------------- database/seeds/CategorySeeder.php | 8 ++--- database/seeds/DatabaseSeeder.php | 8 ++--- tests/unit/CategoryTest.php | 33 +++++++++-------- 5 files changed, 59 insertions(+), 79 deletions(-) diff --git a/composer.lock b/composer.lock index 6e94f70e41..940fcc223e 100644 --- a/composer.lock +++ b/composer.lock @@ -9,16 +9,16 @@ "packages": [ { "name": "aws/aws-sdk-php", - "version": "3.20.13", + "version": "3.20.12", "source": { "type": "git", "url": "https://github.com/aws/aws-sdk-php.git", - "reference": "343c6c96468de5087ae5e7df4ccee2668857a5aa" + "reference": "8725e67cb77b057b55596b4468ce9a1a95c5fe96" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/343c6c96468de5087ae5e7df4ccee2668857a5aa", - "reference": "343c6c96468de5087ae5e7df4ccee2668857a5aa", + "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/8725e67cb77b057b55596b4468ce9a1a95c5fe96", + "reference": "8725e67cb77b057b55596b4468ce9a1a95c5fe96", "shasum": "" }, "require": { @@ -85,7 +85,7 @@ "s3", "sdk" ], - "time": "2017-01-04 18:20:17" + "time": "2016-12-30 00:41:36" }, { "name": "aws/aws-sdk-php-laravel", @@ -145,20 +145,20 @@ }, { "name": "barryvdh/laravel-debugbar", - "version": "v2.3.1", + "version": "v2.3.0", "source": { "type": "git", "url": "https://github.com/barryvdh/laravel-debugbar.git", - "reference": "65b0465e38a9524c9d5eb2dfc0389aba23090625" + "reference": "0c87981df959c7c1943abe227baf607c92f204f9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/barryvdh/laravel-debugbar/zipball/65b0465e38a9524c9d5eb2dfc0389aba23090625", - "reference": "65b0465e38a9524c9d5eb2dfc0389aba23090625", + "url": "https://api.github.com/repos/barryvdh/laravel-debugbar/zipball/0c87981df959c7c1943abe227baf607c92f204f9", + "reference": "0c87981df959c7c1943abe227baf607c92f204f9", "shasum": "" }, "require": { - "illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*", + "illuminate/support": "5.1.*|5.2.*|5.3.*", "maximebf/debugbar": "~1.13.0", "php": ">=5.5.9", "symfony/finder": "~2.7|~3.0" @@ -195,7 +195,7 @@ "profiler", "webprofiler" ], - "time": "2017-01-05 08:53:44" + "time": "2016-09-15 14:05:56" }, { "name": "christian-riesen/base32", @@ -1318,16 +1318,16 @@ }, { "name": "laravel/framework", - "version": "v5.3.29", + "version": "v5.3.28", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "6fd76dec90466dc3f703d8df72e38130f2ee6a32" + "reference": "a64fc4f8958091ca39623b2e8c8f173cb34fa47a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/6fd76dec90466dc3f703d8df72e38130f2ee6a32", - "reference": "6fd76dec90466dc3f703d8df72e38130f2ee6a32", + "url": "https://api.github.com/repos/laravel/framework/zipball/a64fc4f8958091ca39623b2e8c8f173cb34fa47a", + "reference": "a64fc4f8958091ca39623b2e8c8f173cb34fa47a", "shasum": "" }, "require": { @@ -1344,7 +1344,7 @@ "php": ">=5.6.4", "psy/psysh": "0.7.*|0.8.*", "ramsey/uuid": "~3.0", - "swiftmailer/swiftmailer": "~5.4", + "swiftmailer/swiftmailer": "~5.1", "symfony/console": "3.1.*", "symfony/debug": "3.1.*", "symfony/finder": "3.1.*", @@ -1442,7 +1442,7 @@ "framework", "laravel" ], - "time": "2017-01-06 14:33:56" + "time": "2016-12-15 18:03:17" }, { "name": "laravel/legacy-encrypter", @@ -1984,16 +1984,16 @@ }, { "name": "maximebf/debugbar", - "version": "1.13.1", + "version": "v1.13.0", "source": { "type": "git", "url": "https://github.com/maximebf/php-debugbar.git", - "reference": "afee79a236348e39a44cb837106b7c5b4897ac2a" + "reference": "5f49a5ed6cfde81d31d89378806670d77462526e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/afee79a236348e39a44cb837106b7c5b4897ac2a", - "reference": "afee79a236348e39a44cb837106b7c5b4897ac2a", + "url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/5f49a5ed6cfde81d31d89378806670d77462526e", + "reference": "5f49a5ed6cfde81d31d89378806670d77462526e", "shasum": "" }, "require": { @@ -2041,7 +2041,7 @@ "debug", "debugbar" ], - "time": "2017-01-05 08:46:19" + "time": "2016-09-15 14:01:59" }, { "name": "monolog/monolog", @@ -4062,16 +4062,16 @@ }, { "name": "zendframework/zend-diactoros", - "version": "1.3.8", + "version": "1.3.7", "source": { "type": "git", "url": "https://github.com/zendframework/zend-diactoros.git", - "reference": "d9c1fd7c4b024179d49faf367da544b4eef7cfe8" + "reference": "969ff423d3f201da3ff718a5831bb999bb0669b0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-diactoros/zipball/d9c1fd7c4b024179d49faf367da544b4eef7cfe8", - "reference": "d9c1fd7c4b024179d49faf367da544b4eef7cfe8", + "url": "https://api.github.com/repos/zendframework/zend-diactoros/zipball/969ff423d3f201da3ff718a5831bb999bb0669b0", + "reference": "969ff423d3f201da3ff718a5831bb999bb0669b0", "shasum": "" }, "require": { @@ -4083,7 +4083,7 @@ }, "require-dev": { "phpunit/phpunit": "^4.6 || ^5.5", - "zendframework/zend-coding-standard": "~1.0.0" + "squizlabs/php_codesniffer": "^2.3.1" }, "type": "library", "extra": { @@ -4108,7 +4108,7 @@ "psr", "psr-7" ], - "time": "2017-01-05 21:44:28" + "time": "2016-10-11 13:25:21" } ], "packages-dev": [ diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index ef5d97f105..1c91b123b7 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -11,6 +11,7 @@ | */ +use App\Models\Category; use App\Models\Company; use App\Models\Location; use App\Models\Manufacturer; @@ -61,38 +62,17 @@ $factory->defineAs(App\Models\Location::class, 'location', function (Faker\Gener ]; }); -$factory->defineAs(App\Models\Category::class, 'asset-category', function (Faker\Generator $faker) { +$factory->defineAs(App\Models\Category::class, 'category', function (Faker\Generator $faker) { return [ 'name' => $faker->text(20), - 'category_type' => $faker->randomElement($array = array ('asset')), + 'category_type' => $faker->randomElement(['asset', 'accessory', 'component', 'consumable']), 'eula_text' => $faker->paragraph(), 'require_acceptance' => $faker->boolean(), + 'use_default_eula' => $faker->boolean(), 'checkin_email' => $faker->boolean() ]; }); -$factory->defineAs(App\Models\Category::class, 'accessory-category', function (Faker\Generator $faker) { - return [ - 'name' => $faker->text(20), - 'category_type' => $faker->randomElement($array = array ('accessory')), - ]; -}); - -$factory->defineAs(App\Models\Category::class, 'component-category', function (Faker\Generator $faker) { - return [ - 'name' => $faker->text(20), - 'category_type' => $faker->randomElement($array = array ('component')), - ]; -}); - -$factory->defineAs(App\Models\Category::class, 'consumable-category', function (Faker\Generator $faker) { - return [ - 'name' => $faker->text(20), - 'category_type' => $faker->randomElement($array = array ('consumable')), - ]; -}); - - $factory->defineAs(App\Models\Company::class, 'company', function (Faker\Generator $faker) { return [ 'name' => $faker->company, @@ -131,7 +111,7 @@ $factory->defineAs(App\Models\Accessory::class, 'accessory', function (Faker\Gen return [ 'company_id' => Company::inRandomOrder()->first()->id, 'name' => $faker->text(20), - 'category_id' => $faker->numberBetween(11, 15), + 'category_id' => Category::where('category_type', 'accessory')->inRandomOrder()->first()->id, 'manufacturer_id' => Manufacturer::inRandomOrder()->first()->id, 'location_id' => $faker->numberBetween(1, 5), 'order_number' => $faker->numberBetween(1000000, 50000000), @@ -389,6 +369,3 @@ $factory->defineAs(App\Models\CustomField::class, 'customfield-ip', function (Fa 'element' => 'text', ]; }); - - - diff --git a/database/seeds/CategorySeeder.php b/database/seeds/CategorySeeder.php index b4d87424e3..338acebdc3 100755 --- a/database/seeds/CategorySeeder.php +++ b/database/seeds/CategorySeeder.php @@ -7,10 +7,10 @@ class CategorySeeder extends Seeder public function run() { Category::truncate(); - factory(Category::class, 'asset-category', 10)->create(); - factory(Category::class, 'accessory-category', 5)->create(); - factory(Category::class, 'consumable-category', 5)->create(); - factory(Category::class, 'component-category', 5)->create(); + factory(Category::class, 'category', 10)->create(['category_type' => 'asset']); + factory(Category::class, 'category', 10)->create(['category_type' => 'accessory']); + factory(Category::class, 'category', 10)->create(['category_type' => 'consumable']); + factory(Category::class, 'category', 10)->create(['category_type' => 'component']); } } diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index 7ae5ed2308..6332a85999 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -15,20 +15,20 @@ class DatabaseSeeder extends Seeder Model::unguard(); $this->call(CompanySeeder::class); + $this->call(CategorySeeder::class); $this->call(UserSeeder::class); + $this->call(DepreciationSeeder::class); $this->call(ManufacturerSeeder::class); $this->call(LocationSeeder::class); + $this->call(SupplierSeeder::class); $this->call(AssetModelSeeder::class); $this->call(AccessorySeeder::class); $this->call(AssetSeeder::class); + $this->call(LicenseSeeder::class); $this->call(ComponentSeeder::class); $this->call(ConsumableSeeder::class); $this->call(StatuslabelSeeder::class); - $this->call(SupplierSeeder::class); - $this->call(CategorySeeder::class); - $this->call(LicenseSeeder::class); $this->call(ActionlogSeeder::class); - $this->call(DepreciationSeeder::class); $this->call(CustomFieldSeeder::class); Model::reguard(); diff --git a/tests/unit/CategoryTest.php b/tests/unit/CategoryTest.php index 655f47f307..9ebc9b72e3 100644 --- a/tests/unit/CategoryTest.php +++ b/tests/unit/CategoryTest.php @@ -15,26 +15,29 @@ class CategoryTest extends \Codeception\TestCase\Test public function testAssetCategoryAdd() { - $category = factory(Category::class, 'asset-category')->make(); - $values = [ - 'name' => $category->name, - 'category_type' => $category->category_type, - ]; + $category = factory(Category::class, 'category')->make(['category_type' => 'asset']); + $values = [ + 'name' => $category->name, + 'category_type' => $category->category_type, + 'require_acceptance' => true, + 'use_default_eula' => false + ]; - Category::create($values); - $this->tester->seeRecord('categories', $values); + Category::create($values); + $this->tester->seeRecord('categories', $values); } public function testAccessoryCategoryAdd() { - $category = factory(Category::class, 'accessory-category')->make(); - $values = [ - 'name' => $category->name, - 'category_type' => $category->category_type, - ]; + $category = factory(Category::class, 'category')->make(['category_type' => 'accessory']); + $values = [ + 'name' => $category->name, + 'category_type' => $category->category_type, + 'require_acceptance' => true, + 'use_default_eula' => false + ]; - Category::create($values); - $this->tester->seeRecord('categories', $values); + Category::create($values); + $this->tester->seeRecord('categories', $values); } - }