Last active
March 7, 2016 20:35
-
-
Save michaelachrisco/fe62542809b628d93ec2 to your computer and use it in GitHub Desktop.
TestCase with example (basic) relation testing built in.
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 | |
//Set up Testing env | |
use Illuminate\Foundation\Testing\WithoutMiddleware; | |
// use Illuminate\Foundation\Testing\DatabaseMigrations; | |
use Illuminate\Foundation\Testing\DatabaseTransactions; | |
abstract class TestCase extends Illuminate\Foundation\Testing\TestCase | |
{ | |
/** | |
* The base URL to use while testing the application. | |
* | |
* @var string | |
*/ | |
protected $baseUrl = 'http://localhost'; | |
/** | |
* Creates the application. | |
* | |
* @return \Illuminate\Foundation\Application | |
*/ | |
public function createApplication() | |
{ | |
$app = require __DIR__.'/../bootstrap/app.php'; | |
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap(); | |
return $app; | |
} | |
public function assertArrayHasKeys(array $keys, array $array, $message = null) | |
{ | |
foreach ($keys as $key) { | |
$this->assertArrayHasKey($key, $array, $message); | |
} | |
} | |
public function assertBelongsTo($relation, $relationName){ | |
$this->assertEquals('Illuminate\Database\Eloquent\Relations\BelongsTo', get_class($relation)); | |
$this->assertEquals($relationName, get_class($relation->getRelated())); | |
} | |
public function assertHasMany($relation, $relationName){ | |
$this->assertEquals('Illuminate\Database\Eloquent\Relations\HasMany', get_class($relation)); | |
$this->assertEquals($relationName, get_class($relation->getRelated())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To start out:
Model:
Test:
This is a compactly shallow test and really should include the models reflexive properties as well as index through operations. This may change depending on how long Laravel sticks around.