NameGeneratorSpec.php
1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace spec\Prophecy\Doubler;
use PhpSpec\ObjectBehavior;
class NameGeneratorSpec extends ObjectBehavior
{
    function its_name_generates_name_based_on_simple_class_reflection(\ReflectionClass $class)
    {
        $class->getName()->willReturn('stdClass');
        $this->name($class, array())->shouldStartWith('Double\stdClass\\');
    }
    function its_name_generates_name_based_on_namespaced_class_reflection(\ReflectionClass $class)
    {
        $class->getName()->willReturn('Some\Custom\Class');
        $this->name($class, array())->shouldStartWith('Double\Some\Custom\Class\P');
    }
    function its_name_generates_name_based_on_interface_shortnames(
        \ReflectionClass $interface1,
        \ReflectionClass $interface2
    ) {
        $interface1->getShortName()->willReturn('HandlerInterface');
        $interface2->getShortName()->willReturn('LoaderInterface');
        $this->name(null, array($interface1, $interface2))->shouldStartWith(
            'Double\HandlerInterface\LoaderInterface\P'
        );
    }
    function it_generates_proper_name_for_no_class_and_interfaces_list()
    {
        $this->name(null, array())->shouldStartWith('Double\stdClass\P');
    }
    function its_name_generates_name_based_only_on_class_if_its_available(
        \ReflectionClass $class,
        \ReflectionClass $interface1,
        \ReflectionClass $interface2
    ) {
        $class->getName()->willReturn('Some\Custom\Class');
        $interface1->getShortName()->willReturn('HandlerInterface');
        $interface2->getShortName()->willReturn('LoaderInterface');
        $this->name($class, array($interface1, $interface2))->shouldStartWith(
            'Double\Some\Custom\Class\P'
        );
    }
    public function getMatchers()
    {
        return array(
            'startWith' => function ($subject, $string) {
                return 0 === strpos($subject, $string);
            },
        );
    }
}