Skip to content

Commit 886ece0

Browse files
Add tests
1 parent 71681c2 commit 886ece0

File tree

7 files changed

+279
-10
lines changed

7 files changed

+279
-10
lines changed

Tests/Converter/NpmPackageUtilTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public function getLicenses()
4444
array(array('MIT'), array('MIT')),
4545
array(array('type' => 'MIT'), array('MIT')),
4646
array(array('name' => 'MIT'), array('MIT')),
47+
array(array(array('type' => 'MIT')), array('MIT')),
48+
array(array(array('name' => 'MIT')), array('MIT')),
4749
);
4850
}
4951

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Fxp Composer Asset Plugin package.
5+
*
6+
* (c) François Pluchino <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Fxp\Composer\AssetPlugin\Tests\Fixtures\Repository\Vcs;
13+
14+
/**
15+
* Mock vcs driver for packages test.
16+
*
17+
* @author François Pluchino <[email protected]>
18+
*/
19+
class MockVcsDriverWithException extends MockVcsDriver
20+
{
21+
/**
22+
* {@inheritdoc}
23+
*
24+
* @throws
25+
*/
26+
public function getTags()
27+
{
28+
throw new \ErrorException('Error to retrieve the tags');
29+
}
30+
}

Tests/Installer/AssetInstallerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ protected function tearDown()
122122

123123
$fs = new Filesystem();
124124
$fs->remove(sys_get_temp_dir().'/composer-test-repo-cache');
125-
$fs->remove(sys_get_temp_dir().'/composer-test/vendor');
125+
$fs->remove(sys_get_temp_dir().'/composer-test');
126126
}
127127

128128
public function testDefaultVendorDir()

Tests/Installer/IgnoreFactoryTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Composer\Config;
1616
use Composer\Package\PackageInterface;
1717
use Composer\Package\RootPackageInterface;
18+
use Composer\Util\Filesystem;
1819
use Fxp\Composer\AssetPlugin\Config\ConfigBuilder;
1920
use Fxp\Composer\AssetPlugin\Installer\IgnoreFactory;
2021
use Fxp\Composer\AssetPlugin\Installer\IgnoreManager;
@@ -95,6 +96,10 @@ protected function tearDown()
9596
$this->config = null;
9697
$this->rootPackage = null;
9798
$this->package = null;
99+
100+
$fs = new Filesystem();
101+
$fs->remove(sys_get_temp_dir().'/composer-test-repo-cache');
102+
$fs->remove(sys_get_temp_dir().'/composer-test');
98103
}
99104

100105
public function testCreateWithoutIgnoreFiles()

Tests/Repository/AbstractAssetsRepositoryTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Fxp\Composer\AssetPlugin\Repository\AssetRepositoryManager;
2323
use Fxp\Composer\AssetPlugin\Repository\AssetVcsRepository;
2424
use Fxp\Composer\AssetPlugin\Repository\VcsPackageFilter;
25+
use Symfony\Component\Filesystem\Filesystem;
2526

2627
/**
2728
* Abstract class for Tests of assets repository.
@@ -72,7 +73,7 @@ protected function setUp()
7273
$config->merge(array(
7374
'config' => array(
7475
'home' => sys_get_temp_dir().'/composer-test',
75-
'cache-repo-dir' => sys_get_temp_dir().'/composer-test-cache-repo',
76+
'cache-repo-dir' => sys_get_temp_dir().'/composer-test-repo-cache',
7677
),
7778
));
7879
/** @var VcsPackageFilter $filter */
@@ -101,6 +102,10 @@ protected function tearDown()
101102
$this->rm = null;
102103
$this->registry = null;
103104
$this->pool = null;
105+
106+
$fs = new Filesystem();
107+
$fs->remove(sys_get_temp_dir().'/composer-test-repo-cache');
108+
$fs->remove(sys_get_temp_dir().'/composer-test');
104109
}
105110

106111
public function testFindPackageMustBeAlwaysNull()

Tests/Repository/AssetVcsRepositoryTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,38 @@ public function testSkipParsingFile($type, $url, $class, $verbose)
201201
static::assertSame($validTraces, $this->io->getTraces());
202202
}
203203

204+
/**
205+
* Data provider.
206+
*
207+
* @return array
208+
*/
209+
public function getMockDriversWithExceptions()
210+
{
211+
return array(
212+
array('npm-mock', 'http://example.org/foo', 'Fxp\Composer\AssetPlugin\Tests\Fixtures\Repository\Vcs\MockVcsDriverWithException'),
213+
array('bower-mock', 'http://example.org/foo', 'Fxp\Composer\AssetPlugin\Tests\Fixtures\Repository\Vcs\MockVcsDriverWithException'),
214+
array('npm-mock', 'http://example.org/foo', 'Fxp\Composer\AssetPlugin\Tests\Fixtures\Repository\Vcs\MockVcsDriverWithException'),
215+
array('bower-mock', 'http://example.org/foo', 'Fxp\Composer\AssetPlugin\Tests\Fixtures\Repository\Vcs\MockVcsDriverWithException'),
216+
);
217+
}
218+
219+
/**
220+
* @dataProvider getMockDriversWithExceptions
221+
*
222+
* @param string $type
223+
* @param string $url
224+
* @param string $class
225+
*
226+
* @expectedException \ErrorException
227+
* @expectedExceptionMessage Error to retrieve the tags
228+
*/
229+
public function testInitFullDriverWithUncachedException($type, $url, $class)
230+
{
231+
$this->init(true, $type, $url, $class);
232+
233+
$this->repository->getComposerPackageName();
234+
}
235+
204236
/**
205237
* Data provider.
206238
*

0 commit comments

Comments
 (0)