AbstractRepositoryListHandlerTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 6
dl 0
loc 62
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A testGetCollectionWithNoVersions() 0 13 2
A comparatorProvider() 0 9 1
A testOutputVersions() 0 11 1
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace BaleenTest\Cli\CommandBus\Repository;
21
22
use Baleen\Cli\CommandBus\Repository\AbstractRepositoryListHandler;
23
use Baleen\Migrations\Repository\RepositoryInterface;
24
use Baleen\Migrations\Version;
25
use Baleen\Migrations\Version\Collection\LinkedVersions;
26
use BaleenTest\Cli\BaseTestCase;
27
use Mockery as m;
28
use Symfony\Component\Console\Output\OutputInterface;
29
30
/**
31
 * Class AbstractRepositoryListHandlerTest
32
 * @author Gabriel Somoza <[email protected]>
33
 */
34
class AbstractRepositoryListHandlerTest extends BaseTestCase
35
{
36
    /** @var m\Mock|AbstractRepositoryListHandler */
37
    protected $instance;
38
39
    /**
40
     * @inheritDoc
41
     */
42
    protected function setUp()
43
    {
44
        parent::setUp();
45
        $this->instance = m::mock(AbstractRepositoryListHandler::class)
46
            ->shouldAllowMockingProtectedMethods()
47
            ->makePartial();
48
    }
49
50
    /**
51
     * @param callable|null $comparator
52
     * @dataProvider comparatorProvider
53
     */
54
    public function testGetCollectionWithNoVersions(callable $comparator = null)
55
    {
56
        $repository = m::mock(RepositoryInterface::class);
57
        $versions = m::mock(LinkedVersions::class);
58
        $repository->shouldReceive('fetchAll')->once()->andReturn($versions);
59
60
        if ($comparator) {
61
            $versions->shouldReceive('sortWith')->with($comparator)->once();
62
        }
63
64
        $result = $this->invokeMethod('getCollection', $this->instance, [$repository, $comparator]);
65
        $this->assertSame($versions, $result);
66
    }
67
68
    /**
69
     * @return array
70
     */
71
    public function comparatorProvider()
72
    {
73
        return [
74
            [null],
75
            [function(Version $v1, Version $v2) {
76
                return $v1->getId() - $v2->getId();
77
            }] // implementation doesn't really matter
78
        ];
79
    }
80
81
    /**
82
     * testOutputVersions
83
     */
84
    public function testOutputVersions()
85
    {
86
        $lastVersionId = 123;
87
        $versions = m::mock(LinkedVersions::class);
88
        $versions->shouldReceive('last->getId')->once()->andReturn($lastVersionId);
89
90
        $output = m::mock(OutputInterface::class);
91
        $output->shouldReceive('writeln')->once()->with($lastVersionId);
92
93
        $this->invokeMethod('outputVersions', $this->instance, [$versions, $output]);
94
    }
95
}
96