SimpleUseCaseTest::configureKernelOptions()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 24
ccs 19
cts 19
cp 1
rs 8.9713
cc 1
eloc 15
nc 1
nop 1
crap 1
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