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()) |
|
|
|
|
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()) |
|
|
|
|
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
|
|
|
|
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.