laravel base files
This commit is contained in:
28
tests/ApiTestTrait.php
Normal file
28
tests/ApiTestTrait.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
trait ApiTestTrait
|
||||
{
|
||||
public function assertApiResponse(Array $actualData)
|
||||
{
|
||||
$this->assertApiSuccess();
|
||||
|
||||
$response = json_decode($this->response->getContent(), true);
|
||||
$responseData = $response['data'];
|
||||
|
||||
$this->assertNotEmpty($responseData['id']);
|
||||
$this->assertModelData($actualData, $responseData);
|
||||
}
|
||||
|
||||
public function assertApiSuccess()
|
||||
{
|
||||
$this->assertResponseOk();
|
||||
$this->seeJson(['success' => true]);
|
||||
}
|
||||
|
||||
public function assertModelData(Array $actualData, Array $expectedData)
|
||||
{
|
||||
foreach ($actualData as $key => $value) {
|
||||
$this->assertEquals($actualData[$key], $expectedData[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
19
tests/ExampleTest.php
Executable file
19
tests/ExampleTest.php
Executable file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class ExampleTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* A basic functional test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBasicExample()
|
||||
{
|
||||
$this->visit('/')
|
||||
->see('Laravel');
|
||||
}
|
||||
}
|
||||
25
tests/TestCase.php
Executable file
25
tests/TestCase.php
Executable file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user