Completed
Push — master ( 0708d4...99f0e4 )
by Rafał
02:36
created

WebTestCase   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 41
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A assertRedirect() 0 5 1
A deleteTmpDir() 0 9 2
A getKernelClass() 0 6 1
B createKernel() 0 15 5
1
<?php
2
3
/**
4
 * This file is part of the Superdesk Web Publisher Bridge Bundle.
5
 *
6
 * Copyright 2016 Sourcefabric z.u. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2016 Sourcefabric z.ú.
12
 * @license http://www.superdesk.org/license
13
 */
14
namespace SWP\Bundle\BridgeBundle\Tests\Functional;
15
16
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase;
17
use Symfony\Component\Filesystem\Filesystem;
18
use Symfony\Component\HttpKernel\Kernel;
19
20
class WebTestCase extends BaseWebTestCase
21
{
22
    public static function assertRedirect($response, $location)
23
    {
24
        self::assertTrue($response->isRedirect(), 'Response is not a redirect, got status code: '.$response->getStatusCode());
25
        self::assertEquals('http://localhost'.$location, $response->headers->get('Location'));
26
    }
27
28
    protected static function deleteTmpDir($testCase)
29
    {
30
        if (!file_exists($dir = sys_get_temp_dir().'/'.Kernel::VERSION.'/'.$testCase)) {
31
            return;
32
        }
33
34
        $fs = new Filesystem();
35
        $fs->remove($dir);
36
    }
37
38
    protected static function getKernelClass()
39
    {
40
        require_once __DIR__.'/app/AppKernel.php';
41
42
        return 'SWP\Bundle\BridgeBundle\Tests\Functional\app\AppKernel';
43
    }
44
45
    protected static function createKernel(array $options = array())
46
    {
47
        $class = self::getKernelClass();
48
49
        if (!isset($options['test_case'])) {
50
            throw new \InvalidArgumentException('The option "test_case" must be set.');
51
        }
52
53
        return new $class(
54
            $options['test_case'],
55
            isset($options['root_config']) ? $options['root_config'] : 'config.yml',
56
            isset($options['environment']) ? $options['environment'] : 'frameworkbundletest'.strtolower($options['test_case']),
57
            isset($options['debug']) ? $options['debug'] : true
58
        );
59
    }
60
}
61