1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Author: Nil Portugués Calderó <[email protected]> |
4
|
|
|
* Date: 12/9/15 |
5
|
|
|
* Time: 5:24 PM. |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace NilPortugues\Tests\Laravel5\JsonApi; |
12
|
|
|
|
13
|
|
|
use Illuminate\Events\Dispatcher; |
14
|
|
|
use Illuminate\Filesystem\ClassFinder; |
15
|
|
|
use Illuminate\Filesystem\Filesystem; |
16
|
|
|
use Illuminate\Routing\Router; |
17
|
|
|
use NilPortugues\Tests\App\Transformers\EmployeesTransformer; |
18
|
|
|
use NilPortugues\Tests\App\Transformers\OrdersTransformer; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class LaravelTestCase. |
22
|
|
|
*/ |
23
|
|
|
class LaravelTestCase extends \Illuminate\Foundation\Testing\TestCase |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Setup DB before each test. |
27
|
|
|
*/ |
28
|
|
|
public function setUp() |
29
|
|
|
{ |
30
|
|
|
parent::setUp(); |
31
|
|
|
|
32
|
|
|
$this->app['config']->set('database.default', 'sqlite'); |
33
|
|
|
$this->app['config']->set('database.connections.sqlite.database', ':memory:'); |
34
|
|
|
$this->app['config']->set('jsonapi', [EmployeesTransformer::class, OrdersTransformer::class]); |
35
|
|
|
$this->app['config']->set('app.url', 'http://example.com/'); |
36
|
|
|
$this->app['config']->set('app.debug', true); |
37
|
|
|
$this->app['config']->set('app.key', \env('APP_KEY', '1234567890123456')); |
38
|
|
|
$this->app['config']->set('app.cipher', 'AES-128-CBC'); |
39
|
|
|
|
40
|
|
|
$this->app->boot(); |
41
|
|
|
|
42
|
|
|
$this->migrate(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* run package database migrations. |
47
|
|
|
*/ |
48
|
|
|
public function migrate() |
49
|
|
|
{ |
50
|
|
|
$fileSystem = new Filesystem(); |
51
|
|
|
$classFinder = new ClassFinder(); |
52
|
|
|
|
53
|
|
|
foreach ($fileSystem->files(__DIR__.'/../../../../tests/NilPortugues/App/Migrations') as $file) { |
54
|
|
|
$fileSystem->requireOnce($file); |
55
|
|
|
$migrationClass = $classFinder->findClass($file); |
56
|
|
|
(new $migrationClass())->down(); |
57
|
|
|
(new $migrationClass())->up(); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Boots the application. |
63
|
|
|
* |
64
|
|
|
* @return \Illuminate\Foundation\Application |
65
|
|
|
*/ |
66
|
|
|
public function createApplication() |
67
|
|
|
{ |
68
|
|
|
/** @var $app \Illuminate\Foundation\Application */ |
69
|
|
|
$app = require __DIR__.'/../../../../vendor/laravel/laravel/bootstrap/app.php'; |
70
|
|
|
|
71
|
|
|
$this->setUpHttpKernel($app); |
72
|
|
|
$app->register(\Illuminate\Database\DatabaseServiceProvider::class); |
73
|
|
|
$app->register(\NilPortugues\Tests\App\Providers\RouteServiceProvider::class); |
74
|
|
|
$app->register(\NilPortugues\Laravel5\JsonApi\Laravel5JsonApiServiceProvider::class); |
75
|
|
|
|
76
|
|
|
return $app; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return Router |
81
|
|
|
*/ |
82
|
|
|
protected function getRouter() |
83
|
|
|
{ |
84
|
|
|
$router = new Router(new Dispatcher()); |
85
|
|
|
|
86
|
|
|
return $router; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param \Illuminate\Foundation\Application $app |
91
|
|
|
*/ |
92
|
|
|
private function setUpHttpKernel($app) |
93
|
|
|
{ |
94
|
|
|
$app->instance('request', \Illuminate\Http\Request::capture()); |
95
|
|
|
$app->make('Illuminate\Foundation\Http\Kernel', [$app, $this->getRouter()])->bootstrap(); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|