Completed
Push — master ( 4207f0...333332 )
by Kamil
23:19 queued 01:42
created

WebTestCase::createKernel()   B

Complexity

Conditions 5
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 15
rs 8.8571
c 1
b 0
f 1
cc 5
eloc 9
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\ThemeBundle\Tests\Functional;
13
14
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase;
15
use Symfony\Component\Filesystem\Filesystem;
16
use Symfony\Component\HttpKernel\Kernel;
17
18
class WebTestCase extends BaseWebTestCase
19
{
20
    public static function assertRedirect($response, $location)
21
    {
22
        self::assertTrue($response->isRedirect(), 'Response is not a redirect, got status code: '.$response->getStatusCode());
23
        self::assertEquals('http://localhost'.$location, $response->headers->get('Location'));
24
    }
25
26
    protected function deleteTmpDir($testCase)
27
    {
28
        if (!file_exists($dir = $this->getTmpDirPath($testCase))) {
29
            return;
30
        }
31
32
        $fs = new Filesystem();
33
        $fs->remove($dir);
34
    }
35
36
    protected function getTmpDirPath($testCase)
37
    {
38
        return sys_get_temp_dir() . '/' . Kernel::VERSION . '/' . $testCase;
39
    }
40
41
    protected static function getKernelClass()
42
    {
43
        require_once __DIR__.'/app/AppKernel.php';
44
45
        return 'Sylius\Bundle\ThemeBundle\Tests\Functional\app\AppKernel';
46
    }
47
48
    protected static function createKernel(array $options = [])
49
    {
50
        $class = self::getKernelClass();
51
52
        if (!isset($options['test_case'])) {
53
            throw new \InvalidArgumentException('The option "test_case" must be set.');
54
        }
55
56
        return new $class(
57
            $options['test_case'],
58
            isset($options['root_config']) ? $options['root_config'] : 'config.yml',
59
            isset($options['environment']) ? $options['environment'] : 'frameworkbundletest'.strtolower($options['test_case']),
60
            isset($options['debug']) ? $options['debug'] : true
61
        );
62
    }
63
}
64