Completed
Push — master ( 53b35c...4f4192 )
by Peter
06:07
created

it_is_not_convertible_arguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 3
1
<?php
2
3
namespace tests\Happyr\DoctrineSpecification\Operand;
4
5
use Happyr\DoctrineSpecification\Exception\NotConvertibleException;
6
use Happyr\DoctrineSpecification\Operand\ArgumentToOperandConverter;
7
use Happyr\DoctrineSpecification\Operand\Field;
8
use Happyr\DoctrineSpecification\Operand\Operand;
9
use Happyr\DoctrineSpecification\Operand\Value;
10
use PhpSpec\ObjectBehavior;
11
12
/**
13
 * @mixin ArgumentToOperandConverter
14
 */
15
class ArgumentToOperandConverterSpec extends ObjectBehavior
16
{
17
    public function it_is_a_converter()
18
    {
19
        $this->shouldBeAnInstanceOf(ArgumentToOperandConverter::class);
20
    }
21
22
    public function it_not_convert_operand_to_field(Operand $operand)
23
    {
24
        $this->toField($operand)->shouldReturn($operand);
25
    }
26
27
    public function it_convert_argument_to_field()
28
    {
29
        $this->toField('foo')->shouldBeAnInstanceOf(Field::class);
30
    }
31
32
    public function it_not_convert_operand_to_value(Operand $operand)
33
    {
34
        $this->toValue($operand)->shouldReturn($operand);
35
    }
36
37
    public function it_convert_argument_to_value()
38
    {
39
        $this->toValue('foo')->shouldBeAnInstanceOf(Value::class);
40
    }
41
42
    public function it_is_all_arguments_a_operands(Operand $first, Operand $second)
43
    {
44
        $arguments = array($first, $second);
45
        $this->isAllOperands($arguments)->shouldReturn(true);
46
    }
47
48
    public function it_is_not_all_arguments_a_operands(Operand $first, Operand $second)
49
    {
50
        $arguments = array($first, 'foo', $second);
51
        $this->isAllOperands($arguments)->shouldReturn(false);
52
    }
53
54
    public function it_no_nothing_to_convert()
55
    {
56
        $this->convert(array())->shouldReturn([]);
57
    }
58
59
    public function it_a_convertible_field()
60
    {
61
        $subject = $this->convert(array('foo'));
62
        $subject->shouldBeArray();
63
        $subject->shouldHaveCount(1);
64
        $subject->shouldHaveField();
65
    }
66
67
    public function it_a_already_converted_field(Operand $field)
68
    {
69
        $this->convert(array($field))->shouldReturn(array($field));
70
    }
71
72
    public function it_a_convertible_field_and_value()
73
    {
74
        $subject = $this->convert(array('foo', 'bar'));
75
        $subject->shouldBeArray();
76
        $subject->shouldHaveCount(2);
77
        $subject->shouldHaveField();
78
        $subject->shouldHaveValue();
79
    }
80
81
    public function it_a_already_converted_value(Operand $field, Operand $value)
82
    {
83
        $this->convert(array($field, $value))->shouldReturn(array($field, $value));
84
    }
85
86
    public function it_a_already_converted_value2(Operand $value)
87
    {
88
        $subject = $this->convert(array('foo', $value));
89
        $subject->shouldBeArray();
90
        $subject->shouldHaveCount(2);
91
        $subject->shouldHaveField();
92
        $subject->shouldHaveOperandAt(1);
93
    }
94
95
    public function it_a_convertible_arguments(Operand $first, Operand $second)
96
    {
97
        $subject = $this->convert(array('foo', $first, $second, 'bar'));
98
        $subject->shouldBeArray();
99
        $subject->shouldHaveCount(4);
100
        $subject->shouldHaveField();
101
        $subject->shouldHaveValue();
102
        $subject->shouldHaveOperandAt(1);
103
        $subject->shouldHaveOperandAt(2);
104
    }
105
106
    public function it_is_not_convertible_arguments(Field $field, Operand $operand, Value $value)
107
    {
108
        $this->shouldThrow(NotConvertibleException::class)
109
            ->duringConvert(array($field, $operand, 'foo', $value));
110
    }
111
112
    public function getMatchers()
113
    {
114
        return array(
115
            'haveField' => function ($subject) {
116
                return $subject[0] instanceof Field;
117
            },
118
            'haveValue' => function ($subject) {
119
                return $subject[count($subject) - 1] instanceof Value;
120
            },
121
            'haveOperandAt' => function ($subject, $position) {
122
                return $subject[$position] instanceof Operand;
123
            },
124
        );
125
    }
126
}
127