Skip to content

Commit bd0e992

Browse files
committed
Improve tests
1 parent d141f81 commit bd0e992

File tree

1 file changed

+54
-2
lines changed

1 file changed

+54
-2
lines changed

tests/Diff/DiffEntryTest.php

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,72 @@ public function testGetPackage()
5757
$this->assertSame($package, $entry->getPackage());
5858
}
5959

60+
/**
61+
* @param string $expectedUrl
62+
*
63+
* @dataProvider operationUrlProvider
64+
*/
65+
public function testUrls($expectedUrl, OperationInterface $operation)
66+
{
67+
$urlGenerator = $this->getMockBuilder('IonBazan\ComposerDiff\Url\UrlGenerator')->getMock();
68+
$urlGenerator->method('getCompareUrl')->willReturn('compare');
69+
$urlGenerator->method('getProjectUrl')->willReturn('project');
70+
$urlGenerator->method('getReleaseUrl')->willReturn('release');
71+
72+
$entry = new DiffEntry($operation, $urlGenerator);
73+
$this->assertSame($expectedUrl, $entry->getUrl());
74+
$this->assertSame('project', $entry->getProjectUrl());
75+
}
76+
6077
public function testGetUrlReturnsNullForInvalidOperation()
6178
{
6279
$operation = $this->getMockBuilder('Composer\DependencyResolver\Operation\OperationInterface')->getMock();
63-
$entry = new DiffEntry($operation);
64-
$this->assertNull($entry->getUrl());
80+
$this->setExpectedException('InvalidArgumentException', 'Invalid operation');
81+
new DiffEntry($operation, $this->getMockBuilder('IonBazan\ComposerDiff\Url\UrlGenerator')->getMock());
6582
}
6683

6784
public function testGetProjectUrlReturnsNullForInvalidOperation()
85+
{
86+
$operation = $this->getMockBuilder('Composer\DependencyResolver\Operation\OperationInterface')->getMock();
87+
$this->setExpectedException('InvalidArgumentException', 'Invalid operation');
88+
new DiffEntry($operation, $this->getMockBuilder('IonBazan\ComposerDiff\Url\UrlGenerator')->getMock());
89+
}
90+
91+
public function testCreateWithoutUrlGenerators()
6892
{
6993
$operation = $this->getMockBuilder('Composer\DependencyResolver\Operation\OperationInterface')->getMock();
7094
$entry = new DiffEntry($operation);
95+
96+
$this->assertNull($entry->getUrl());
7197
$this->assertNull($entry->getProjectUrl());
7298
}
7399

100+
public function operationUrlProvider()
101+
{
102+
return array(
103+
'Install shows release URL' => array(
104+
'release',
105+
new InstallOperation($this->getPackage('a/package-1', '1.0.0')),
106+
),
107+
'Remove shows release URL' => array(
108+
'release',
109+
new UninstallOperation($this->getPackage('a/package-1', '1.0.0')),
110+
),
111+
'Upgrade shows compare URL' => array(
112+
'compare',
113+
new UpdateOperation($this->getPackage('a/package-1', '1.0.0'), $this->getPackage('a/package-1', '2.0.0')),
114+
),
115+
'Downgrade shows compare URL' => array(
116+
'compare',
117+
new UpdateOperation($this->getPackage('a/package-1', '2.0.0'), $this->getPackage('a/package-1', '1.0.0')),
118+
),
119+
'Change shows compare URL' => array(
120+
'compare',
121+
new UpdateOperation($this->getPackage('a/package-1', 'dev-master', 'dev-master 1234567'), $this->getPackage('a/package-1', '1.0.0')),
122+
),
123+
);
124+
}
125+
74126
public function operationTypeProvider()
75127
{
76128
return array(

0 commit comments

Comments
 (0)