AbstractScalarValueObjectTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 4
Metric Value
wmc 6
cbo 4
dl 0
loc 94
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testIsNotSameAs() 0 8 1
A getValues() 0 12 1
A testInvalidValues() 0 4 1
A getInvalidValues() 0 11 1
A getStdClassWithProperty() 0 7 1
A getAbstractScalarValueObjectMock() 0 19 1
1
<?php
2
3
namespace Tests\Unit\Utils\Domain;
4
5
use Tests\Unit\Utils\Domain\Mocks\ScalarValueObjectMock;
6
7
/**
8
 * AbstractScalarValueObject Test
9
 */
10
class AbstractScalarValueObjectTest extends \PHPUnit_Framework_TestCase
11
{
12
    /**
13
     * @param bool  $expectedResult
14
     * @param mixed $value
15
     * @param mixed $otherValue
16
     *
17
     * @dataProvider getValues
18
     */
19
    public function testIsNotSameAs($expectedResult, $value, $otherValue)
20
    {
21
        $valueObject = new ScalarValueObjectMock($value);
22
23
        $this->assertEquals($expectedResult, $valueObject->isSameAs($otherValue));
24
        $this->assertEquals((string) $value, (string) $valueObject);
25
        $this->assertTrue($value === $valueObject->getRawValue());
26
    }
27
28
    /**
29
     * @return array
30
     */
31
    public function getValues()
32
    {
33
        return array(
34
            array(true, 'identical', new ScalarValueObjectMock('identical')),
35
            array(true, -1, new ScalarValueObjectMock(-1)),
36
37
            array(false, 'identical', $this->getAbstractScalarValueObjectMock()),
38
            array(false, 'a', new ScalarValueObjectMock('b')),
39
            array(false, 0, new ScalarValueObjectMock('')),
40
            array(false, 'test', 'test'),
41
        );
42
    }
43
44
    /**
45
     * @param mixed $value
46
     *
47
     * @dataProvider getInvalidValues
48
     * @expectedException \InvalidArgumentException
49
     */
50
    public function testInvalidValues($value)
51
    {
52
        new ScalarValueObjectMock($value);
53
    }
54
55
    /**
56
     * @return array
57
     */
58
    public function getInvalidValues()
59
    {
60
        return array(
61
            array(new \stdClass()),
62
            array($this->getStdClassWithProperty()),
63
            array(array()),
64
            array(array(1234)),
65
            array(new ScalarValueObjectMock(1234)),
66
            array(fopen(dirname(__FILE__), 'r')),
67
        );
68
    }
69
70
    /**
71
     * @return \stdClass
72
     */
73
    protected function getStdClassWithProperty()
74
    {
75
        $stdClassWithProperty = new \stdClass();
76
        $stdClassWithProperty->test = true;
77
78
        return $stdClassWithProperty;
79
    }
80
81
    /**
82
     * @return \PHPUnit_Framework_MockObject_MockObject
83
     */
84
    protected function getAbstractScalarValueObjectMock()
85
    {
86
        $mock = $this->getMockForAbstractClass(
87
            '\Utils\Domain\AbstractScalarValueObject',
88
            array(),
89
            '',
90
            false,
91
            false,
92
            true,
93
            array(
94
                'getRawValue'
95
            )
96
        );
97
        $mock->expects($this->any())
98
            ->method('getRawValue')
99
            ->will($this->returnValue('identical'));
100
101
        return $mock;
102
    }
103
}
104