Completed
Pull Request — master (#2)
by Dan
64:54 queued 63:07
created

SimpleUseCaseTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 91.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 74
ccs 33
cts 36
cp 0.9167
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getTestInfo() 0 22 2
A getKernelClass() 0 6 1
B configureKernelOptions() 0 24 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\OptionsResolver;
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  OptionsResolver $resolver
70
     * @return void
71
     */
72 1
    public static function configureKernelOptions(OptionsResolver $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
0 ignored issues
show
Bug introduced by
The call to setAllowedTypes() misses a required argument $allowedTypes.

This check looks for function calls that miss required arguments.

Loading history...
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(
0 ignored issues
show
Documentation introduced by
array('debug' => 'bool') is of type array<string,string,{"debug":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
92 1
                'debug' => 'bool',
93 1
            ))
94
        ;
95 1
    }
96
}
97