1 | <?php |
||
24 | class LaravelTestCase extends \Illuminate\Foundation\Testing\TestCase |
||
25 | { |
||
26 | use WithoutMiddleware; |
||
27 | /** |
||
28 | * Setup DB before each test. |
||
29 | */ |
||
30 | public function setUp() |
||
31 | { |
||
32 | parent::setUp(); |
||
33 | |||
34 | $this->app['config']->set('database.default', 'sqlite'); |
||
35 | $this->app['config']->set('database.connections.sqlite.database', ':memory:'); |
||
36 | $this->app['config']->set('jsonapi', [EmployeesTransformer::class, OrdersTransformer::class]); |
||
37 | $this->app['config']->set('app.url', 'http://localhost/'); |
||
38 | $this->app['config']->set('app.debug', true); |
||
39 | $this->app['config']->set('app.key', \env('APP_KEY', '1234567890123456')); |
||
40 | $this->app['config']->set('app.cipher', 'AES-128-CBC'); |
||
41 | |||
42 | $this->app->boot(); |
||
43 | |||
44 | $this->migrate(); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * run package database migrations. |
||
49 | */ |
||
50 | public function migrate() |
||
62 | |||
63 | /** |
||
64 | * Boots the application. |
||
65 | * |
||
66 | * @return \Illuminate\Foundation\Application |
||
67 | */ |
||
68 | public function createApplication() |
||
80 | |||
81 | /** |
||
82 | * @return Router |
||
83 | */ |
||
84 | protected function getRouter() |
||
90 | |||
91 | /** |
||
92 | * @param \Illuminate\Foundation\Application $app |
||
93 | */ |
||
94 | private function setUpHttpKernel($app) |
||
99 | |||
100 | /** |
||
101 | * This is required for \Symfony\Bridge\PsrHttpMessage\Factory to work. |
||
102 | * This comes as a trade-off of building the underlying package as framework-agnostic. |
||
103 | * |
||
104 | * @param string $method |
||
105 | * @param string $uri |
||
106 | * @param array $parameters |
||
107 | * @param array $cookies |
||
108 | * @param array $files |
||
109 | * @param array $server |
||
110 | * @param string $content |
||
111 | * |
||
112 | * @return \Illuminate\Http\Response |
||
113 | */ |
||
114 | public function call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null) |
||
123 | } |
||
124 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: