Passed
Branch master (c65b3c)
by Jan
05:40 queued 01:37
created

AbstractTestCase   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
c 2
b 0
f 1
lcom 1
cbo 6
dl 0
loc 62
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A runApp() 0 58 4
1
<?php
2
3
namespace Tests\Functional;
4
5
use App\Executor;
6
use App\Handler;
7
use Interop\Container\ContainerInterface;
8
use Slim\App;
9
use Slim\Http\Request;
10
use Slim\Http\Response;
11
use Slim\Http\Environment;
12
13
abstract class AbstractTestCase extends \PHPUnit_Framework_TestCase
14
{
15
16
    public function runApp($requestData = null, array $values, $command)
17
    {
18
        // Create a mock environment for testing with
19
        $environment = Environment::mock(
20
            [
21
                'REQUEST_METHOD' => 'POST',
22
                'REQUEST_URI' => '/',
23
				'HTTP_CONTENT_TYPE' => 'application/json',
24
				'HTTP_X-Gitlab-Token' => 'alksjdljzcxl'
25
            ]
26
        );
27
28
        // Set up a request object based on the environment
29
        $request = Request::createFromEnvironment($environment);
30
31
        // Add request data, if it exists
32
        if (isset($requestData)) {
33
            $request = $request->withParsedBody(json_decode($requestData, TRUE));
34
        }
35
36
        // Set up a response object
37
        $response = new Response();
38
39
        // Use the application settings
40
		if ( ! defined('CONFIG_DIR')) {
41
			define('CONFIG_DIR', __DIR__ . '/config');
42
		}
43
        $settings = require __DIR__ . '/../../src/settings.php';
44
45
        // Instantiate the application
46
        $app = new App($settings);
47
48
		// Set up dependencies
49
		require __DIR__ . '/../../src/dependencies.php';
50
51
		if ($command !== NULL) {
52
			$app->getContainer()[Executor::class] = function (ContainerInterface $c) use ($values, $command) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
53
				$mock = $this->getMockBuilder(Executor::class)
54
					->setMethods(['executeCommand'])
55
					->getMock();
56
57
				$mock->expects($this->once())
58
					->method('executeCommand')
59
					->with($this->equalTo($command), $this->equalTo($values));
60
61
				return $mock;
62
			};
63
		}
64
65
        // Register routes
66
        require __DIR__ . '/../../src/routes.php';
67
68
        // Process the application
69
        $response = $app->process($request, $response);
70
71
        // Return the response
72
        return $response;
73
    }
74
}
75