BaseTestCase   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 43
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createApp() 0 7 1
A createRequest() 0 11 2
A call() 0 8 1
1
<?php
2
3
namespace Flatdown\Tests;
4
5
use Flatdown\Application;
6
use Middlewares\Utils\Factory\ServerRequestFactory;
7
use PHPUnit\Framework\TestCase;
8
use Psr\Http\Message\ResponseInterface;
9
use Psr\Http\Message\ServerRequestInterface;
10
11
abstract class BaseTestCase extends TestCase
12
{
13
    /**
14
     * @return Application
15
     */
16
    protected function createApp()
17
    {
18
        $app = include __DIR__ . '/../bootstrap/app.php';
19
        $this->assertInstanceOf(Application::class, $app);
20
21
        return $app;
22
    }
23
24
    /**
25
     * @param string $method
26
     * @param string $uri
27
     * @return ServerRequestInterface
28
     */
29
    protected function createRequest($method, $uri)
30
    {
31
        if (!preg_match('/^http/', $uri)) {
32
            $uri = 'http://localhost/' . ltrim($uri, '/');
33
        }
34
35
        $request = (new ServerRequestFactory())->createServerRequest($method, $uri);
36
        $this->assertInstanceOf(ServerRequestInterface::class, $request);
37
38
        return $request;
39
    }
40
41
    /**
42
     * @param ServerRequestInterface $request
43
     * @return ResponseInterface
44
     */
45
    protected function call(ServerRequestInterface $request)
46
    {
47
        $app      = $this->createApp();
48
        $response = $app->dispatch($request);
49
        $this->assertInstanceOf(ResponseInterface::class, $response);
50
51
        return $response;
52
    }
53
}
54