Skip to content

Commit

Permalink
Merge pull request #5 from byte5digital/feature/test_travis
Browse files Browse the repository at this point in the history
Brake the Test
  • Loading branch information
Weegy authored Jul 17, 2019
2 parents 83c21b8 + 6898360 commit 4e959a1
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 3 deletions.
51 changes: 51 additions & 0 deletions .env.testing
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:wO+axlK/1o9pzGQo9UdvqGI1h7sCI03CBHSxiXkNmYk=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=testing

DB_HOST=postgres
DB_PORT=5432
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

DB_HOST_MYSQL=127.0.0.1
DB_PORT_MYSQL=33061
DB_DATABASE_MYSQL=byte5_test
DB_USERNAME_MYSQL=homestead
DB_PASSWORD_MYSQL=secret

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
14 changes: 14 additions & 0 deletions .idea/php-test-framework.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion app/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
class Project extends Model
{

public $connection = 'mysql';

protected $fillable = ['name'];

Expand Down
6 changes: 6 additions & 0 deletions config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],

'testing' => [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
],

'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
Expand Down
2 changes: 1 addition & 1 deletion database/factories/ProjectFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

$factory->define(Project::class, function (Faker $faker) {
return [
//
'name' => $faker->name
];
});
17 changes: 16 additions & 1 deletion tests/CreatesApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Tests;

use Artisan;
use DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Contracts\Console\Kernel;

trait CreatesApplication
Expand All @@ -14,9 +17,21 @@ trait CreatesApplication
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';

$app->loadEnvironmentFrom('.env.testing');
$app->make(Kernel::class)->bootstrap();

return $app;
}

public function setUp(): void
{
parent::setUp();
Artisan::call('migrate');
}

public function tearDown(): void
{
Artisan::call('migrate:reset');
parent::tearDown();
}
}
35 changes: 35 additions & 0 deletions tests/Feature/ProjectTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Tests\Feature;

use App\Project;
use Tests\TestCase;

class ProjectTest extends TestCase
{
protected $mockProject;
protected $tempName;

public function setUp(): void
{
parent::setUp();
$this->mockProject = factory(Project::class)->make();
$this->mockProject->save();
$this->tempName = $this->mockProject->name;
}

public function testProjectApiControllerTest()
{
$response = $this->get('/api/projects');
$response->assertStatus(200);
$response->assertJsonStructure(['data' => [['id', 'user' => [], 'project_name']]]);
$response->assertJson(['data' => [['project_name' => $this->tempName]]]);
}

public function testAddDataToProjectTest()
{
$allProjects = Project::all();
$this->assertEquals($allProjects->count(), 1);
$this->assertEquals($allProjects->first()->name, $this->tempName);
}
}

0 comments on commit 4e959a1

Please sign in to comment.