db test and Travis CI integration

This commit is contained in:
Bubka 2019-05-23 14:02:29 +02:00
parent 85fc616899
commit 507f2677dd
5 changed files with 43 additions and 13 deletions

9
.env.travis Normal file
View File

@ -0,0 +1,9 @@
APP_ENV=testing
APP_KEY=
DB_CONNECTION=sqlite
DB_DATABASE=:memory:
CACHE_DRIVER=array
SESSION_DRIVER=array
QUEUE_DRIVER=sync

15
.travis.yml Normal file
View File

@ -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

View File

@ -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'),
]);
}
}

View File

@ -24,6 +24,8 @@
</filter>
<php>
<server name="APP_ENV" value="testing"/>
<server name="DB_CONNECTION" value="sqlite"/>
<server name="DB_DATABASE" value=":memory:"/>
<server name="BCRYPT_ROUNDS" value="4"/>
<server name="CACHE_DRIVER" value="array"/>
<server name="MAIL_DRIVER" value="array"/>

View File

@ -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')