From b8813e8556ef57a955f99d11fb5be1cdc326f891 Mon Sep 17 00:00:00 2001 From: Victor Lap Date: Wed, 28 Jun 2017 14:18:18 +0200 Subject: [PATCH] WIP --- composer.json | 6 ++- phpunit.xml | 3 +- tests/BaseTest.php | 20 ++++++++ tests/ExampleTest.php | 14 ------ tests/Models/User.php | 20 ++++++++ tests/Models/UserCanApprove.php | 12 +++++ tests/Models/UserCannotApprove.php | 12 +++++ tests/TestCase.php | 47 +++++++++++++++++++ tests/TestServiceProvider.php | 19 ++++++++ .../2014_10_12_000000_create_users_table.php | 35 ++++++++++++++ 10 files changed, 171 insertions(+), 17 deletions(-) create mode 100644 tests/BaseTest.php delete mode 100644 tests/ExampleTest.php create mode 100644 tests/Models/User.php create mode 100644 tests/Models/UserCanApprove.php create mode 100644 tests/Models/UserCannotApprove.php create mode 100644 tests/TestCase.php create mode 100644 tests/TestServiceProvider.php create mode 100644 tests/database/migrations/2014_10_12_000000_create_users_table.php diff --git a/composer.json b/composer.json index 8ace1f8..747dc3b 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,9 @@ "php" : "~5.6|~7.0" }, "require-dev": { - "phpunit/phpunit" : "~4.0||~5.0", + "orchestra/testbench": "~3.0", + "orchestra/database": "~3.1", + "phpunit/phpunit": "~4.0||~5.0", "squizlabs/php_codesniffer": "^2.3" }, "autoload": { @@ -30,7 +32,7 @@ }, "autoload-dev": { "psr-4": { - "Victorlap\\Approvable\\": "tests" + "Victorlap\\Approvable\\Tests\\": "tests" } }, "scripts": { diff --git a/phpunit.xml b/phpunit.xml index d3cea4c..e66a20b 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,6 +1,7 @@ - ./tests/ + ./tests/ \ No newline at end of file diff --git a/tests/BaseTest.php b/tests/BaseTest.php new file mode 100644 index 0000000..0c2a858 --- /dev/null +++ b/tests/BaseTest.php @@ -0,0 +1,20 @@ + 'John Doe', 'email' => 'john@doe.com']); + $this->assertTrue($user->exists); + } + + public function testRegularCanCreate() { + $user = UserCannotApprove::create(['name' => 'John Doe', 'email' => 'john2@doe.com']); + $this->assertTrue($user->exists); + } +} \ No newline at end of file diff --git a/tests/ExampleTest.php b/tests/ExampleTest.php deleted file mode 100644 index 8e5d606..0000000 --- a/tests/ExampleTest.php +++ /dev/null @@ -1,14 +0,0 @@ -assertTrue(true); - } -} diff --git a/tests/Models/User.php b/tests/Models/User.php new file mode 100644 index 0000000..52fcd00 --- /dev/null +++ b/tests/Models/User.php @@ -0,0 +1,20 @@ +artisan('migrate', ['--database' => 'testing']); + } + + /** + * Define environment setup. + * + * @param \Illuminate\Foundation\Application $app + * @return void + */ + protected function getEnvironmentSetUp($app) + { + // set up database configuration + $app['config']->set('database.default', 'testing'); + } + + /** + * Get Approvable package providers. + * + * @return array + */ + protected function getPackageProviders($app) + { + return [ + TestServiceProvider::class, + ApprovableServiceProvider::class, + ]; + } +} \ No newline at end of file diff --git a/tests/TestServiceProvider.php b/tests/TestServiceProvider.php new file mode 100644 index 0000000..249e7c9 --- /dev/null +++ b/tests/TestServiceProvider.php @@ -0,0 +1,19 @@ +loadMigrationsFrom(realpath(__DIR__.'/database/migrations/migrations')); + $this->loadMigrationsFrom(realpath(__DIR__.'/../migrations')); + } +} \ No newline at end of file diff --git a/tests/database/migrations/2014_10_12_000000_create_users_table.php b/tests/database/migrations/2014_10_12_000000_create_users_table.php new file mode 100644 index 0000000..689cbee --- /dev/null +++ b/tests/database/migrations/2014_10_12_000000_create_users_table.php @@ -0,0 +1,35 @@ +increments('id'); + $table->string('name'); + $table->string('email')->unique(); + $table->string('password'); + $table->rememberToken(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('users'); + } +}