protected function setUp() { $this->fs = new Filesystem(); $this->composer = new Composer(); $this->config = new Config(); $this->composer->setConfig($this->config); $this->vendorDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'composer-test-vendor'; $this->ensureDirectoryExistsAndClear($this->vendorDir); $this->binDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'composer-test-bin'; $this->ensureDirectoryExistsAndClear($this->binDir); $this->config->merge(array('config' => array('vendor-dir' => $this->vendorDir, 'bin-dir' => $this->binDir))); $this->dm = $this->getMockBuilder('Composer\\Downloader\\DownloadManager')->disableOriginalConstructor()->getMock(); /* @var DownloadManager $dm */ $dm = $this->dm; $this->composer->setDownloadManager($dm); $this->repository = $this->getMock('Composer\\Repository\\InstalledRepositoryInterface'); $this->io = $this->getMock('Composer\\IO\\IOInterface'); $this->type = $this->getMock('Fxp\\Composer\\AssetPlugin\\Type\\AssetTypeInterface'); $this->type->expects($this->any())->method('getName')->will($this->returnValue('foo')); $this->type->expects($this->any())->method('getComposerVendorName')->will($this->returnValue('foo-asset')); $this->type->expects($this->any())->method('getComposerType')->will($this->returnValue('foo-asset-library')); $this->type->expects($this->any())->method('getFilename')->will($this->returnValue('foo.json')); $this->type->expects($this->any())->method('getVersionConverter')->will($this->returnValue($this->getMock('Fxp\\Composer\\AssetPlugin\\Converter\\VersionConverterInterface'))); $this->type->expects($this->any())->method('getPackageConverter')->will($this->returnValue($this->getMock('Fxp\\Composer\\AssetPlugin\\Converter\\PackageConverterInterface'))); }
/** * Constructor. * * @param IOInterface $io * @param Composer $composer * @param AssetTypeInterface $assetType * @param Filesystem $filesystem */ public function __construct(IOInterface $io, Composer $composer, AssetTypeInterface $assetType, Filesystem $filesystem = null) { parent::__construct($io, $composer, $assetType->getComposerType(), $filesystem); $extra = $composer->getPackage()->getExtra(); if (!empty($extra['asset-installer-paths'][$this->type])) { $this->vendorDir = rtrim($extra['asset-installer-paths'][$this->type], '/'); } else { $this->vendorDir = rtrim($this->vendorDir . '/' . $assetType->getComposerVendorName(), '/'); } }
protected function setUp() { $this->package = $this->getMockBuilder('Composer\\Package\\RootPackageInterface')->getMock(); $this->assetType = $this->getMockBuilder('Fxp\\Composer\\AssetPlugin\\Type\\AssetTypeInterface')->getMock(); $versionConverter = $this->getMockBuilder('Fxp\\Composer\\AssetPlugin\\Converter\\VersionConverterInterface')->getMock(); $versionConverter->expects($this->any())->method('convertVersion')->will($this->returnCallback(function ($value) { return $value; })); $this->assetType->expects($this->any())->method('getVersionConverter')->will($this->returnValue($versionConverter)); $this->installationManager = $this->getMockBuilder('Composer\\Installer\\InstallationManager')->disableOriginalConstructor()->getMock(); $this->installationManager->expects($this->any())->method('isPackageInstalled')->will($this->returnValue(true)); }
protected function setUp() { $this->package = $this->getMock('Composer\Package\RootPackageInterface'); $this->assetType = $this->getMock('Fxp\Composer\AssetPlugin\Type\AssetTypeInterface'); $versionConverter = $this->getMock('Fxp\Composer\AssetPlugin\Converter\VersionConverterInterface'); $versionConverter->expects($this->any()) ->method('convertVersion') ->will($this->returnCallback(function ($value) { return $value; })); $this->assetType->expects($this->any()) ->method('getVersionConverter') ->will($this->returnValue($versionConverter)); }
/** * @param string $type * @param bool $verbose * @param string $exceptionClass * @param string $validTrace * * @dataProvider getConfigIoForException */ public function testTagWithTransportException($type, $verbose, $exceptionClass, $validTrace) { /* @var \PHPUnit_Framework_MockObject_MockObject $loader */ $loader = $this->loader; $loader ->expects($this->any()) ->method('load') ->will($this->throwException(new $exceptionClass('MESSAGE'))); $this->lazyLoader = $this->createLazyLoaderConfigured($type, $verbose); $package = $this->lazyLoader->load($this->lazyPackage); $this->assertFalse($package); $filename = $this->assetType->getFilename(); $validOutput = array(''); if ($verbose) { $validOutput = array( 'Reading ' . $filename . ' of <info>' . $this->lazyPackage->getName() . '</info> (<comment>' . $this->lazyPackage->getPrettyVersion() . '</comment>)', 'Importing empty ' . $type . ' ' . $this->lazyPackage->getPrettyVersion() . ' (' . $this->lazyPackage->getVersion() . ')', $validTrace, '', ); } $this->assertSame($validOutput, $this->io->getTraces()); $packageCache = $this->lazyLoader->load($this->lazyPackage); $this->assertFalse($packageCache); $this->assertSame($validOutput, $this->io->getTraces()); }
/** * Validates the tag. * * @param string $tag * @param AssetTypeInterface $assetType * @param VersionParser|null $parser * * @return false|string */ public static function validateTag($tag, AssetTypeInterface $assetType, VersionParser $parser = null) { if (in_array($tag, array('master', 'trunk', 'default'))) { return false; } if (null === $parser) { $parser = new VersionParser(); } try { $tag = $assetType->getVersionConverter()->convertVersion($tag); $tag = $parser->normalize($tag); } catch (\Exception $e) { $tag = false; } return $tag; }
/** * Creates the search result item. * * @param array $item. * * @return array An array('name' => '...', 'description' => '...') */ protected function createSearchItem(array $item) { return array( 'name' => $this->assetType->getComposerVendorName() . '/' . $item['name'], 'description' => null, ); }
/** * Pre process the data of package before the conversion to Package instance. * * @param array $data * * @return array */ protected function preProcessAsset(array $data) { $vcsRepos = array(); // keep the name of the main identifier for all packages $data['name'] = $this->packageName ?: $data['name']; $data = $this->assetType->getPackageConverter()->convert($data, $vcsRepos); return (array) $data; }
/** * Check if the version must be skipped. * * @param AssetTypeInterface $assetType The asset type * @param string $name The composer package name * @param string $version The version * * @return bool */ public function skip(AssetTypeInterface $assetType, $name, $version) { if (!isset($this->requires[$name])) { return false; } /* @var Link $require */ $require = $this->requires[$name]; try { $cVersion = $assetType->getVersionConverter()->convertVersion($version); $normalizedVersion = $this->versionParser->normalize($cVersion); return !$this->satisfy($require, $normalizedVersion); } catch (\Exception $ex) { return true; } }
/** * Pre process the data of package before the conversion to Package instance. * * @param VcsDriverInterface $driver * @param array $data * @param string $identifier * * @return array */ protected function preProcess(VcsDriverInterface $driver, array $data, $identifier) { $vcsRepos = array(); $data = array_merge($data, $this->packageData); $data = $this->assetType->getPackageConverter()->convert($data, $vcsRepos); $this->dispatchAddVcsEvent($vcsRepos); if (!isset($data['dist'])) { $data['dist'] = $driver->getDist($identifier); } if (!isset($data['source'])) { $data['source'] = $driver->getSource($identifier); } return (array) $data; }
/** * Converts simple key of package. * * @param array $asset The asset data * @param string $assetKey The asset key of dependencies * @param array $composer The composer data * @param string $composerKey The composer key of dependencies * @param array $vcsRepos The list of new vcs configs */ protected function convertDependencies(array $asset, $assetKey, array &$composer, $composerKey, array &$vcsRepos = array()) { if (isset($asset[$assetKey]) && is_array($asset[$assetKey])) { $newDependencies = array(); foreach ($asset[$assetKey] as $dependency => $version) { list($dependency, $version) = $this->convertDependency($dependency, $version, $vcsRepos, $composer); $version = $this->assetType->getVersionConverter()->convertRange($version); if (0 !== strpos($version, $dependency)) { $newDependencies[$this->assetType->getComposerVendorName() . '/' . $dependency] = $version; } } $composer[$composerKey] = $newDependencies; } }
public function testCustomFooDir() { $vendorDir = realpath(sys_get_temp_dir()) . '/composer-test/web'; $vendorDir = str_replace('\\', '/', $vendorDir); /* @var \PHPUnit_Framework_MockObject_MockObject $package */ $package = $this->package; $package->expects($this->any())->method('getExtra')->will($this->returnValue(array('asset-installer-paths' => array($this->type->getComposerType() => $vendorDir)))); $installer = $this->createInstaller(); $installerPath = $installer->getInstallPath($this->createPackageMock('foo-asset/foo')); $installerPath = str_replace('\\', '/', $installerPath); $this->assertEquals($vendorDir . '/foo', $installerPath); $installerPath2 = $installer->getInstallPath($this->createPackageMock('foo-asset/foo/bar')); $installerPath2 = str_replace('\\', '/', $installerPath2); $this->assertEquals($vendorDir . '/foo/bar', $installerPath2); }
/** * Check if the version must be skipped. * * @param AssetTypeInterface $assetType The asset type * @param string $name The composer package name * @param string $version The version * * @return bool */ public function skip(AssetTypeInterface $assetType, $name, $version) { try { $cVersion = $assetType->getVersionConverter()->convertVersion($version); $normalizedVersion = $this->versionParser->normalize($cVersion); } catch (\Exception $ex) { return true; } if (false !== $this->skipByPattern() && $this->forceSkipVersion($normalizedVersion)) { return true; } return $this->doSkip($name, $normalizedVersion); }
public function testConverter() { $this->assertInstanceOf('Fxp\\Composer\\AssetPlugin\\Converter\\PackageConverterInterface', $this->type->getPackageConverter()); $this->assertInstanceOf('Fxp\\Composer\\AssetPlugin\\Converter\\VersionConverterInterface', $this->type->getVersionConverter()); }
/** * Get the version of url file dependency. * * @param AssetTypeInterface $assetType The asset type * @param string $url The url * @param string $version The version * * @return string The version */ protected static function getUrlFileDependencyVersion(AssetTypeInterface $assetType, $url, $version) { if ('#' !== $version) { return substr($version, 1); } if (preg_match('/(\\d+)(\\.\\d+)(\\.\\d+)?(\\.\\d+)?/', $url, $match)) { return $assetType->getVersionConverter()->convertVersion($match[0]); } return '0.0.0.0'; }