Completed
Pull Request — master (#19)
by Sullivan
03:10
created

DependsCommandWrapperTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 18 1
A testWithoutDepends() 0 10 1
A testWithDepends() 0 22 1
1
<?php
2
3
namespace SLLH\ComposerVersionsCheck\Tests;
4
5
use Composer\Composer;
6
use Composer\Package\Link;
7
use Composer\Package\Package;
8
use Composer\Repository\WritableRepositoryInterface;
9
use SLLH\ComposerVersionsCheck\DependsCommandWrapper;
10
11
/**
12
 * @author Sullivan Senechal <[email protected]>
13
 */
14
class DependsCommandWrapperTest extends \PHPUnit_Framework_TestCase
15
{
16
    /**
17
     * @var Composer
18
     */
19
    private $composer;
20
21
    /**
22
     * @var WritableRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
23
     */
24
    private $localRepository;
25
26
    protected function setUp()
27
    {
28
        $this->composer = $this->getMockBuilder('Composer\Composer')
29
            ->disableOriginalConstructor()->getMock();
30
31
        $eventDispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')
32
            ->disableOriginalConstructor()->getMock();
33
        $this->composer->expects($this->any())
34
            ->method('getEventDispatcher')->willReturn($eventDispatcher);
35
36
        $this->localRepository = $this->getMock('Composer\Repository\WritableRepositoryInterface');
37
        $repositoryManager = $this->getMockBuilder('Composer\Repository\RepositoryManager')
38
            ->disableOriginalConstructor()->getMock();
39
        $repositoryManager->expects($this->any())
40
            ->method('getLocalRepository')->willReturn($this->localRepository);
41
        $this->composer->expects($this->any())
42
            ->method('getRepositoryManager')->willReturn($repositoryManager);
43
    }
44
45
    public function testWithoutDepends()
46
    {
47
        $wrapper = new DependsCommandWrapper($this->composer);
48
        $package = new Package('foo/bar', '1.0.0', '1.0.0');
49
50
        $this->localRepository->expects($this->atLeastOnce())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Composer\Reposito...bleRepositoryInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
51
            ->method('getPackages')->willReturn(array($package));
52
53
        $this->assertSame(array(), $wrapper->dependsOutput($package));
54
    }
55
56
    public function testWithDepends()
57
    {
58
        $wrapper = new DependsCommandWrapper($this->composer);
59
        $package = new Package('foo/bar', '1.0.0', '1.0.0');
60
61
        $depPackage01 = new Package('dummy/library', '2.4.5', '2.4.5');
62
        $depPackage01->setRequires(array(new Link('dummy/library', 'foo/bar', null, 'relates to', '~1.0')));
63
        $depPackage02 = new Package('dummy/project', '1.1.2', '1.1.2');
64
        $depPackage02->setRequires(array(new Link('dummy/project', 'foo/bar', null, 'relates to', '1.0.*')));
65
66
        $this->localRepository->expects($this->atLeastOnce())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Composer\Reposito...bleRepositoryInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
67
            ->method('getPackages')->willReturn(array(
68
                $package,
69
                $depPackage01,
70
                $depPackage02,
71
            ));
72
73
        $this->assertSame(array(
74
            '    dummy/library requires foo/bar (~1.0)',
75
            '    dummy/project requires foo/bar (1.0.*)',
76
        ), $wrapper->dependsOutput($package));
77
    }
78
}
79