CreatesApplication::createApplication()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Cerbero\OctaneTestbench\Concerns;
4
5
use Laravel\Octane\ApplicationFactory;
6
use Laravel\Octane\Events\RequestReceived;
7
use Mockery;
8
9
/**
10
 * The trait to create an Octane application.
11
 *
12
 */
13
trait CreatesApplication
14
{
15
    /**
16
     * Create the Laravel Octane application.
17
     *
18
     * @return \Symfony\Component\HttpKernel\HttpKernelInterface
19
     */
20 15
    public function createApplication()
21
    {
22 15
        $factory = new ApplicationFactory($this->getBasePath());
23 15
        $bindings = $this->getInitialServerBindings();
24 15
        $app = $factory->warm($factory->createApplication($bindings));
25
26 15
        $app->events->forget(RequestReceived::class);
27
28 15
        return $app;
29
    }
30
31
    /**
32
     * Retrieve the application base path.
33
     *
34
     * @return string
35
     */
36
    protected function getBasePath(): string
37
    {
38
        return realpath(dirname(__DIR__, 5));
39
    }
40
41
    /**
42
     * Retrieve the initial services to bind for the server in use
43
     *
44
     * @return array
45
     */
46 15
    protected function getInitialServerBindings(): array
47
    {
48 15
        $serverState = [];
49 15
        $serverState['octaneConfig'] = require $this->getBasePath() . '/config/octane.php';
50
51 15
        if ($serverState['octaneConfig']['server'] == 'roadrunner') {
52
            return [];
53
        }
54
55 15
        $workerState = (object) ['tables' => require $this->getOctaneBinPath() . '/createSwooleTables.php'];
56
57
        return [
58 15
            'octane.cacheTable' => require $this->getOctaneBinPath() . '/createSwooleCacheTable.php',
59 15
            'Swoole\Http\Server' => Mockery::spy('Swoole\Http\Server'),
60
            'Laravel\Octane\Swoole\WorkerState' => $workerState,
61
        ];
62
    }
63
64
    /**
65
     * Retrieve the Octane bin path.
66
     *
67
     * @return string
68
     */
69
    protected function getOctaneBinPath(): string
70
    {
71
        return $this->getBasePath() . '/vendor/laravel/octane/bin';
72
    }
73
}
74