From d6de4a00368b9cd302c39bb7db49beaaad8b001d Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 23 Aug 2012 15:52:40 +0200 Subject: [PATCH] Rename Package interfaces to reduce BC issues --- src/Composer/Command/SearchCommand.php | 6 +- src/Composer/Command/ShowCommand.php | 10 +- src/Composer/Composer.php | 10 +- src/Composer/Installer.php | 7 +- src/Composer/Package/AliasPackage.php | 2 +- src/Composer/Package/CompletePackage.php | 174 ++++++++++ .../Package/CompletePackageInterface.php | 81 +++++ src/Composer/Package/CorePackageInterface.php | 297 ------------------ src/Composer/Package/Dumper/ArrayDumper.php | 39 ++- src/Composer/Package/Loader/ArrayLoader.php | 82 ++--- .../Package/Loader/LoaderInterface.php | 3 +- .../Package/Loader/RootPackageLoader.php | 4 +- .../Package/Loader/ValidatingArrayLoader.php | 4 +- .../{MemoryPackage.php => Package.php} | 225 +------------ src/Composer/Package/PackageInterface.php | 268 ++++++++++++++-- src/Composer/Package/RootPackage.php | 81 +++++ src/Composer/Package/RootPackageInterface.php | 2 +- .../Repository/ComposerRepository.php | 4 +- .../Repository/Pear/ChannelReader.php | 2 +- src/Composer/Repository/PearRepository.php | 8 +- .../Repository/PlatformRepository.php | 8 +- .../Test/Autoload/AutoloadGeneratorTest.php | 58 ++-- tests/Composer/Test/ComposerTest.php | 2 +- .../Test/Installer/LibraryInstallerTest.php | 2 +- .../Installer/MetapackageInstallerTest.php | 2 +- tests/Composer/Test/InstallerTest.php | 8 +- ...ackageTest.php => CompletePackageTest.php} | 16 +- .../Test/Package/Dumper/ArrayDumperTest.php | 4 +- .../Repository/Pear/ChannelReaderTest.php | 4 +- tests/Composer/Test/TestCase.php | 6 +- 30 files changed, 743 insertions(+), 676 deletions(-) create mode 100644 src/Composer/Package/CompletePackage.php create mode 100644 src/Composer/Package/CompletePackageInterface.php delete mode 100644 src/Composer/Package/CorePackageInterface.php rename src/Composer/Package/{MemoryPackage.php => Package.php} (70%) create mode 100644 src/Composer/Package/RootPackage.php rename tests/Composer/Test/Package/{MemoryPackageTest.php => CompletePackageTest.php} (78%) diff --git a/src/Composer/Command/SearchCommand.php b/src/Composer/Command/SearchCommand.php index c09b5d4f1..f212f0621 100644 --- a/src/Composer/Command/SearchCommand.php +++ b/src/Composer/Command/SearchCommand.php @@ -17,7 +17,7 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Output\OutputInterface; use Composer\Repository\CompositeRepository; use Composer\Repository\PlatformRepository; -use Composer\Package\PackageInterface; +use Composer\Package\CompletePackageInterface; use Composer\Package\AliasPackage; use Composer\Factory; @@ -117,11 +117,11 @@ EOT /** * tries to find a token within the name/keywords/description * - * @param PackageInterface $package + * @param CompletePackageInterface $package * @param string $token * @return boolean */ - private function matchPackage(PackageInterface $package, $token) + private function matchPackage(CompletePackageInterface $package, $token) { $score = 0; diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php index 7d8632588..a850da552 100644 --- a/src/Composer/Command/ShowCommand.php +++ b/src/Composer/Command/ShowCommand.php @@ -14,7 +14,7 @@ namespace Composer\Command; use Composer\Composer; use Composer\Factory; -use Composer\Package\PackageInterface; +use Composer\Package\CompletePackageInterface; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; @@ -133,7 +133,7 @@ EOT * finds a package by name and version if provided * * @param InputInterface $input - * @return PackageInterface + * @return CompletePackageInterface * @throws \InvalidArgumentException */ protected function getPackage(InputInterface $input, OutputInterface $output, RepositoryInterface $installedRepo, RepositoryInterface $repos) @@ -164,7 +164,7 @@ EOT /** * prints package meta data */ - protected function printMeta(InputInterface $input, OutputInterface $output, PackageInterface $package, RepositoryInterface $installedRepo, RepositoryInterface $repos) + protected function printMeta(InputInterface $input, OutputInterface $output, CompletePackageInterface $package, RepositoryInterface $installedRepo, RepositoryInterface $repos) { $output->writeln('name : ' . $package->getPrettyName()); $output->writeln('descrip. : ' . $package->getDescription()); @@ -206,7 +206,7 @@ EOT /** * prints all available versions of this package and highlights the installed one if any */ - protected function printVersions(InputInterface $input, OutputInterface $output, PackageInterface $package, RepositoryInterface $installedRepo, RepositoryInterface $repos) + protected function printVersions(InputInterface $input, OutputInterface $output, CompletePackageInterface $package, RepositoryInterface $installedRepo, RepositoryInterface $repos) { if ($input->getArgument('version')) { $output->writeln('version : ' . $package->getPrettyVersion()); @@ -237,7 +237,7 @@ EOT * * @param string $linkType */ - protected function printLinks(InputInterface $input, OutputInterface $output, PackageInterface $package, $linkType, $title = null) + protected function printLinks(InputInterface $input, OutputInterface $output, CompletePackageInterface $package, $linkType, $title = null) { $title = $title ?: $linkType; if ($links = $package->{'get'.ucfirst($linkType)}()) { diff --git a/src/Composer/Composer.php b/src/Composer/Composer.php index 5b85e172a..2222f85f9 100644 --- a/src/Composer/Composer.php +++ b/src/Composer/Composer.php @@ -12,7 +12,7 @@ namespace Composer; -use Composer\Package\PackageInterface; +use Composer\Package\RootPackageInterface; use Composer\Package\Locker; use Composer\Repository\RepositoryManager; use Composer\Installer\InstallationManager; @@ -27,7 +27,7 @@ class Composer const VERSION = '@package_version@'; /** - * @var Package\PackageInterface + * @var Package\RootPackageInterface */ private $package; @@ -57,16 +57,16 @@ class Composer private $config; /** - * @param Package\PackageInterface $package + * @param Package\RootPackageInterface $package * @return void */ - public function setPackage(PackageInterface $package) + public function setPackage(RootPackageInterface $package) { $this->package = $package; } /** - * @return Package\PackageInterface + * @return Package\RootPackageInterface */ public function getPackage() { diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index e2c6f8113..282fafb78 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -29,6 +29,7 @@ use Composer\Package\Link; use Composer\Package\LinkConstraint\VersionConstraint; use Composer\Package\Locker; use Composer\Package\PackageInterface; +use Composer\Package\RootPackageInterface; use Composer\Repository\CompositeRepository; use Composer\Repository\InstalledArrayRepository; use Composer\Repository\PlatformRepository; @@ -55,7 +56,7 @@ class Installer protected $config; /** - * @var PackageInterface + * @var RootPackageInterface */ protected $package; @@ -112,7 +113,7 @@ class Installer * * @param IOInterface $io * @param Config $config - * @param PackageInterface $package + * @param RootPackageInterface $package * @param DownloadManager $downloadManager * @param RepositoryManager $repositoryManager * @param Locker $locker @@ -120,7 +121,7 @@ class Installer * @param EventDispatcher $eventDispatcher * @param AutoloadGenerator $autoloadGenerator */ - public function __construct(IOInterface $io, Config $config, PackageInterface $package, DownloadManager $downloadManager, RepositoryManager $repositoryManager, Locker $locker, InstallationManager $installationManager, EventDispatcher $eventDispatcher, AutoloadGenerator $autoloadGenerator) + public function __construct(IOInterface $io, Config $config, RootPackageInterface $package, DownloadManager $downloadManager, RepositoryManager $repositoryManager, Locker $locker, InstallationManager $installationManager, EventDispatcher $eventDispatcher, AutoloadGenerator $autoloadGenerator) { $this->io = $io; $this->config = $config; diff --git a/src/Composer/Package/AliasPackage.php b/src/Composer/Package/AliasPackage.php index 14c0d65b0..1fe7ff2f8 100644 --- a/src/Composer/Package/AliasPackage.php +++ b/src/Composer/Package/AliasPackage.php @@ -18,7 +18,7 @@ use Composer\Package\Version\VersionParser; /** * @author Jordi Boggiano */ -class AliasPackage extends BasePackage +class AliasPackage extends BasePackage implements CompletePackageInterface { protected $version; protected $prettyVersion; diff --git a/src/Composer/Package/CompletePackage.php b/src/Composer/Package/CompletePackage.php new file mode 100644 index 000000000..a2177214a --- /dev/null +++ b/src/Composer/Package/CompletePackage.php @@ -0,0 +1,174 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Package; + +use Composer\Package\Version\VersionParser; + +/** + * Package containing additional metadata that is not used by the solver + * + * @author Nils Adermann + */ +class CompletePackage extends Package implements CompletePackageInterface +{ + protected $repositories; + protected $license = array(); + protected $keywords; + protected $authors; + protected $description; + protected $homepage; + protected $scripts = array(); + protected $support = array(); + + /** + * @param array $scripts + */ + public function setScripts(array $scripts) + { + $this->scripts = $scripts; + } + + /** + * {@inheritDoc} + */ + public function getScripts() + { + return $this->scripts; + } + + /** + * Set the repositories + * + * @param string $repositories + */ + public function setRepositories($repositories) + { + $this->repositories = $repositories; + } + + /** + * {@inheritDoc} + */ + public function getRepositories() + { + return $this->repositories; + } + + /** + * Set the license + * + * @param array $license + */ + public function setLicense(array $license) + { + $this->license = $license; + } + + /** + * {@inheritDoc} + */ + public function getLicense() + { + return $this->license; + } + + /** + * Set the keywords + * + * @param array $keywords + */ + public function setKeywords(array $keywords) + { + $this->keywords = $keywords; + } + + /** + * {@inheritDoc} + */ + public function getKeywords() + { + return $this->keywords; + } + + /** + * Set the authors + * + * @param array $authors + */ + public function setAuthors(array $authors) + { + $this->authors = $authors; + } + + /** + * {@inheritDoc} + */ + public function getAuthors() + { + return $this->authors; + } + + /** + * Set the description + * + * @param string $description + */ + public function setDescription($description) + { + $this->description = $description; + } + + /** + * {@inheritDoc} + */ + public function getDescription() + { + return $this->description; + } + + /** + * Set the homepage + * + * @param string $homepage + */ + public function setHomepage($homepage) + { + $this->homepage = $homepage; + } + + /** + * {@inheritDoc} + */ + public function getHomepage() + { + return $this->homepage; + } + + /** + * Set the support information + * + * @param array $support + */ + public function setSupport(array $support) + { + $this->support = $support; + } + + /** + * {@inheritDoc} + */ + public function getSupport() + { + return $this->support; + } +} diff --git a/src/Composer/Package/CompletePackageInterface.php b/src/Composer/Package/CompletePackageInterface.php new file mode 100644 index 000000000..a341766d3 --- /dev/null +++ b/src/Composer/Package/CompletePackageInterface.php @@ -0,0 +1,81 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Package; + +/** + * Defines package metadata that is not necessarily needed for solving and installing packages + * + * @author Nils Adermann + */ +interface CompletePackageInterface extends PackageInterface +{ + /** + * Returns the scripts of this package + * + * @return array array('script name' => array('listeners')) + */ + public function getScripts(); + + /** + * Returns an array of repositories + * + * {"": {}} + * + * @return array Repositories + */ + public function getRepositories(); + + /** + * Returns the package license, e.g. MIT, BSD, GPL + * + * @return array The package licenses + */ + public function getLicense(); + + /** + * Returns an array of keywords relating to the package + * + * @return array + */ + public function getKeywords(); + + /** + * Returns the package description + * + * @return string + */ + public function getDescription(); + + /** + * Returns the package homepage + * + * @return string + */ + public function getHomepage(); + + /** + * Returns an array of authors of the package + * + * Each item can contain name/homepage/email keys + * + * @return array + */ + public function getAuthors(); + + /** + * Returns the support information + * + * @return array + */ + public function getSupport(); +} diff --git a/src/Composer/Package/CorePackageInterface.php b/src/Composer/Package/CorePackageInterface.php deleted file mode 100644 index b0d98d40f..000000000 --- a/src/Composer/Package/CorePackageInterface.php +++ /dev/null @@ -1,297 +0,0 @@ - - * Jordi Boggiano - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Composer\Package; - -use Composer\Repository\RepositoryInterface; - -/** - * Defines the essential information a package has that is used during solving/installation - * - * @author Jordi Boggiano - */ -interface CorePackageInterface -{ - /** - * Returns the package's name without version info, thus not a unique identifier - * - * @return string package name - */ - public function getName(); - - /** - * Returns the package's pretty (i.e. with proper case) name - * - * @return string package name - */ - public function getPrettyName(); - - /** - * Returns a set of names that could refer to this package - * - * No version or release type information should be included in any of the - * names. Provided or replaced package names need to be returned as well. - * - * @return array An array of strings referring to this package - */ - public function getNames(); - - /** - * Allows the solver to set an id for this package to refer to it. - * - * @param int $id - */ - public function setId($id); - - /** - * Retrieves the package's id set through setId - * - * @return int The previously set package id - */ - public function getId(); - - /** - * Returns whether the package is a development virtual package or a concrete one - * - * @return bool - */ - public function isDev(); - - /** - * Returns the package type, e.g. library - * - * @return string The package type - */ - public function getType(); - - /** - * Returns the package targetDir property - * - * @return string The package targetDir - */ - public function getTargetDir(); - - /** - * Returns the package extra data - * - * @return array The package extra data - */ - public function getExtra(); - - /** - * Sets source from which this package was installed (source/dist). - * - * @param string $type source/dist - */ - public function setInstallationSource($type); - - /** - * Returns source from which this package was installed (source/dist). - * - * @param string $type source/dist - */ - public function getInstallationSource(); - - /** - * Returns the repository type of this package, e.g. git, svn - * - * @return string The repository type - */ - public function getSourceType(); - - /** - * Returns the repository url of this package, e.g. git://github.com/naderman/composer.git - * - * @return string The repository url - */ - public function getSourceUrl(); - - /** - * Returns the repository reference of this package, e.g. master, 1.0.0 or a commit hash for git - * - * @return string The repository reference - */ - public function getSourceReference(); - - /** - * Returns the type of the distribution archive of this version, e.g. zip, tarball - * - * @return string The repository type - */ - public function getDistType(); - - /** - * Returns the url of the distribution archive of this version - * - * @return string - */ - public function getDistUrl(); - - /** - * Returns the reference of the distribution archive of this version, e.g. master, 1.0.0 or a commit hash for git - * - * @return string - */ - public function getDistReference(); - - /** - * Returns the sha1 checksum for the distribution archive of this version - * - * @return string - */ - public function getDistSha1Checksum(); - - /** - * Returns the version of this package - * - * @return string version - */ - public function getVersion(); - - /** - * Returns the pretty (i.e. non-normalized) version string of this package - * - * @return string version - */ - public function getPrettyVersion(); - - /** - * Returns the stability of this package: one of (dev, alpha, beta, RC, stable) - * - * @return string - */ - public function getStability(); - - /** - * Returns a set of links to packages which need to be installed before - * this package can be installed - * - * @return array An array of package links defining required packages - */ - public function getRequires(); - - /** - * Returns a set of links to packages which must not be installed at the - * same time as this package - * - * @return array An array of package links defining conflicting packages - */ - public function getConflicts(); - - /** - * Returns a set of links to virtual packages that are provided through - * this package - * - * @return array An array of package links defining provided packages - */ - public function getProvides(); - - /** - * Returns a set of links to packages which can alternatively be - * satisfied by installing this package - * - * @return array An array of package links defining replaced packages - */ - public function getReplaces(); - - /** - * Returns a set of links to packages which are required to develop - * this package. These are installed if in dev mode. - * - * @return array An array of package links defining packages required for development - */ - public function getDevRequires(); - - /** - * Returns a set of package names and reasons why they are useful in - * combination with this package. - * - * @return array An array of package suggestions with descriptions - */ - public function getSuggests(); - - /** - * Returns an associative array of autoloading rules - * - * {"": {""}} - * - * Type is either "psr-0" or "pear". Namespaces are mapped to directories - * for autoloading using the type specified. - * - * @return array Mapping of autoloading rules - */ - public function getAutoload(); - - /** - * Returns a list of directories which should get added to PHP's - * include path. - * - * @return array - */ - public function getIncludePaths(); - - /** - * Stores a reference to the repository that owns the package - * - * @param RepositoryInterface $repository - */ - public function setRepository(RepositoryInterface $repository); - - /** - * Returns a reference to the repository that owns the package - * - * @return RepositoryInterface - */ - public function getRepository(); - - /** - * Returns the package binaries - * - * @return array - */ - public function getBinaries(); - - /** - * Returns a version this package should be aliased to - * - * @return string - */ - public function getAlias(); - - /** - * Returns a non-normalized version this package should be aliased to - * - * @return string - */ - public function getPrettyAlias(); - - /** - * Returns package unique name, constructed from name and version. - * - * @return string - */ - public function getUniqueName(); - - /** - * Converts the package into a readable and unique string - * - * @return string - */ - public function __toString(); - - /** - * Converts the package into a pretty readable string - * - * @return string - */ - public function getPrettyString(); -} diff --git a/src/Composer/Package/Dumper/ArrayDumper.php b/src/Composer/Package/Dumper/ArrayDumper.php index 70691ee44..76e1dede4 100644 --- a/src/Composer/Package/Dumper/ArrayDumper.php +++ b/src/Composer/Package/Dumper/ArrayDumper.php @@ -14,6 +14,7 @@ namespace Composer\Package\Dumper; use Composer\Package\BasePackage; use Composer\Package\PackageInterface; +use Composer\Package\CompletePackageInterface; /** * @author Konstantin Kudryashiv @@ -25,19 +26,11 @@ class ArrayDumper { $keys = array( 'binaries' => 'bin', - 'scripts', 'type', 'extra', 'installationSource' => 'installation-source', - 'license', - 'authors', - 'description', - 'homepage', - 'keywords', 'autoload', - 'repositories', 'includePaths' => 'include-path', - 'support', ); $data = array(); @@ -49,10 +42,6 @@ class ArrayDumper $data['target-dir'] = $package->getTargetDir(); } - if ($package->getReleaseDate()) { - $data['time'] = $package->getReleaseDate()->format('Y-m-d H:i:s'); - } - if ($package->getSourceType()) { $data['source']['type'] = $package->getSourceType(); $data['source']['url'] = $package->getSourceUrl(); @@ -78,6 +67,32 @@ class ArrayDumper $data['suggest'] = $packages; } + if ($package->getReleaseDate()) { + $data['time'] = $package->getReleaseDate()->format('Y-m-d H:i:s'); + } + + $data = $this->dumpValues($package, $keys, $data); + + if ($package instanceof CompletePackageInterface) { + $keys = array( + 'scripts', + 'license', + 'authors', + 'description', + 'homepage', + 'keywords', + 'repositories', + 'support', + ); + + $data = $this->dumpValues($package, $keys, $data); + } + + return $data; + } + + private function dumpValues(PackageInterface $package, array $keys, array $data) + { foreach ($keys as $method => $key) { if (is_numeric($method)) { $method = $key; diff --git a/src/Composer/Package/Loader/ArrayLoader.php b/src/Composer/Package/Loader/ArrayLoader.php index 07ef88a59..0a8c9fb53 100644 --- a/src/Composer/Package/Loader/ArrayLoader.php +++ b/src/Composer/Package/Loader/ArrayLoader.php @@ -31,7 +31,7 @@ class ArrayLoader implements LoaderInterface $this->versionParser = $parser; } - public function load(array $config) + public function load(array $config, $class = 'Composer\Package\CompletePackage') { if (!isset($config['name'])) { throw new \UnexpectedValueException('Unknown package has no name defined ('.json_encode($config).').'); @@ -46,7 +46,7 @@ class ArrayLoader implements LoaderInterface } else { $version = $this->versionParser->normalize($config['version']); } - $package = new Package\MemoryPackage($config['name'], $version, $config['version']); + $package = new $class($config['name'], $version, $config['version']); $package->setType(isset($config['type']) ? strtolower($config['type']) : 'library'); if (isset($config['target-dir'])) { @@ -67,42 +67,6 @@ class ArrayLoader implements LoaderInterface $package->setBinaries($config['bin']); } - if (isset($config['scripts']) && is_array($config['scripts'])) { - foreach ($config['scripts'] as $event => $listeners) { - $config['scripts'][$event]= (array) $listeners; - } - $package->setScripts($config['scripts']); - } - - if (!empty($config['description']) && is_string($config['description'])) { - $package->setDescription($config['description']); - } - - if (!empty($config['homepage']) && is_string($config['homepage'])) { - $package->setHomepage($config['homepage']); - } - - if (!empty($config['keywords']) && is_array($config['keywords'])) { - $package->setKeywords($config['keywords']); - } - - if (!empty($config['license'])) { - $package->setLicense(is_array($config['license']) ? $config['license'] : array($config['license'])); - } - - if (!empty($config['time'])) { - try { - $date = new \DateTime($config['time']); - $date->setTimezone(new \DateTimeZone('UTC')); - $package->setReleaseDate($date); - } catch (\Exception $e) { - } - } - - if (!empty($config['authors']) && is_array($config['authors'])) { - $package->setAuthors($config['authors']); - } - if (isset($config['installation-source'])) { $package->setInstallationSource($config['installation-source']); } @@ -165,8 +129,46 @@ class ArrayLoader implements LoaderInterface $package->setIncludePaths($config['include-path']); } - if (isset($config['support'])) { - $package->setSupport($config['support']); + if (!empty($config['time'])) { + try { + $date = new \DateTime($config['time']); + $date->setTimezone(new \DateTimeZone('UTC')); + $package->setReleaseDate($date); + } catch (\Exception $e) { + } + } + + if ($package instanceof Package\CompletePackageInterface) { + if (isset($config['scripts']) && is_array($config['scripts'])) { + foreach ($config['scripts'] as $event => $listeners) { + $config['scripts'][$event]= (array) $listeners; + } + $package->setScripts($config['scripts']); + } + + if (!empty($config['description']) && is_string($config['description'])) { + $package->setDescription($config['description']); + } + + if (!empty($config['homepage']) && is_string($config['homepage'])) { + $package->setHomepage($config['homepage']); + } + + if (!empty($config['keywords']) && is_array($config['keywords'])) { + $package->setKeywords($config['keywords']); + } + + if (!empty($config['license'])) { + $package->setLicense(is_array($config['license']) ? $config['license'] : array($config['license'])); + } + + if (!empty($config['authors']) && is_array($config['authors'])) { + $package->setAuthors($config['authors']); + } + + if (isset($config['support'])) { + $package->setSupport($config['support']); + } } return $package; diff --git a/src/Composer/Package/Loader/LoaderInterface.php b/src/Composer/Package/Loader/LoaderInterface.php index 7fd03c49e..295ddf95b 100644 --- a/src/Composer/Package/Loader/LoaderInterface.php +++ b/src/Composer/Package/Loader/LoaderInterface.php @@ -23,7 +23,8 @@ interface LoaderInterface * Converts a package from an array to a real instance * * @param array $package Package config + * @param string $class Package class to use * @return \Composer\Package\PackageInterface */ - public function load(array $package); + public function load(array $package, $class = 'Composer\Package\CompletePackage'); } diff --git a/src/Composer/Package/Loader/RootPackageLoader.php b/src/Composer/Package/Loader/RootPackageLoader.php index d4c62bca7..2733744ee 100644 --- a/src/Composer/Package/Loader/RootPackageLoader.php +++ b/src/Composer/Package/Loader/RootPackageLoader.php @@ -40,7 +40,7 @@ class RootPackageLoader extends ArrayLoader parent::__construct($parser); } - public function load(array $config) + public function load(array $config, $class = 'Composer\Package\RootPackage') { if (!isset($config['name'])) { $config['name'] = '__root__'; @@ -62,7 +62,7 @@ class RootPackageLoader extends ArrayLoader $version = $config['version']; } - $package = parent::load($config); + $package = parent::load($config, $class); $aliases = array(); $stabilityFlags = array(); diff --git a/src/Composer/Package/Loader/ValidatingArrayLoader.php b/src/Composer/Package/Loader/ValidatingArrayLoader.php index 7b68fd4d0..653ed4b42 100644 --- a/src/Composer/Package/Loader/ValidatingArrayLoader.php +++ b/src/Composer/Package/Loader/ValidatingArrayLoader.php @@ -36,7 +36,7 @@ class ValidatingArrayLoader implements LoaderInterface $this->versionParser = $parser; } - public function load(array $config) + public function load(array $config, $class = 'Composer\Package\CompletePackage') { $this->config = $config; @@ -168,7 +168,7 @@ class ValidatingArrayLoader implements LoaderInterface throw new \Exception(implode("\n", $this->errors)); } - $package = $this->loader->load($this->config); + $package = $this->loader->load($this->config, $class); $this->errors = array(); $this->config = null; diff --git a/src/Composer/Package/MemoryPackage.php b/src/Composer/Package/Package.php similarity index 70% rename from src/Composer/Package/MemoryPackage.php rename to src/Composer/Package/Package.php index dcb4f2bcf..d2de23673 100644 --- a/src/Composer/Package/MemoryPackage.php +++ b/src/Composer/Package/Package.php @@ -15,11 +15,11 @@ namespace Composer\Package; use Composer\Package\Version\VersionParser; /** - * A package with setters for all members to create it dynamically in memory + * Core package definitions that are needed to resolve dependencies and install packages * * @author Nils Adermann */ -class MemoryPackage extends BasePackage +class Package extends BasePackage { protected $type; protected $targetDir; @@ -33,24 +33,14 @@ class MemoryPackage extends BasePackage protected $distSha1Checksum; protected $version; protected $prettyVersion; - protected $repositories; - protected $license = array(); protected $releaseDate; - protected $keywords; - protected $authors; - protected $description; - protected $homepage; protected $extra = array(); protected $binaries = array(); - protected $scripts = array(); protected $aliases = array(); protected $alias; protected $prettyAlias; protected $dev; - - protected $minimumStability = 'stable'; - protected $stabilityFlags = array(); - protected $references = array(); + protected $stability; protected $requires = array(); protected $conflicts = array(); @@ -60,7 +50,6 @@ class MemoryPackage extends BasePackage protected $suggests = array(); protected $autoload = array(); protected $includePaths = array(); - protected $support = array(); /** * Creates a new in memory package. @@ -160,22 +149,6 @@ class MemoryPackage extends BasePackage return $this->binaries; } - /** - * @param array $scripts - */ - public function setScripts(array $scripts) - { - $this->scripts = $scripts; - } - - /** - * {@inheritDoc} - */ - public function getScripts() - { - return $this->scripts; - } - /** * @param array $aliases */ @@ -352,24 +325,6 @@ class MemoryPackage extends BasePackage return $this->distSha1Checksum; } - /** - * Set the repositories - * - * @param string $repositories - */ - public function setRepositories($repositories) - { - $this->repositories = $repositories; - } - - /** - * {@inheritDoc} - */ - public function getRepositories() - { - return $this->repositories; - } - /** * {@inheritDoc} */ @@ -387,21 +342,21 @@ class MemoryPackage extends BasePackage } /** - * Set the license + * Set the releaseDate * - * @param array $license + * @param DateTime $releaseDate */ - public function setLicense(array $license) + public function setReleaseDate(\DateTime $releaseDate) { - $this->license = $license; + $this->releaseDate = $releaseDate; } /** * {@inheritDoc} */ - public function getLicense() + public function getReleaseDate() { - return $this->license; + return $this->releaseDate; } /** @@ -512,150 +467,6 @@ class MemoryPackage extends BasePackage return $this->suggests; } - /** - * Set the releaseDate - * - * @param DateTime $releaseDate - */ - public function setReleaseDate(\DateTime $releaseDate) - { - $this->releaseDate = $releaseDate; - } - - /** - * {@inheritDoc} - */ - public function getReleaseDate() - { - return $this->releaseDate; - } - - /** - * Set the keywords - * - * @param array $keywords - */ - public function setKeywords(array $keywords) - { - $this->keywords = $keywords; - } - - /** - * {@inheritDoc} - */ - public function getKeywords() - { - return $this->keywords; - } - - /** - * Set the authors - * - * @param array $authors - */ - public function setAuthors(array $authors) - { - $this->authors = $authors; - } - - /** - * {@inheritDoc} - */ - public function getAuthors() - { - return $this->authors; - } - - /** - * Set the description - * - * @param string $description - */ - public function setDescription($description) - { - $this->description = $description; - } - - /** - * {@inheritDoc} - */ - public function getDescription() - { - return $this->description; - } - - /** - * Set the homepage - * - * @param string $homepage - */ - public function setHomepage($homepage) - { - $this->homepage = $homepage; - } - - /** - * {@inheritDoc} - */ - public function getHomepage() - { - return $this->homepage; - } - - /** - * Set the minimumStability - * - * @param string $minimumStability - */ - public function setMinimumStability($minimumStability) - { - $this->minimumStability = $minimumStability; - } - - /** - * {@inheritDoc} - */ - public function getMinimumStability() - { - return $this->minimumStability; - } - - /** - * Set the stabilityFlags - * - * @param array $stabilityFlags - */ - public function setStabilityFlags(array $stabilityFlags) - { - $this->stabilityFlags = $stabilityFlags; - } - - /** - * {@inheritDoc} - */ - public function getStabilityFlags() - { - return $this->stabilityFlags; - } - - /** - * Set the references - * - * @param array $references - */ - public function setReferences(array $references) - { - $this->references = $references; - } - - /** - * {@inheritDoc} - */ - public function getReferences() - { - return $this->references; - } - /** * Set the autoload mapping * @@ -691,22 +502,4 @@ class MemoryPackage extends BasePackage { return $this->includePaths; } - - /** - * Set the support information - * - * @param array $support - */ - public function setSupport(array $support) - { - $this->support = $support; - } - - /** - * {@inheritDoc} - */ - public function getSupport() - { - return $this->support; - } } diff --git a/src/Composer/Package/PackageInterface.php b/src/Composer/Package/PackageInterface.php index 5d4958c61..c8b9a7f39 100644 --- a/src/Composer/Package/PackageInterface.php +++ b/src/Composer/Package/PackageInterface.php @@ -12,35 +12,157 @@ namespace Composer\Package; +use Composer\Repository\RepositoryInterface; + /** - * Defines package metadata that is not necessarily needed for solving and installing packages + * Defines the essential information a package has that is used during solving/installation * - * @author Nils Adermann + * @author Jordi Boggiano */ -interface PackageInterface extends CorePackageInterface +interface PackageInterface { /** - * Returns the scripts of this package + * Returns the package's name without version info, thus not a unique identifier + * + * @return string package name + */ + public function getName(); + + /** + * Returns the package's pretty (i.e. with proper case) name + * + * @return string package name + */ + public function getPrettyName(); + + /** + * Returns a set of names that could refer to this package + * + * No version or release type information should be included in any of the + * names. Provided or replaced package names need to be returned as well. + * + * @return array An array of strings referring to this package + */ + public function getNames(); + + /** + * Allows the solver to set an id for this package to refer to it. + * + * @param int $id + */ + public function setId($id); + + /** + * Retrieves the package's id set through setId + * + * @return int The previously set package id + */ + public function getId(); + + /** + * Returns whether the package is a development virtual package or a concrete one + * + * @return bool + */ + public function isDev(); + + /** + * Returns the package type, e.g. library + * + * @return string The package type + */ + public function getType(); + + /** + * Returns the package targetDir property + * + * @return string The package targetDir + */ + public function getTargetDir(); + + /** + * Returns the package extra data + * + * @return array The package extra data + */ + public function getExtra(); + + /** + * Sets source from which this package was installed (source/dist). + * + * @param string $type source/dist + */ + public function setInstallationSource($type); + + /** + * Returns source from which this package was installed (source/dist). + * + * @param string $type source/dist + */ + public function getInstallationSource(); + + /** + * Returns the repository type of this package, e.g. git, svn + * + * @return string The repository type + */ + public function getSourceType(); + + /** + * Returns the repository url of this package, e.g. git://github.com/naderman/composer.git + * + * @return string The repository url + */ + public function getSourceUrl(); + + /** + * Returns the repository reference of this package, e.g. master, 1.0.0 or a commit hash for git + * + * @return string The repository reference + */ + public function getSourceReference(); + + /** + * Returns the type of the distribution archive of this version, e.g. zip, tarball + * + * @return string The repository type + */ + public function getDistType(); + + /** + * Returns the url of the distribution archive of this version + * + * @return string + */ + public function getDistUrl(); + + /** + * Returns the reference of the distribution archive of this version, e.g. master, 1.0.0 or a commit hash for git * - * @return array array('script name' => array('listeners')) + * @return string */ - public function getScripts(); + public function getDistReference(); /** - * Returns an array of repositories + * Returns the sha1 checksum for the distribution archive of this version * - * {"": {}} + * @return string + */ + public function getDistSha1Checksum(); + + /** + * Returns the version of this package * - * @return array Repositories + * @return string version */ - public function getRepositories(); + public function getVersion(); /** - * Returns the package license, e.g. MIT, BSD, GPL + * Returns the pretty (i.e. non-normalized) version string of this package * - * @return array The package licenses + * @return string version */ - public function getLicense(); + public function getPrettyVersion(); /** * Returns the release date of the package @@ -50,39 +172,133 @@ interface PackageInterface extends CorePackageInterface public function getReleaseDate(); /** - * Returns an array of keywords relating to the package + * Returns the stability of this package: one of (dev, alpha, beta, RC, stable) + * + * @return string + */ + public function getStability(); + + /** + * Returns a set of links to packages which need to be installed before + * this package can be installed + * + * @return array An array of package links defining required packages + */ + public function getRequires(); + + /** + * Returns a set of links to packages which must not be installed at the + * same time as this package + * + * @return array An array of package links defining conflicting packages + */ + public function getConflicts(); + + /** + * Returns a set of links to virtual packages that are provided through + * this package + * + * @return array An array of package links defining provided packages + */ + public function getProvides(); + + /** + * Returns a set of links to packages which can alternatively be + * satisfied by installing this package + * + * @return array An array of package links defining replaced packages + */ + public function getReplaces(); + + /** + * Returns a set of links to packages which are required to develop + * this package. These are installed if in dev mode. + * + * @return array An array of package links defining packages required for development + */ + public function getDevRequires(); + + /** + * Returns a set of package names and reasons why they are useful in + * combination with this package. + * + * @return array An array of package suggestions with descriptions + */ + public function getSuggests(); + + /** + * Returns an associative array of autoloading rules + * + * {"": {""}} + * + * Type is either "psr-0" or "pear". Namespaces are mapped to directories + * for autoloading using the type specified. + * + * @return array Mapping of autoloading rules + */ + public function getAutoload(); + + /** + * Returns a list of directories which should get added to PHP's + * include path. + * + * @return array + */ + public function getIncludePaths(); + + /** + * Stores a reference to the repository that owns the package + * + * @param RepositoryInterface $repository + */ + public function setRepository(RepositoryInterface $repository); + + /** + * Returns a reference to the repository that owns the package + * + * @return RepositoryInterface + */ + public function getRepository(); + + /** + * Returns the package binaries * * @return array */ - public function getKeywords(); + public function getBinaries(); /** - * Returns the package description + * Returns a version this package should be aliased to * * @return string */ - public function getDescription(); + public function getAlias(); /** - * Returns the package homepage + * Returns a non-normalized version this package should be aliased to * * @return string */ - public function getHomepage(); + public function getPrettyAlias(); /** - * Returns an array of authors of the package + * Returns package unique name, constructed from name and version. * - * Each item can contain name/homepage/email keys + * @return string + */ + public function getUniqueName(); + + /** + * Converts the package into a readable and unique string * - * @return array + * @return string */ - public function getAuthors(); + public function __toString(); /** - * Returns the support information + * Converts the package into a pretty readable string * - * @return array + * @return string */ - public function getSupport(); + public function getPrettyString(); } diff --git a/src/Composer/Package/RootPackage.php b/src/Composer/Package/RootPackage.php new file mode 100644 index 000000000..10bd826c5 --- /dev/null +++ b/src/Composer/Package/RootPackage.php @@ -0,0 +1,81 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Package; + +use Composer\Package\Version\VersionParser; + +/** + * The root package represents the project's composer.json and contains additional metadata + * + * @author Jordi Boggiano + */ +class RootPackage extends CompletePackage implements RootPackageInterface +{ + protected $minimumStability = 'stable'; + protected $stabilityFlags = array(); + protected $references = array(); + + /** + * Set the minimumStability + * + * @param string $minimumStability + */ + public function setMinimumStability($minimumStability) + { + $this->minimumStability = $minimumStability; + } + + /** + * {@inheritDoc} + */ + public function getMinimumStability() + { + return $this->minimumStability; + } + + /** + * Set the stabilityFlags + * + * @param array $stabilityFlags + */ + public function setStabilityFlags(array $stabilityFlags) + { + $this->stabilityFlags = $stabilityFlags; + } + + /** + * {@inheritDoc} + */ + public function getStabilityFlags() + { + return $this->stabilityFlags; + } + + /** + * Set the references + * + * @param array $references + */ + public function setReferences(array $references) + { + $this->references = $references; + } + + /** + * {@inheritDoc} + */ + public function getReferences() + { + return $this->references; + } +} diff --git a/src/Composer/Package/RootPackageInterface.php b/src/Composer/Package/RootPackageInterface.php index 0b8a30f4e..501376f66 100644 --- a/src/Composer/Package/RootPackageInterface.php +++ b/src/Composer/Package/RootPackageInterface.php @@ -17,7 +17,7 @@ namespace Composer\Package; * * @author Jordi Boggiano */ -interface RootPackageInterface extends PackageInterface +interface RootPackageInterface extends CompletePackageInterface { /** * Returns the minimum stability of the package diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index b8937bb33..51a51fd27 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -127,7 +127,7 @@ class ComposerRepository extends ArrayRepository implements NotifiableRepository */ public function loadPackage(array $data) { - $package = $this->loader->load($data['raw']); + $package = $this->loader->load($data['raw'], 'Composer\Package\Package'); $package->setRepository($this); return $package; @@ -154,7 +154,7 @@ class ComposerRepository extends ArrayRepository implements NotifiableRepository $repoData = $this->loadDataFromServer(); foreach ($repoData as $package) { - $this->addPackage($this->loader->load($package)); + $this->addPackage($this->loader->load($package, 'Composer\Package\Package')); } } diff --git a/src/Composer/Repository/Pear/ChannelReader.php b/src/Composer/Repository/Pear/ChannelReader.php index 7beb37d3c..bb909b3b7 100644 --- a/src/Composer/Repository/Pear/ChannelReader.php +++ b/src/Composer/Repository/Pear/ChannelReader.php @@ -17,7 +17,7 @@ use Composer\Util\RemoteFilesystem; /** * PEAR Channel package reader. * - * Reads channel packages info from and builds MemoryPackage's + * Reads channel packages info from and builds Package's * * @author Alexey Prilipko */ diff --git a/src/Composer/Repository/PearRepository.php b/src/Composer/Repository/PearRepository.php index 6b3119e47..7af8e6f4d 100644 --- a/src/Composer/Repository/PearRepository.php +++ b/src/Composer/Repository/PearRepository.php @@ -15,7 +15,7 @@ namespace Composer\Repository; use Composer\IO\IOInterface; use Composer\Package\Version\VersionParser; use Composer\Repository\Pear\ChannelReader; -use Composer\Package\MemoryPackage; +use Composer\Package\CompletePackage; use Composer\Repository\Pear\ChannelInfo; use Composer\Package\Link; use Composer\Package\LinkConstraint\VersionConstraint; @@ -81,10 +81,10 @@ class PearRepository extends ArrayRepository } /** - * Builds MemoryPackages from PEAR package definition data. + * Builds CompletePackages from PEAR package definition data. * * @param ChannelInfo $channelInfo - * @return MemoryPackage + * @return CompletePackage */ private function buildComposerPackages(ChannelInfo $channelInfo, VersionParser $versionParser) { @@ -152,7 +152,7 @@ class PearRepository extends ArrayRepository } } - $package = new MemoryPackage($composerPackageName, $normalizedVersion, $version); + $package = new CompletePackage($composerPackageName, $normalizedVersion, $version); $package->setType('pear-library'); $package->setDescription($packageDefinition->getDescription()); $package->setDistType('file'); diff --git a/src/Composer/Repository/PlatformRepository.php b/src/Composer/Repository/PlatformRepository.php index c7db1f8ea..c6affe9a2 100644 --- a/src/Composer/Repository/PlatformRepository.php +++ b/src/Composer/Repository/PlatformRepository.php @@ -12,7 +12,7 @@ namespace Composer\Repository; -use Composer\Package\MemoryPackage; +use Composer\Package\CompletePackage; use Composer\Package\Version\VersionParser; /** @@ -34,7 +34,7 @@ class PlatformRepository extends ArrayRepository $version = $versionParser->normalize($prettyVersion); } - $php = new MemoryPackage('php', $version, $prettyVersion); + $php = new CompletePackage('php', $version, $prettyVersion); $php->setDescription('The PHP interpreter'); parent::addPackage($php); @@ -55,7 +55,7 @@ class PlatformRepository extends ArrayRepository $version = $versionParser->normalize($prettyVersion); } - $ext = new MemoryPackage('ext-'.$name, $version, $prettyVersion); + $ext = new CompletePackage('ext-'.$name, $version, $prettyVersion); $ext->setDescription('The '.$name.' PHP extension'); parent::addPackage($ext); } @@ -107,7 +107,7 @@ class PlatformRepository extends ArrayRepository continue; } - $lib = new MemoryPackage('lib-'.$name, $version, $prettyVersion); + $lib = new CompletePackage('lib-'.$name, $version, $prettyVersion); $lib->setDescription('The '.$name.' PHP library'); parent::addPackage($lib); } diff --git a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php index 9a5d48ba9..33601cc91 100644 --- a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php +++ b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php @@ -15,7 +15,7 @@ namespace Composer\Test\Autoload; use Composer\Autoload\AutoloadGenerator; use Composer\Util\Filesystem; use Composer\Package\AliasPackage; -use Composer\Package\MemoryPackage; +use Composer\Package\Package; use Composer\Test\TestCase; class AutoloadGeneratorTest extends TestCase @@ -76,7 +76,7 @@ class AutoloadGeneratorTest extends TestCase public function testMainPackageAutoloading() { - $package = new MemoryPackage('a', '1.0', '1.0'); + $package = new Package('a', '1.0', '1.0'); $package->setAutoload(array( 'psr-0' => array('Main' => 'src/', 'Lala' => array('src/', 'lib/')), 'classmap' => array('composersrc/'), @@ -101,7 +101,7 @@ class AutoloadGeneratorTest extends TestCase { $this->vendorDir = $this->workingDir; - $package = new MemoryPackage('a', '1.0', '1.0'); + $package = new Package('a', '1.0', '1.0'); $package->setAutoload(array( 'psr-0' => array('Main' => 'src/', 'Lala' => 'src/'), 'classmap' => array('composersrc/'), @@ -124,7 +124,7 @@ class AutoloadGeneratorTest extends TestCase public function testMainPackageAutoloadingAlternativeVendorDir() { - $package = new MemoryPackage('a', '1.0', '1.0'); + $package = new Package('a', '1.0', '1.0'); $package->setAutoload(array( 'psr-0' => array('Main' => 'src/', 'Lala' => 'src/'), 'classmap' => array('composersrc/'), @@ -147,7 +147,7 @@ class AutoloadGeneratorTest extends TestCase public function testMainPackageAutoloadingWithTargetDir() { - $package = new MemoryPackage('a', '1.0', '1.0'); + $package = new Package('a', '1.0', '1.0'); $package->setAutoload(array( 'psr-0' => array('Main\\Foo' => '', 'Main\\Bar' => ''), )); @@ -166,11 +166,11 @@ class AutoloadGeneratorTest extends TestCase public function testVendorsAutoloading() { - $package = new MemoryPackage('a', '1.0', '1.0'); + $package = new Package('a', '1.0', '1.0'); $packages = array(); - $packages[] = $a = new MemoryPackage('a/a', '1.0', '1.0'); - $packages[] = $b = new MemoryPackage('b/b', '1.0', '1.0'); + $packages[] = $a = new Package('a/a', '1.0', '1.0'); + $packages[] = $b = new Package('b/b', '1.0', '1.0'); $packages[] = $c = new AliasPackage($b, '1.2', '1.2'); $a->setAutoload(array('psr-0' => array('A' => 'src/', 'A\\B' => 'lib/'))); $b->setAutoload(array('psr-0' => array('B\\Sub\\Name' => 'src/'))); @@ -191,11 +191,11 @@ class AutoloadGeneratorTest extends TestCase public function testVendorsClassMapAutoloading() { - $package = new MemoryPackage('a', '1.0', '1.0'); + $package = new Package('a', '1.0', '1.0'); $packages = array(); - $packages[] = $a = new MemoryPackage('a/a', '1.0', '1.0'); - $packages[] = $b = new MemoryPackage('b/b', '1.0', '1.0'); + $packages[] = $a = new Package('a/a', '1.0', '1.0'); + $packages[] = $b = new Package('b/b', '1.0', '1.0'); $a->setAutoload(array('classmap' => array('src/'))); $b->setAutoload(array('classmap' => array('src/', 'lib/'))); @@ -226,12 +226,12 @@ class AutoloadGeneratorTest extends TestCase public function testClassMapAutoloadingEmptyDirAndExactFile() { - $package = new MemoryPackage('a', '1.0', '1.0'); + $package = new Package('a', '1.0', '1.0'); $packages = array(); - $packages[] = $a = new MemoryPackage('a/a', '1.0', '1.0'); - $packages[] = $b = new MemoryPackage('b/b', '1.0', '1.0'); - $packages[] = $c = new MemoryPackage('c/c', '1.0', '1.0'); + $packages[] = $a = new Package('a/a', '1.0', '1.0'); + $packages[] = $b = new Package('b/b', '1.0', '1.0'); + $packages[] = $c = new Package('c/c', '1.0', '1.0'); $a->setAutoload(array('classmap' => array(''))); $b->setAutoload(array('classmap' => array('test.php'))); $c->setAutoload(array('classmap' => array('./'))); @@ -263,12 +263,12 @@ class AutoloadGeneratorTest extends TestCase public function testFilesAutoloadGeneration() { - $package = new MemoryPackage('a', '1.0', '1.0'); + $package = new Package('a', '1.0', '1.0'); $package->setAutoload(array('files' => array('root.php'))); $packages = array(); - $packages[] = $a = new MemoryPackage('a/a', '1.0', '1.0'); - $packages[] = $b = new MemoryPackage('b/b', '1.0', '1.0'); + $packages[] = $a = new Package('a/a', '1.0', '1.0'); + $packages[] = $b = new Package('b/b', '1.0', '1.0'); $a->setAutoload(array('files' => array('test.php'))); $b->setAutoload(array('files' => array('test2.php'))); @@ -297,12 +297,12 @@ class AutoloadGeneratorTest extends TestCase public function testOverrideVendorsAutoloading() { - $package = new MemoryPackage('a', '1.0', '1.0'); + $package = new Package('a', '1.0', '1.0'); $package->setAutoload(array('psr-0' => array('A\\B' => $this->workingDir.'/lib'))); $packages = array(); - $packages[] = $a = new MemoryPackage('a/a', '1.0', '1.0'); - $packages[] = $b = new MemoryPackage('b/b', '1.0', '1.0'); + $packages[] = $a = new Package('a/a', '1.0', '1.0'); + $packages[] = $b = new Package('b/b', '1.0', '1.0'); $a->setAutoload(array('psr-0' => array('A' => 'src/', 'A\\B' => 'lib/'))); $b->setAutoload(array('psr-0' => array('B\\Sub\\Name' => 'src/'))); @@ -356,16 +356,16 @@ EOF; public function testIncludePathFileGeneration() { - $package = new MemoryPackage('a', '1.0', '1.0'); + $package = new Package('a', '1.0', '1.0'); $packages = array(); - $a = new MemoryPackage("a/a", "1.0", "1.0"); + $a = new Package("a/a", "1.0", "1.0"); $a->setIncludePaths(array("lib/")); - $b = new MemoryPackage("b/b", "1.0", "1.0"); + $b = new Package("b/b", "1.0", "1.0"); $b->setIncludePaths(array("library")); - $c = new MemoryPackage("c", "1.0", "1.0"); + $c = new Package("c", "1.0", "1.0"); $c->setIncludePaths(array("library")); $packages[] = $a; @@ -393,10 +393,10 @@ EOF; public function testIncludePathsArePrependedInAutoloadFile() { - $package = new MemoryPackage('a', '1.0', '1.0'); + $package = new Package('a', '1.0', '1.0'); $packages = array(); - $a = new MemoryPackage("a/a", "1.0", "1.0"); + $a = new Package("a/a", "1.0", "1.0"); $a->setIncludePaths(array("lib/")); $packages[] = $a; @@ -426,10 +426,10 @@ EOF; public function testIncludePathFileWithoutPathsIsSkipped() { - $package = new MemoryPackage('a', '1.0', '1.0'); + $package = new Package('a', '1.0', '1.0'); $packages = array(); - $a = new MemoryPackage("a/a", "1.0", "1.0"); + $a = new Package("a/a", "1.0", "1.0"); $packages[] = $a; $this->repository->expects($this->once()) diff --git a/tests/Composer/Test/ComposerTest.php b/tests/Composer/Test/ComposerTest.php index 6ff841919..c23488251 100644 --- a/tests/Composer/Test/ComposerTest.php +++ b/tests/Composer/Test/ComposerTest.php @@ -18,7 +18,7 @@ class ComposerTest extends TestCase public function testSetGetPackage() { $composer = new Composer(); - $package = $this->getMock('Composer\Package\PackageInterface'); + $package = $this->getMock('Composer\Package\RootPackageInterface'); $composer->setPackage($package); $this->assertSame($package, $composer->getPackage()); diff --git a/tests/Composer/Test/Installer/LibraryInstallerTest.php b/tests/Composer/Test/Installer/LibraryInstallerTest.php index fb130967d..c76052e22 100644 --- a/tests/Composer/Test/Installer/LibraryInstallerTest.php +++ b/tests/Composer/Test/Installer/LibraryInstallerTest.php @@ -235,7 +235,7 @@ class LibraryInstallerTest extends TestCase protected function createPackageMock() { - return $this->getMockBuilder('Composer\Package\MemoryPackage') + return $this->getMockBuilder('Composer\Package\Package') ->setConstructorArgs(array(md5(rand()), '1.0.0.0', '1.0.0')) ->getMock(); } diff --git a/tests/Composer/Test/Installer/MetapackageInstallerTest.php b/tests/Composer/Test/Installer/MetapackageInstallerTest.php index 1aa3d3e66..a590274df 100644 --- a/tests/Composer/Test/Installer/MetapackageInstallerTest.php +++ b/tests/Composer/Test/Installer/MetapackageInstallerTest.php @@ -94,7 +94,7 @@ class MetapackageInstallerTest extends \PHPUnit_Framework_TestCase private function createPackageMock() { - return $this->getMockBuilder('Composer\Package\MemoryPackage') + return $this->getMockBuilder('Composer\Package\Package') ->setConstructorArgs(array(md5(rand()), '1.0.0.0', '1.0.0')) ->getMock(); } diff --git a/tests/Composer/Test/InstallerTest.php b/tests/Composer/Test/InstallerTest.php index ebb684894..d4635f246 100644 --- a/tests/Composer/Test/InstallerTest.php +++ b/tests/Composer/Test/InstallerTest.php @@ -17,7 +17,7 @@ use Composer\Config; use Composer\Json\JsonFile; use Composer\Repository\ArrayRepository; use Composer\Repository\RepositoryManager; -use Composer\Package\PackageInterface; +use Composer\Package\RootPackageInterface; use Composer\Package\Link; use Composer\Package\Locker; use Composer\Test\Mock\FactoryMock; @@ -32,7 +32,7 @@ class InstallerTest extends TestCase /** * @dataProvider provideInstaller */ - public function testInstaller(PackageInterface $rootPackage, $repositories, array $options) + public function testInstaller(RootPackageInterface $rootPackage, $repositories, array $options) { $io = $this->getMock('Composer\IO\IOInterface'); @@ -80,7 +80,7 @@ class InstallerTest extends TestCase // when A requires B and B requires A, and A is a non-published root package // the install of B should succeed - $a = $this->getPackage('A', '1.0.0'); + $a = $this->getPackage('A', '1.0.0', 'Composer\Package\RootPackage'); $a->setRequires(array( new Link('A', 'B', $this->getVersionConstraint('=', '1.0.0')), )); @@ -100,7 +100,7 @@ class InstallerTest extends TestCase // #480: when A requires B and B requires A, and A is a published root package // only B should be installed, as A is the root - $a = $this->getPackage('A', '1.0.0'); + $a = $this->getPackage('A', '1.0.0', 'Composer\Package\RootPackage'); $a->setRequires(array( new Link('A', 'B', $this->getVersionConstraint('=', '1.0.0')), )); diff --git a/tests/Composer/Test/Package/MemoryPackageTest.php b/tests/Composer/Test/Package/CompletePackageTest.php similarity index 78% rename from tests/Composer/Test/Package/MemoryPackageTest.php rename to tests/Composer/Test/Package/CompletePackageTest.php index b843d18c2..cccdae1c0 100644 --- a/tests/Composer/Test/Package/MemoryPackageTest.php +++ b/tests/Composer/Test/Package/CompletePackageTest.php @@ -12,11 +12,11 @@ namespace Composer\Test\Package; -use Composer\Package\MemoryPackage; +use Composer\Package\Package; use Composer\Package\Version\VersionParser; use Composer\Test\TestCase; -class MemoryPackageTest extends TestCase +class CompletePackageTest extends TestCase { /** * Memory package naming, versioning, and marshalling semantics provider @@ -38,11 +38,11 @@ class MemoryPackageTest extends TestCase * Tests memory package naming semantics * @dataProvider providerVersioningSchemes */ - public function testMemoryPackageHasExpectedNamingSemantics($name, $version) + public function testPackageHasExpectedNamingSemantics($name, $version) { $versionParser = new VersionParser(); $normVersion = $versionParser->normalize($version); - $package = new MemoryPackage($name, $normVersion, $version); + $package = new Package($name, $normVersion, $version); $this->assertEquals(strtolower($name), $package->getName()); } @@ -50,11 +50,11 @@ class MemoryPackageTest extends TestCase * Tests memory package versioning semantics * @dataProvider providerVersioningSchemes */ - public function testMemoryPackageHasExpectedVersioningSemantics($name, $version) + public function testPackageHasExpectedVersioningSemantics($name, $version) { $versionParser = new VersionParser(); $normVersion = $versionParser->normalize($version); - $package = new MemoryPackage($name, $normVersion, $version); + $package = new Package($name, $normVersion, $version); $this->assertEquals($version, $package->getPrettyVersion()); $this->assertEquals($normVersion, $package->getVersion()); } @@ -63,11 +63,11 @@ class MemoryPackageTest extends TestCase * Tests memory package marshalling/serialization semantics * @dataProvider providerVersioningSchemes */ - public function testMemoryPackageHasExpectedMarshallingSemantics($name, $version) + public function testPackageHasExpectedMarshallingSemantics($name, $version) { $versionParser = new VersionParser(); $normVersion = $versionParser->normalize($version); - $package = new MemoryPackage($name, $normVersion, $version); + $package = new Package($name, $normVersion, $version); $this->assertEquals(strtolower($name).'-'.$normVersion, (string) $package); } diff --git a/tests/Composer/Test/Package/Dumper/ArrayDumperTest.php b/tests/Composer/Test/Package/Dumper/ArrayDumperTest.php index 11ce676e4..9387ef926 100644 --- a/tests/Composer/Test/Package/Dumper/ArrayDumperTest.php +++ b/tests/Composer/Test/Package/Dumper/ArrayDumperTest.php @@ -23,14 +23,14 @@ class ArrayDumperTest extends \PHPUnit_Framework_TestCase */ private $dumper; /** - * @var \Composer\Package\PackageInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Composer\Package\CompletePackageInterface|\PHPUnit_Framework_MockObject_MockObject */ private $package; public function setUp() { $this->dumper = new ArrayDumper(); - $this->package = $this->getMock('Composer\Package\PackageInterface'); + $this->package = $this->getMock('Composer\Package\CompletePackageInterface'); } public function testRequiredInformation() diff --git a/tests/Composer/Test/Repository/Pear/ChannelReaderTest.php b/tests/Composer/Test/Repository/Pear/ChannelReaderTest.php index 8a93a60aa..127c5689c 100644 --- a/tests/Composer/Test/Repository/Pear/ChannelReaderTest.php +++ b/tests/Composer/Test/Repository/Pear/ChannelReaderTest.php @@ -16,7 +16,7 @@ use Composer\Test\TestCase; use Composer\Package\Version\VersionParser; use Composer\Package\LinkConstraint\VersionConstraint; use Composer\Package\Link; -use Composer\Package\MemoryPackage; +use Composer\Package\CompletePackage; use Composer\Test\Mock\RemoteFilesystemMock; class ChannelReaderTest extends TestCase @@ -117,7 +117,7 @@ class ChannelReaderTest extends TestCase $packages = $ref->invoke($reader, $channelInfo, new VersionParser()); - $expectedPackage = new MemoryPackage('pear-test.loc/sample', '1.0.0.1' , '1.0.0.1'); + $expectedPackage = new CompletePackage('pear-test.loc/sample', '1.0.0.1' , '1.0.0.1'); $expectedPackage->setType('pear-library'); $expectedPackage->setDistType('file'); $expectedPackage->setDescription('description'); diff --git a/tests/Composer/Test/TestCase.php b/tests/Composer/Test/TestCase.php index 0e13a7921..bb4e0f14b 100644 --- a/tests/Composer/Test/TestCase.php +++ b/tests/Composer/Test/TestCase.php @@ -13,7 +13,7 @@ namespace Composer\Test; use Composer\Package\Version\VersionParser; -use Composer\Package\MemoryPackage; +use Composer\Package\Package; use Composer\Package\AliasPackage; use Composer\Package\LinkConstraint\VersionConstraint; use Composer\Util\Filesystem; @@ -43,11 +43,11 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase return $constraint; } - protected function getPackage($name, $version) + protected function getPackage($name, $version, $class = 'Composer\Package\Package') { $normVersion = self::getVersionParser()->normalize($version); - return new MemoryPackage($name, $normVersion, $version); + return new $class($name, $normVersion, $version); } protected function getAliasPackage($package, $version)