From b70bb1a9bcf16467352fb61bbfdb50319c496390 Mon Sep 17 00:00:00 2001 From: Wil Moore III Date: Mon, 26 Sep 2011 22:05:57 -0600 Subject: [PATCH] memory-package-test-refactor: refactored the memory package test to be a bit more DRY and "hopefully" re-usable in anticipation of more package types being adding in the future. --- src/Composer/Package/MemoryPackage.php | 12 ++-- .../Test/Package/MemoryPackageTest.php | 60 +++++++++++++++++-- 2 files changed, 60 insertions(+), 12 deletions(-) diff --git a/src/Composer/Package/MemoryPackage.php b/src/Composer/Package/MemoryPackage.php index 535b73eb1..0276ab877 100644 --- a/src/Composer/Package/MemoryPackage.php +++ b/src/Composer/Package/MemoryPackage.php @@ -90,7 +90,7 @@ class MemoryPackage extends BasePackage */ public function setInstallationSource($type) { - $this-> installationSource = $type; + $this->installationSource = $type; } /** @@ -166,7 +166,7 @@ class MemoryPackage extends BasePackage } /** - * @param string $url + * @param string $sha1checksum */ public function setDistSha1Checksum($sha1checksum) { @@ -274,7 +274,7 @@ class MemoryPackage extends BasePackage /** * Set the provided virtual packages * - * @param array $conflicts A set of package links + * @param array $provides A set of package links */ public function setProvides(array $provides) { @@ -292,7 +292,7 @@ class MemoryPackage extends BasePackage /** * Set the packages this one replaces * - * @param array $conflicts A set of package links + * @param array $replaces A set of package links */ public function setReplaces(array $replaces) { @@ -310,7 +310,7 @@ class MemoryPackage extends BasePackage /** * Set the recommended packages * - * @param array $conflicts A set of package links + * @param array $recommends A set of package links */ public function setRecommends(array $recommends) { @@ -328,7 +328,7 @@ class MemoryPackage extends BasePackage /** * Set the suggested packages * - * @param array $conflicts A set of package links + * @param array $suggests A set of package links */ public function setSuggests(array $suggests) { diff --git a/tests/Composer/Test/Package/MemoryPackageTest.php b/tests/Composer/Test/Package/MemoryPackageTest.php index d61e97987..822ee8996 100644 --- a/tests/Composer/Test/Package/MemoryPackageTest.php +++ b/tests/Composer/Test/Package/MemoryPackageTest.php @@ -5,6 +5,7 @@ * * (c) Nils Adermann * Jordi Boggiano + * Wil Moore III * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -16,13 +17,60 @@ use Composer\Package\MemoryPackage; class MemoryPackageTest extends \PHPUnit_Framework_TestCase { - public function testMemoryPackage() + + /** + * Memory package naming, versioning, and marshalling semantics provider + * + * demonstrates several versioning schemes + * + * @todo if all package types share the same semantics, we could use a data provider + * to test them all in a single suite + */ + public function provider_memory_package_semantics() { - $package = new MemoryPackage('foo', '1-beta'); + $provider[] = array('foo', '1-beta', 'foo-1-beta'); + $provider[] = array('node', '0.5.6', 'node-0.5.6'); + $provider[] = array('li3', '0.10', 'li3-0.10'); + $provider[] = array('mongodb_odm', '1.0.0BETA3', 'mongodb_odm-1.0.0BETA3'); + $provider[] = array('DoctrineCommon', '2.2.0-DEV', 'doctrinecommon-2.2.0-DEV'); - $this->assertEquals('foo', $package->getName()); - $this->assertEquals('1-beta', $package->getVersion()); - - $this->assertEquals('foo-1-beta', (string) $package); + return $provider; } + + /** + * Tests memory package naming semantics + * + * @test + * @dataProvider provider_memory_package_semantics + */ + public function Memory_Package_Has_Expected_Naming_Semantics($name, $version, $marshalled) + { + $package = new MemoryPackage($name, $version); + $this->assertEquals(strtolower($name), $package->getName()); + } + + /** + * Tests memory package versioning semantics + * + * @test + * @dataProvider provider_memory_package_semantics + */ + public function Memory_Package_Has_Expected_Versioning_Semantics($name, $version, $marshalled) + { + $package = new MemoryPackage($name, $version); + $this->assertEquals($version, $package->getVersion()); + } + + /** + * Tests memory package marshalling/serialization semantics + * + * @test + * @dataProvider provider_memory_package_semantics + */ + public function Memory_Package_Has_Expected_Marshalling_Semantics($name, $version, $marshalled) + { + $package = new MemoryPackage($name, $version); + $this->assertEquals($marshalled, (string) $package); + } + }