|
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\Direction; |
|
16
|
|
|
use Cubiche\Core\Comparable\SelectorComparator; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Comparator Tests Class. |
|
20
|
|
|
* |
|
21
|
|
|
* @author Ivannis Suárez Jerez <[email protected]> |
|
22
|
|
|
* @author Karel Osorio Ramírez <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
class ComparatorTests extends ComparatorTestCase |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* Test default comparator method. |
|
28
|
|
|
*/ |
|
29
|
|
|
public function testDefaultComparator() |
|
30
|
|
|
{ |
|
31
|
|
|
$this |
|
32
|
|
|
->given($comparator = Comparator::defaultComparator()) |
|
33
|
|
|
->then() |
|
34
|
|
|
->object($comparator) |
|
35
|
|
|
->isInstanceOf(ComparatorInterface::class) |
|
36
|
|
|
; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Test by method. |
|
41
|
|
|
*/ |
|
42
|
|
|
public function testBy() |
|
43
|
|
|
{ |
|
44
|
|
|
$this |
|
45
|
|
|
->given($selector = function ($value) { |
|
46
|
|
|
return $value['foo']; |
|
47
|
|
|
}) |
|
48
|
|
|
/* @var \Cubiche\Core\Comparable\SelectorComparator $comparator */ |
|
49
|
|
|
->when($comparator = Comparator::by($selector)) |
|
50
|
|
|
->then() |
|
51
|
|
|
->object($comparator) |
|
52
|
|
|
->isInstanceOf(SelectorComparator::class) |
|
53
|
|
|
->object($comparator->selector()) |
|
54
|
|
|
->isIdenticalTo($selector) |
|
55
|
|
|
->object($comparator->direction()) |
|
56
|
|
|
->isEqualTo(Direction::ASC()) |
|
57
|
|
|
->when($comparator = Comparator::by($selector, Direction::DESC())) |
|
58
|
|
|
->then() |
|
59
|
|
|
->object($comparator->direction()) |
|
60
|
|
|
->isEqualTo(Direction::DESC()) |
|
61
|
|
|
; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|