1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Cubiche package. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) Cubiche |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
namespace Cubiche\Core\Comparable\Tests\Units; |
12
|
|
|
|
13
|
|
|
use Cubiche\Core\Comparable\Comparator; |
14
|
|
|
use Cubiche\Core\Comparable\ComparatorInterface; |
15
|
|
|
use Cubiche\Core\Comparable\ComparatorVisitorInterface; |
16
|
|
|
use Cubiche\Core\Comparable\MultiComparator; |
17
|
|
|
use Cubiche\Core\Visitor\Tests\Units\VisiteeInterfaceTestCase; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Comparator Interface Test Case Class. |
21
|
|
|
* |
22
|
|
|
* @author Ivannis Suárez Jerez <[email protected]> |
23
|
|
|
* @author Karel Osorio Ramírez <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
abstract class ComparatorInterfaceTestCase extends VisiteeInterfaceTestCase |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Test create. |
29
|
|
|
*/ |
30
|
|
|
public function testCreate() |
31
|
|
|
{ |
32
|
|
|
$this |
33
|
|
|
->given($comparator = $this->newDefaultTestedInstance()) |
34
|
|
|
->then() |
35
|
|
|
->object($comparator) |
36
|
|
|
->isInstanceOf(ComparatorInterface::class) |
37
|
|
|
; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Test reverse. |
42
|
|
|
*/ |
43
|
|
|
public function testReverse() |
44
|
|
|
{ |
45
|
|
|
$this |
46
|
|
|
/* @var \Cubiche\Core\Comparable\ComparatorInterface $comparator */ |
47
|
|
|
->given($comparator = $this->newDefaultTestedInstance()) |
48
|
|
|
->then() |
49
|
|
|
->object($comparator->reverse()) |
50
|
|
|
->isInstanceOf(ComparatorInterface::class) |
51
|
|
|
; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Test compare. |
56
|
|
|
* |
57
|
|
|
* @param mixed $a |
58
|
|
|
* @param mixed $b |
59
|
|
|
* @param int $expected |
60
|
|
|
* |
61
|
|
|
* @dataProvider compareDataProvider |
62
|
|
|
*/ |
63
|
|
|
public function testCompare($a, $b, $expected) |
64
|
|
|
{ |
65
|
|
|
$this |
66
|
|
|
/* @var \Cubiche\Core\Comparable\ComparatorInterface $comparator */ |
67
|
|
|
->given($comparator = $this->newDefaultTestedInstance()) |
68
|
|
|
->then() |
69
|
|
|
->integer($comparator->compare($a, $b)) |
70
|
|
|
->isEqualTo($expected) |
71
|
|
|
; |
72
|
|
|
|
73
|
|
|
$this |
74
|
|
|
->given($reverse = $comparator->reverse()) |
75
|
|
|
->then() |
76
|
|
|
->integer($reverse->compare($a, $b)) |
77
|
|
|
->isEqualTo(-1 * $expected) |
78
|
|
|
; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Test orX. |
83
|
|
|
*/ |
84
|
|
|
public function testOrX() |
85
|
|
|
{ |
86
|
|
|
$this |
87
|
|
|
/* @var \Cubiche\Core\Comparable\ComparatorInterface $comparator */ |
88
|
|
|
->given($comparator = $this->newDefaultTestedInstance()) |
89
|
|
|
->then() |
90
|
|
|
->when($result = $comparator->orX($comparator->reverse())) |
91
|
|
|
->object($result) |
92
|
|
|
->isInstanceOf(MultiComparator::class) |
93
|
|
|
; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/* |
97
|
|
|
* Test __call. |
98
|
|
|
*/ |
99
|
|
|
public function testMagicCall() |
100
|
|
|
{ |
101
|
|
|
$this |
102
|
|
|
/* @var \Cubiche\Core\Comparable\ComparatorInterface $comparatorMock */ |
103
|
|
|
->given($comparatorMock = $this->newDefaultMockTestedInstance()) |
104
|
|
|
->given($comparator = $this->newDefaultTestedInstance()) |
105
|
|
|
->when($comparatorMock->or($comparator)) |
106
|
|
|
->mock($comparatorMock) |
107
|
|
|
->call('orX') |
108
|
|
|
->withArguments($comparator) |
109
|
|
|
->once() |
110
|
|
|
; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* {@inheritdoc} |
115
|
|
|
*/ |
116
|
|
|
protected function visitorInterface() |
117
|
|
|
{ |
118
|
|
|
return ComparatorVisitorInterface::class; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return array |
123
|
|
|
*/ |
124
|
|
|
abstract protected function compareDataProvider(); |
125
|
|
|
} |
126
|
|
|
|