ClassFinderSpec::let()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
1
<?php
2
3
namespace spec\Knp\RadBundle\Finder;
4
5
use PhpSpec\ObjectBehavior;
6
use Symfony\Component\Filesystem\Filesystem;
7
8
class ClassFinderSpec extends ObjectBehavior
9
{
10
    /**
11
     * @param  Symfony\Component\Finder\Finder $finder
12
     * @param  Symfony\Component\Filesystem\Filesystem $filesystem
13
     * @param  Knp\RadBundle\Reflection\ReflectionFactory $reflectionFactory
14
     */
15
    function let($finder, $filesystem, $reflectionFactory)
16
    {
17
        $this->beConstructedWith($finder, $filesystem, $reflectionFactory);
18
    }
19
20
    function it_should_find_classes_from_specified_the_namespace_directory($finder, $filesystem)
0 ignored issues
show
Coding Style introduced by
Method name "ClassFinderSpec::it_should_find_classes_from_specified_the_namespace_directory" is not in camel caps format
Loading history...
21
    {
22
        $filesystem->exists('/my/project/src/App/Entity')->willReturn(true);
23
24
        $finder->files()->shouldBeCalled();
25
        $finder->name('*.php')->shouldBeCalled();
26
        $finder->in('/my/project/src/App/Entity')->shouldBeCalled();
27
        $finder->getIterator()->willReturn(array(
28
            '/my/project/src/App/Entity/Cheese.php',
29
            '/my/project/src/App/Entity/CheeseRepository.php',
30
            '/my/project/src/App/Entity/Customer.php',
31
            '/my/project/src/App/Entity/CustomerRepository.php',
32
            '/my/project/src/App/Entity/Customer/Address.php',
33
        ));
34
35
        $this->findClasses('/my/project/src/App/Entity', 'App\Entity')->shouldReturn(array(
36
            'App\Entity\Cheese',
37
            'App\Entity\CheeseRepository',
38
            'App\Entity\Customer',
39
            'App\Entity\CustomerRepository',
40
            'App\Entity\Customer\Address',
41
        ));
42
    }
43
44
    function it_should_return_empty_array_when_directory_does_not_exist($finder, $filesystem)
0 ignored issues
show
Coding Style introduced by
Method name "ClassFinderSpec::it_should_return_empty_array_when_directory_does_not_exist" is not in camel caps format
Loading history...
45
    {
46
        $filesystem->exists('/my/project/src/App/Entity')->willReturn(false);
47
48
        $finder->in(\Prophecy\Argument::cetera())->shouldNotBeCalled();
49
        $finder->getIterator()->shouldNotBeCalled();
50
51
        $this->findClasses('/my/project/src/App/Entity', 'App\Entity')->shouldReturn(array());
52
    }
53
54
    function it_should_allow_to_filter_by_name_pattern($finder, $filesystem)
0 ignored issues
show
Coding Style introduced by
Method name "ClassFinderSpec::it_should_allow_to_filter_by_name_pattern" is not in camel caps format
Loading history...
55
    {
56
        $filesystem->exists('/my/project/src/App/Entity')->willReturn(true);
57
58
        $finder->files()->shouldBeCalled();
59
        $finder->name('*.php')->shouldBeCalled();
60
        $finder->in('/my/project/src/App/Entity')->shouldBeCalled();
61
        $finder->getIterator()->willReturn(array(
62
            '/my/project/src/App/Entity/Cheese.php',
63
            '/my/project/src/App/Entity/CheeseRepository.php',
64
            '/my/project/src/App/Entity/Customer.php',
65
            '/my/project/src/App/Entity/CustomerRepository.php',
66
            '/my/project/src/App/Entity/Customer/Address.php',
67
        ));
68
69
        $this->findClassesMatching('/my/project/src/App/Entity', 'App\Entity', '(?<!Repository)$')->shouldReturn(array(
70
            'App\Entity\Cheese',
71
            'App\Entity\Customer',
72
            'App\Entity\Customer\Address',
73
        ));
74
    }
75
76
    /**
77
     * @param ReflectionClass $cheeseRefl
78
     * @param ReflectionClass $noCheeseRefl
79
     **/
80
    function it_should_allow_to_filter_by_class_interface($reflectionFactory, $cheeseRefl, $noCheeseRefl)
0 ignored issues
show
Coding Style introduced by
Method name "ClassFinderSpec::it_should_allow_to_filter_by_class_interface" is not in camel caps format
Loading history...
81
    {
82
        $reflectionFactory->createReflectionClass('App\Entity\Cheese')->willReturn($cheeseRefl);
83
        $reflectionFactory->createReflectionClass('App\Entity\NoCheese')->willReturn($noCheeseRefl);
84
85
        $noCheeseRefl->isSubclassOf('Some\Cheese')->shouldBeCalled()->willReturn(false);
86
        $cheeseRefl->isSubclassOf('Some\Cheese')->shouldBeCalled()->willReturn(true);
87
88
        $this->filterClassesImplementing(array('App\Entity\Cheese', 'App\Entity\NoCheese'), 'Some\Cheese')->shouldReturn(array(
89
                'App\Entity\Cheese',
90
            )
91
        );
92
    }
93
}
94