SimpleUseCaseTest::getTestInfo()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2.0393

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 11
cts 14
cp 0.7856
rs 9.2
c 0
b 0
f 0
cc 2
eloc 14
nc 2
nop 0
crap 2.0393
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
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
19
20
/**
21
 * Axstrad\Bundle\UseCaseTestBundle\Test\SimpleUseCaseTest
22
 */
23
abstract class SimpleUseCaseTest extends UseCaseTest
24
{
25
    /**
26
     * Returns the namespace and path to the current function tests.
27
     *
28
     * This method has to be invoked from a subclass because it uses reflection
29
     * on the calling class to find the test's location and namespace.
30
     *
31
     * @return array
32
     * @throws BadMethodCallException If invoked directly on SimpleUseCaseTest.
33
     */
34 1
    protected static function getTestInfo()
35
    {
36 1
        $class = get_called_class();
37 1
        if ($class === 'Axstrad\Bundle\UseCaseTestBundle\Test\SimpleUseCaseTest') {
38
            throw new BadMethodCallException(
39
                __METHOD__.' cannot be invoked directly, it must be invoked '.
40
                ' by a subclass.'
41
            );
42
        }
43
44 1
        $namespaceKey = '\\Tests\\Functional';
45 1
        $pathKey = str_replace('\\', DIRECTORY_SEPARATOR, $namespaceKey);
46
47 1
        $r = new \ReflectionClass($class);
48 1
        $namespace = explode($namespaceKey, $r->getNamespaceName());
49 1
        $path = explode($pathKey, $r->getFileName());
50
51
        return array(
52 1
            'namespace' => $namespace[0].$namespaceKey,
53 1
            'path' => $path[0].$pathKey
54 1
        );
55
    }
56
57
    /**
58
     */
59 1
    protected static function getKernelClass()
60
    {
61 1
        $testInfo = self::getTestInfo();
62
63 1
        return $testInfo['namespace'].'\app\AppKernel';
64
    }
65
66
    /**
67
     * Define this method to configure the OptionsResolver.
68
     *
69
     * @param  OptionsResolverInterface $resolver
70
     * @return void
71
     */
72 1
    public static function configureKernelOptions(OptionsResolverInterface $resolver)
73
    {
74 1
        parent::configureKernelOptions($resolver);
75
76 1
        $testInfo = self::getTestInfo();
77 1
        $resolver->setDefaults(array(
78 1
            'root_dir' => $testInfo['path'].DIRECTORY_SEPARATOR.'app',
79 1
        ));
80
81
        $resolver
82 1
            ->setRequired(array(
83 1
                'tmp_dir',
84 1
            ))
85 1
            ->setDefaults(array(
86 1
                'environment' => 'test',
87 1
                'debug' => true,
88 1
                'use_case' => static::$useCase,
89 1
                'tmp_dir' => static::getPhpUnitXmlDir().DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, array('build', 'tmp')),
90 1
            ))
91 1
            ->setAllowedTypes(array(
92 1
                'debug' => 'bool',
93 1
            ))
94
        ;
95 1
    }
96
}
97