LatestHandlerTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 7
dl 0
loc 53
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 14 1
A testHandle() 0 17 1
A testHandleNoVersions() 0 8 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\LatestMessage;
23
use Baleen\Cli\CommandBus\Repository\LatestHandler;
24
use Baleen\Migrations\Migration\MigrationInterface;
25
use Baleen\Migrations\Repository\RepositoryInterface;
26
use Baleen\Migrations\Version as V;
27
use Baleen\Migrations\Version\Collection\LinkedVersions;
28
use BaleenTest\Cli\CommandBus\HandlerTestCase;
29
use Mockery as m;
30
31
/**
32
 * Class LatestHandlerTest
33
 * @author Gabriel Somoza <[email protected]>
34
 */
35
class LatestHandlerTest extends HandlerTestCase
36
{
37
    /**
38
     * @inheritDoc
39
     */
40
    public function setUp()
41
    {
42
        $this->instance = m::mock(LatestHandler::class)
43
            ->shouldAllowMockingProtectedMethods()
44
            ->makePartial();
45
        $this->command = m::mock(LatestMessage::class);
46
        $comparator = function(){};
47
        $repository = m::mock(RepositoryInterface::class);
48
        $this->command->shouldReceive([
49
            'getRepository' => $repository,
50
            'getComparator' => $comparator,
51
        ])->once();
52
        parent::setUp();
53
    }
54
55
    /**
56
     * testHandle
57
     */
58
    public function testHandle()
59
    {
60
        $version = new V(1);
61
        /** @var m\Mock|MigrationInterface $migration */
62
        $migration = m::mock(MigrationInterface::class);
63
        $version->setMigration($migration);
64
        $versions = new LinkedVersions([$version]); // only thing that matters is count > 0
65
66
        $this->instance
67
            ->shouldReceive('getCollection')
68
            ->once()
69
            ->with(m::type(RepositoryInterface::class), m::type('callable'))
70
            ->andReturn($versions);
71
        $this->instance->shouldReceive('outputVersions')->once()->with($versions, $this->output);
72
73
        $this->handle();
74
    }
75
76
    /**
77
     * testHandleNoVersions
78
     */
79
    public function testHandleNoVersions()
80
    {
81
        // only thing that matters is that its empty
82
        $this->instance->shouldReceive('getCollection')->once()->andReturn([]);
83
        $this->instance->shouldNotReceive('outputVersions');
84
        $this->output->shouldReceive('writeln')->once(); // some error message
85
        $this->handle();
86
    }
87
}
88