From 507f2677dd6b7593386526490600ccd9a32a1ba6 Mon Sep 17 00:00:00 2001 From: Bubka <858858+Bubka@users.noreply.github.com> Date: Thu, 23 May 2019 14:02:29 +0200 Subject: [PATCH] db test and Travis CI integration --- .env.travis | 9 +++++++++ .travis.yml | 15 +++++++++++++++ database/seeds/UsersTableSeeder.php | 6 +++--- phpunit.xml | 2 ++ tests/Unit/APITest.php | 24 ++++++++++++++---------- 5 files changed, 43 insertions(+), 13 deletions(-) create mode 100644 .env.travis create mode 100644 .travis.yml diff --git a/.env.travis b/.env.travis new file mode 100644 index 00000000..7de28349 --- /dev/null +++ b/.env.travis @@ -0,0 +1,9 @@ +APP_ENV=testing +APP_KEY= + +DB_CONNECTION=sqlite +DB_DATABASE=:memory: + +CACHE_DRIVER=array +SESSION_DRIVER=array +QUEUE_DRIVER=sync \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..f5d82ea4 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,15 @@ +language: php + +php: + - "7.2" + +before_script: + - cp .env.travis .env + - composer self-update + - composer install --no-interaction + - php artisan key:generate + - php artisan migrate --seed + - php artisan passport:install + +script: +- vendor/bin/phpunit \ No newline at end of file diff --git a/database/seeds/UsersTableSeeder.php b/database/seeds/UsersTableSeeder.php index 6431ca5a..5116d4b3 100644 --- a/database/seeds/UsersTableSeeder.php +++ b/database/seeds/UsersTableSeeder.php @@ -13,9 +13,9 @@ class UsersTableSeeder extends Seeder public function run() { User::create([ - 'name' => 'bubka', - 'email' => 'edouard@ganeau.me', - 'password' => bcrypt('bubka'), + 'name' => 'testLogin', + 'email' => 'test@test.com', + 'password' => bcrypt('test'), ]); } } diff --git a/phpunit.xml b/phpunit.xml index da4add30..c594cc14 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -24,6 +24,8 @@ + + diff --git a/tests/Unit/APITest.php b/tests/Unit/APITest.php index edad6955..d36d7cc3 100644 --- a/tests/Unit/APITest.php +++ b/tests/Unit/APITest.php @@ -4,11 +4,15 @@ use Tests\TestCase; use Illuminate\Foundation\Testing\WithFaker; -use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Auth\Authenticatable; class APITest extends TestCase { + + use DatabaseMigrations; + + /** * test User creation via API * @@ -17,9 +21,9 @@ class APITest extends TestCase public function testUserCreation() { $response = $this->json('POST', '/api/register', [ - 'name' => 'Demo User', - 'email' => str_random(10) . '@phpunit.com', - 'password' => '12345', + 'name' => 'testCreate', + 'email' => str_random(10) . '@test.com', + 'password' => 'test', ]); $response->assertStatus(200)->assertJsonStructure([ @@ -36,8 +40,8 @@ public function testUserCreation() public function testUserLogin() { $response = $this->json('POST', '/api/login', [ - 'email' => 'edouard@ganeau.me', - 'password' => 'bubka' + 'email' => 'test@test.com', + 'password' => 'test' ]); $response->assertStatus(200)->assertJsonStructure([ @@ -58,8 +62,8 @@ public function testAccountCreation() $response = $this->actingAs($user, 'api') ->json('POST', '/api/account', [ - 'name' => 'phpunit account #' . str_random(5), - 'secret' => '3GB2I2P365J575LS', + 'name' => 'testCreation', + 'secret' => 'test', ]); $response->assertStatus(200)->assertJson([ @@ -105,8 +109,8 @@ public function testAccountDeletion() $user = \App\User::find(1); $account = \App\Account::create([ - 'name' => 'To be deleted #' . str_random(5), - 'secret' => '12345' + 'name' => 'testDelete', + 'secret' => 'test' ]); $response = $this->actingAs($user, 'api')