Completed
Push — master ( 13ee85...192638 )
by Ivannis Suárez
02:46
created

ComparatorInterfaceTestCase::testClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
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\MultiComparator;
16
use Cubiche\Core\Visitor\Tests\Units\VisiteeInterfaceTestCase;
17
18
/**
19
 * Comparator Interface Test Case Class.
20
 *
21
 * @author Ivannis Suárez Jerez <[email protected]>
22
 * @author Karel Osorio Ramírez <[email protected]>
23
 */
24
abstract class ComparatorInterfaceTestCase extends VisiteeInterfaceTestCase
25
{
26
    /**
27
     * Test class.
28
     */
29
    public function testClass()
30
    {
31
        $this
32
            ->testedClass
33
                ->implements(ComparatorInterface::class)
34
        ;
35
    }
36
37
    /**
38
     * Test reverse.
39
     */
40
    public function testReverse()
41
    {
42
        $this
43
            /* @var \Cubiche\Core\Comparable\ComparatorInterface $comparator */
44
            ->given($comparator = $this->newDefaultTestedInstance())
45
            ->then()
46
                ->object($comparator->reverse())
47
                    ->isInstanceOf(ComparatorInterface::class)
48
        ;
49
    }
50
51
    /**
52
     * Test compare.
53
     *
54
     * @param mixed $a
55
     * @param mixed $b
56
     * @param int   $expected
57
     *
58
     * @dataProvider compareDataProvider
59
     */
60
    public function testCompare($a, $b, $expected)
61
    {
62
        $this
63
            /* @var \Cubiche\Core\Comparable\ComparatorInterface $comparator */
64
            ->given($comparator = $this->newDefaultTestedInstance())
65
            ->then()
66
                ->integer($comparator->compare($a, $b))
67
                    ->isEqualTo($expected)
68
        ;
69
70
        $this
71
            ->given($reverse = $comparator->reverse())
72
            ->then()
73
                ->integer($reverse->compare($a, $b))
74
                    ->isEqualTo(-1 * $expected)
75
        ;
76
    }
77
78
    /**
79
     * Test orX.
80
     */
81
    public function testOrX()
82
    {
83
        $this
84
            /* @var \Cubiche\Core\Comparable\ComparatorInterface $comparator */
85
            ->given($comparator = $this->newDefaultTestedInstance())
86
            ->then()
87
            ->when($result = $comparator->orX($comparator->reverse()))
88
                ->object($result)
89
                    ->isInstanceOf(MultiComparator::class)
90
        ;
91
    }
92
93
    /*
94
     * Test __call.
95
     */
96
    public function testMagicCall()
97
    {
98
        $this
99
            /* @var \Cubiche\Core\Comparable\ComparatorInterface $comparatorMock */
100
            ->given($comparatorMock = $this->newDefaultMockTestedInstance())
101
            ->given($comparator = $this->newDefaultTestedInstance())
102
            ->when($comparatorMock->or($comparator))
103
                ->mock($comparatorMock)
104
                    ->call('orX')
105
                        ->withArguments($comparator)
106
                        ->once()
107
        ;
108
    }
109
110
    /**
111
     * @return array
112
     */
113
    abstract protected function compareDataProvider();
114
}
115