-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodecept_setup.php
More file actions
100 lines (81 loc) · 3.1 KB
/
codecept_setup.php
File metadata and controls
100 lines (81 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php namespace App;
use App\Models\User;
use Barryvdh\Cors\ServiceProvider as CORSServiceProvider;
use Bkwld\Croppa\ServiceProvider as CroppaServiceProvider;
use Dotenv\Dotenv;
use Gzero\Core\Exceptions\Handler;
use Gzero\Core\ServiceProvider;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Database\DatabaseManager;
use Laravel\Passport\Passport;
use Laravel\Passport\PassportServiceProvider;
use Orchestra\Testbench\Traits\CreatesApplication;
require_once __DIR__ . '/tests/fixture/User.php';
require_once __DIR__ . '/tests/fixture/HelloWorld.php';
require_once __DIR__ . '/tests/fixture/UploadableEntity.php';
require __DIR__ . '/vendor/autoload.php';
if (file_exists(__DIR__ . '/.env.testing')) {
(new Dotenv(__DIR__, '.env.testing'))->load();
}
if (!class_exists('App\TestApp')) {
function dbReconnectIfNeeded(DatabaseManager $db)
{
if ($db->connection()->getPdo() === null) {
$db->connection()->reconnect();
}
}
class TestApp {
static $oldDb = null;
use CreatesApplication;
protected function getPackageProviders($app)
{
$routes = $app['router']->getRoutes();
// The URL generator needs the route collection that exists on the router.
// Keep in mind this is an object, so we're passing by references here
// and all the registered routes will be available to the generator.
$app->instance('routes', $routes);
// Register Exception handler
$app->singleton(
ExceptionHandler::class,
Handler::class
);
// We need to tell Laravel Passport where to find oauth keys
Passport::loadKeysFrom(__DIR__ . '/vendor/gzero/testing/oauth/');
return [
PassportServiceProvider::class,
CORSServiceProvider::class,
CroppaServiceProvider::class,
ServiceProvider::class
];
}
/**
* Define environment setup.
*
* @param \Illuminate\Foundation\Application $app
*
* @return void
*/
protected function getEnvironmentSetUp($app)
{
// Reuse existing db to prevent transaction between application calls
if (static::$oldDb !== null) {
dbReconnectIfNeeded(static::$oldDb);
$app->singleton('db', function () {
return static::$oldDb;
});
} else {
if (isset($app['db']) && $app['db']->connection()) {
static::$oldDb = $app['db'];
}
}
// Use passport as guard for api
$app['config']->set('auth.guards.api.driver', 'passport');
// We want to return Access-Control-Allow-Credentials header as well
$app['config']->set('cors.supportsCredentials', true);
// We moved user model in platform
$app['config']->set('auth.providers.users.model', User::class);
}
}
}
$app = (new TestApp)->createApplication();
return $app;