Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
francoispluchino committed Aug 8, 2019
1 parent 71681c2 commit 886ece0
Show file tree
Hide file tree
Showing 7 changed files with 279 additions and 10 deletions.
2 changes: 2 additions & 0 deletions Tests/Converter/NpmPackageUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public function getLicenses()
array(array('MIT'), array('MIT')),
array(array('type' => 'MIT'), array('MIT')),
array(array('name' => 'MIT'), array('MIT')),
array(array(array('type' => 'MIT')), array('MIT')),
array(array(array('name' => 'MIT')), array('MIT')),
);
}

Expand Down
30 changes: 30 additions & 0 deletions Tests/Fixtures/Repository/Vcs/MockVcsDriverWithException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/*
* This file is part of the Fxp Composer Asset Plugin package.
*
* (c) François Pluchino <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Fxp\Composer\AssetPlugin\Tests\Fixtures\Repository\Vcs;

/**
* Mock vcs driver for packages test.
*
* @author François Pluchino <[email protected]>
*/
class MockVcsDriverWithException extends MockVcsDriver
{
/**
* {@inheritdoc}
*
* @throws
*/
public function getTags()
{
throw new \ErrorException('Error to retrieve the tags');
}
}
2 changes: 1 addition & 1 deletion Tests/Installer/AssetInstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ protected function tearDown()

$fs = new Filesystem();
$fs->remove(sys_get_temp_dir().'/composer-test-repo-cache');
$fs->remove(sys_get_temp_dir().'/composer-test/vendor');
$fs->remove(sys_get_temp_dir().'/composer-test');
}

public function testDefaultVendorDir()
Expand Down
5 changes: 5 additions & 0 deletions Tests/Installer/IgnoreFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Composer\Config;
use Composer\Package\PackageInterface;
use Composer\Package\RootPackageInterface;
use Composer\Util\Filesystem;
use Fxp\Composer\AssetPlugin\Config\ConfigBuilder;
use Fxp\Composer\AssetPlugin\Installer\IgnoreFactory;
use Fxp\Composer\AssetPlugin\Installer\IgnoreManager;
Expand Down Expand Up @@ -95,6 +96,10 @@ protected function tearDown()
$this->config = null;
$this->rootPackage = null;
$this->package = null;

$fs = new Filesystem();
$fs->remove(sys_get_temp_dir().'/composer-test-repo-cache');
$fs->remove(sys_get_temp_dir().'/composer-test');
}

public function testCreateWithoutIgnoreFiles()
Expand Down
7 changes: 6 additions & 1 deletion Tests/Repository/AbstractAssetsRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Fxp\Composer\AssetPlugin\Repository\AssetRepositoryManager;
use Fxp\Composer\AssetPlugin\Repository\AssetVcsRepository;
use Fxp\Composer\AssetPlugin\Repository\VcsPackageFilter;
use Symfony\Component\Filesystem\Filesystem;

/**
* Abstract class for Tests of assets repository.
Expand Down Expand Up @@ -72,7 +73,7 @@ protected function setUp()
$config->merge(array(
'config' => array(
'home' => sys_get_temp_dir().'/composer-test',
'cache-repo-dir' => sys_get_temp_dir().'/composer-test-cache-repo',
'cache-repo-dir' => sys_get_temp_dir().'/composer-test-repo-cache',
),
));
/** @var VcsPackageFilter $filter */
Expand Down Expand Up @@ -101,6 +102,10 @@ protected function tearDown()
$this->rm = null;
$this->registry = null;
$this->pool = null;

$fs = new Filesystem();
$fs->remove(sys_get_temp_dir().'/composer-test-repo-cache');
$fs->remove(sys_get_temp_dir().'/composer-test');
}

public function testFindPackageMustBeAlwaysNull()
Expand Down
32 changes: 32 additions & 0 deletions Tests/Repository/AssetVcsRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,38 @@ public function testSkipParsingFile($type, $url, $class, $verbose)
static::assertSame($validTraces, $this->io->getTraces());
}

/**
* Data provider.
*
* @return array
*/
public function getMockDriversWithExceptions()
{
return array(
array('npm-mock', 'http://example.org/foo', 'Fxp\Composer\AssetPlugin\Tests\Fixtures\Repository\Vcs\MockVcsDriverWithException'),
array('bower-mock', 'http://example.org/foo', 'Fxp\Composer\AssetPlugin\Tests\Fixtures\Repository\Vcs\MockVcsDriverWithException'),
array('npm-mock', 'http://example.org/foo', 'Fxp\Composer\AssetPlugin\Tests\Fixtures\Repository\Vcs\MockVcsDriverWithException'),
array('bower-mock', 'http://example.org/foo', 'Fxp\Composer\AssetPlugin\Tests\Fixtures\Repository\Vcs\MockVcsDriverWithException'),
);
}

/**
* @dataProvider getMockDriversWithExceptions
*
* @param string $type
* @param string $url
* @param string $class
*
* @expectedException \ErrorException
* @expectedExceptionMessage Error to retrieve the tags
*/
public function testInitFullDriverWithUncachedException($type, $url, $class)
{
$this->init(true, $type, $url, $class);

$this->repository->getComposerPackageName();
}

/**
* Data provider.
*
Expand Down
Loading

0 comments on commit 886ece0

Please sign in to comment.