Completed
Pull Request — master (#2)
by Dan
48:50 queued 46:56
created

SimpleUseCaseTest::getKernelClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * This file is part of the Axstrad Library.
4
 *
5
 * Copyright (c) 2015 Dan Kempster
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * Feel free to edit as you please, and have fun.
11
 *
12
 * @author Dan Kempster <[email protected]>
13
 */
14
15
namespace Axstrad\Bundle\UseCaseTestBundle\Test;
16
17
use Axstrad\Bundle\UseCaseTestBundle\Exception\BadMethodCallException;
18
19
/**
20
 * Axstrad\Bundle\UseCaseTestBundle\Test\SimpleUseCaseTest
21
 */
22
abstract class SimpleUseCaseTest extends UseCaseTest
23
{
24
    /**
25
     * Returns the namespace and path to the current function tests.
26
     *
27
     * This method has to be invoked from a subclass because it uses reflection
28
     * on the calling class to find the test's location and namespace.
29
     *
30
     * @return array
31
     * @throws BadMethodCallException If invoked directly on SimpleUseCaseTest.
32
     */
33
    protected static function getTestInfo()
34
    {
35
        $class = get_called_class();
36
        if ($class === 'Axstrad\Bundle\UseCaseTestBundle\Test\SimpleUseCaseTest') {
37
            throw new BadMethodCallException(
38
                __METHOD__.' cannot be invoked directly, it must be invoked '.
39
                ' by a subclass.'
40
            );
41
        }
42
43
        $namespaceKey = '\\Tests\\Functional';
44
        $pathKey = str_replace('\\', DIRECTORY_SEPARATOR, $namespaceKey);
45
46
        $r = new \ReflectionClass($class);
47
        $namespace = explode($namespaceKey, $r->getNamespaceName());
48
        $path = explode($pathKey, $r->getFileName());
49
50
        return array(
51
            'namespace' => $namespace[0].$namespaceKey,
52
            'path' => $path[0].$pathKey
53
        );
54
    }
55
56
    /**
57
     */
58
    protected static function getKernelClass()
59
    {
60
        $testInfo = self::getTestInfo();
61
62
        return $testInfo['namespace'].'\app\AppKernel';
63
    }
64
65
    /**
66
     * Define this method to configure the OptionsResolver.
67
     *
68
     * @param  OptionsResolver $resolver
69
     * @return void
70
     */
71
    public static function configureKernelOptions(OptionsResolver $resolver)
72
    {
73
        parent::configureKernelOptions($resolver);
74
75
        $testInfo = self::getTestInfo();
76
        $resolver->setDefaults(array(
77
            'root_dir' => $testInfo['path'].DIRECTORY_SEPARATOR.'app',
78
        ));
79
80
        $resolver
81
            ->setRequired(array(
82
                'tmp_dir',
83
            ))
84
            ->setDefaults(array(
85
                'environment' => 'test',
86
                'debug' => true,
87
                'use_case' => static::$useCase,
88
                'tmp_dir' => static::getPhpUnitXmlDir().DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, array('build', 'tmp')),
89
            ))
90
            ->setAllowedTypes(array(
91
                'debug' => 'bool',
92
            ))
93
        ;
94
    }
95
}
96