Last active
November 24, 2015 17:08
-
-
Save ethaizone/317eb7ec1dafca205fee to your computer and use it in GitHub Desktop.
Laravel 5.1 - Run testcase with real model in memory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// config/database.php | |
return [ | |
'connections' => [ | |
// create new connection on sqlite | |
// we con do anything with it because it's on ram. | |
// NOTICE: When you write migration script. You must tell which fields is null or not null with nullable() | |
// On mysql default is null but sqlite is not null. | |
// It's better if you define it at first. | |
'testing' => [ | |
'driver' => 'sqlite', | |
'database' => ':memory:', | |
'prefix' => '' | |
], | |
], | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<phpunit backupGlobals="false" | |
backupStaticAttributes="false" | |
bootstrap="bootstrap/autoload.php" | |
colors="true" | |
convertErrorsToExceptions="true" | |
convertNoticesToExceptions="true" | |
convertWarningsToExceptions="true" | |
processIsolation="false" | |
stopOnFailure="false" | |
syntaxCheck="false"> | |
<testsuites> | |
<testsuite name="Application Test Suite"> | |
<directory>./tests/</directory> | |
</testsuite> | |
</testsuites> | |
<filter> | |
<whitelist> | |
<directory suffix=".php">app/</directory> | |
</whitelist> | |
</filter> | |
<php> | |
<env name="APP_ENV" value="testing"/> | |
<env name="CACHE_DRIVER" value="array"/> | |
<env name="SESSION_DRIVER" value="array"/> | |
<env name="QUEUE_DRIVER" value="sync"/> | |
<env name="DB_CONNECTION" value="testing"/> | |
</php> | |
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Foundation\Testing\DatabaseMigrations; | |
class ProductControllerTest extends TestCase | |
{ | |
use DatabaseMigrations; | |
protected $testSubject = null; | |
protected function assertPreConditions() | |
{ | |
$this->seed('ProductTableSeeder'); | |
$this->seed('UserTableSeeder'); | |
$admin = App\Models\User::where('name', 'admin')->first(); | |
$this->be($admin); | |
} | |
public function testGetIndex() | |
{ | |
$this->route('GET', 'backoffice.products.index.get'); | |
$this->assertViewHas('products'); | |
} | |
public function testCreateGroup() | |
{ | |
$this->route('GET', 'backoffice.products.create-group.get'); | |
$this->assertViewHas('product'); | |
$admin = App\Models\User::where('name', 'admin')->first(); | |
$response = $this->route('POST', 'backoffice.products.create-group.post', [ | |
'title' => 'Test Group 1', | |
'position' => '0', | |
'status' => 'enable' | |
'_token' => csrf_token(), | |
]); | |
$lastItem = App\Models\Product::orderBy('id', 'desc')->first(); | |
$this->assertRedirectedToRoute('backoffice.products.edit-group.get', ['id' => $lastItem->getKey()]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment