From b70bb1a9bcf16467352fb61bbfdb50319c496390 Mon Sep 17 00:00:00 2001 From: Wil Moore III Date: Mon, 26 Sep 2011 22:05:57 -0600 Subject: [PATCH 1/5] 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); + } + } From b4df1d1a6b1949cf5dafad9e1c0521cb0cc37360 Mon Sep 17 00:00:00 2001 From: Wil Moore III Date: Tue, 27 Sep 2011 21:32:36 -0600 Subject: [PATCH 2/5] follows code review comments @ https://github.com/composer/composer/pull/23#issuecomment-2208146 --- .../Test/Package/MemoryPackageTest.php | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/tests/Composer/Test/Package/MemoryPackageTest.php b/tests/Composer/Test/Package/MemoryPackageTest.php index 822ee8996..7afb6f555 100644 --- a/tests/Composer/Test/Package/MemoryPackageTest.php +++ b/tests/Composer/Test/Package/MemoryPackageTest.php @@ -5,7 +5,6 @@ * * (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. @@ -22,11 +21,8 @@ class MemoryPackageTest extends \PHPUnit_Framework_TestCase * 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() + public function ProviderVersioningSchemes() { $provider[] = array('foo', '1-beta', 'foo-1-beta'); $provider[] = array('node', '0.5.6', 'node-0.5.6'); @@ -40,10 +36,9 @@ class MemoryPackageTest extends \PHPUnit_Framework_TestCase /** * Tests memory package naming semantics * - * @test - * @dataProvider provider_memory_package_semantics + * @dataProvider ProviderVersioningSchemes */ - public function Memory_Package_Has_Expected_Naming_Semantics($name, $version, $marshalled) + public function testMemoryPackageHasExpectedNamingSemantics($name, $version, $marshalled) { $package = new MemoryPackage($name, $version); $this->assertEquals(strtolower($name), $package->getName()); @@ -52,10 +47,9 @@ class MemoryPackageTest extends \PHPUnit_Framework_TestCase /** * Tests memory package versioning semantics * - * @test - * @dataProvider provider_memory_package_semantics + * @dataProvider ProviderVersioningSchemes */ - public function Memory_Package_Has_Expected_Versioning_Semantics($name, $version, $marshalled) + public function testMemoryPackageHasExpectedVersioningSemantics($name, $version, $marshalled) { $package = new MemoryPackage($name, $version); $this->assertEquals($version, $package->getVersion()); @@ -64,10 +58,9 @@ class MemoryPackageTest extends \PHPUnit_Framework_TestCase /** * Tests memory package marshalling/serialization semantics * - * @test - * @dataProvider provider_memory_package_semantics + * @dataProvider ProviderVersioningSchemes */ - public function Memory_Package_Has_Expected_Marshalling_Semantics($name, $version, $marshalled) + public function testMemoryPackageHasExpectedMarshallingSemantics($name, $version, $marshalled) { $package = new MemoryPackage($name, $version); $this->assertEquals($marshalled, (string) $package); From fd5b1e0f1c382f7281fb6ddc9020163d6dc88854 Mon Sep 17 00:00:00 2001 From: Wil Moore III Date: Tue, 27 Sep 2011 21:36:55 -0600 Subject: [PATCH 3/5] added annotations to test methods --- tests/Composer/Test/Package/MemoryPackageTest.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/Composer/Test/Package/MemoryPackageTest.php b/tests/Composer/Test/Package/MemoryPackageTest.php index 7afb6f555..5d63b6e9d 100644 --- a/tests/Composer/Test/Package/MemoryPackageTest.php +++ b/tests/Composer/Test/Package/MemoryPackageTest.php @@ -37,8 +37,11 @@ class MemoryPackageTest extends \PHPUnit_Framework_TestCase * Tests memory package naming semantics * * @dataProvider ProviderVersioningSchemes + * + * @param string $name + * @param string $version */ - public function testMemoryPackageHasExpectedNamingSemantics($name, $version, $marshalled) + public function testMemoryPackageHasExpectedNamingSemantics($name, $version) { $package = new MemoryPackage($name, $version); $this->assertEquals(strtolower($name), $package->getName()); @@ -48,8 +51,11 @@ class MemoryPackageTest extends \PHPUnit_Framework_TestCase * Tests memory package versioning semantics * * @dataProvider ProviderVersioningSchemes + * + * @param string $name + * @param string $version */ - public function testMemoryPackageHasExpectedVersioningSemantics($name, $version, $marshalled) + public function testMemoryPackageHasExpectedVersioningSemantics($name, $version) { $package = new MemoryPackage($name, $version); $this->assertEquals($version, $package->getVersion()); @@ -59,6 +65,10 @@ class MemoryPackageTest extends \PHPUnit_Framework_TestCase * Tests memory package marshalling/serialization semantics * * @dataProvider ProviderVersioningSchemes + * + * @param string $name + * @param string $version + * @param string $marshalled */ public function testMemoryPackageHasExpectedMarshallingSemantics($name, $version, $marshalled) { From eceb416564d98497a2ee34a6a365cd919c2bdfa0 Mon Sep 17 00:00:00 2001 From: Wil Moore III Date: Wed, 28 Sep 2011 03:18:21 -0600 Subject: [PATCH 4/5] eased up on the param documentation/annotations and lowercased the provider method. --- .../Test/Package/MemoryPackageTest.php | 21 ++++--------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/tests/Composer/Test/Package/MemoryPackageTest.php b/tests/Composer/Test/Package/MemoryPackageTest.php index 5d63b6e9d..1e6d90e34 100644 --- a/tests/Composer/Test/Package/MemoryPackageTest.php +++ b/tests/Composer/Test/Package/MemoryPackageTest.php @@ -22,7 +22,7 @@ class MemoryPackageTest extends \PHPUnit_Framework_TestCase * * demonstrates several versioning schemes */ - public function ProviderVersioningSchemes() + public function providerversioningschemes() { $provider[] = array('foo', '1-beta', 'foo-1-beta'); $provider[] = array('node', '0.5.6', 'node-0.5.6'); @@ -35,11 +35,7 @@ class MemoryPackageTest extends \PHPUnit_Framework_TestCase /** * Tests memory package naming semantics - * - * @dataProvider ProviderVersioningSchemes - * - * @param string $name - * @param string $version + * @dataProvider providerversioningschemes */ public function testMemoryPackageHasExpectedNamingSemantics($name, $version) { @@ -49,11 +45,7 @@ class MemoryPackageTest extends \PHPUnit_Framework_TestCase /** * Tests memory package versioning semantics - * - * @dataProvider ProviderVersioningSchemes - * - * @param string $name - * @param string $version + * @dataProvider providerversioningschemes */ public function testMemoryPackageHasExpectedVersioningSemantics($name, $version) { @@ -63,12 +55,7 @@ class MemoryPackageTest extends \PHPUnit_Framework_TestCase /** * Tests memory package marshalling/serialization semantics - * - * @dataProvider ProviderVersioningSchemes - * - * @param string $name - * @param string $version - * @param string $marshalled + * @dataProvider providerversioningschemes */ public function testMemoryPackageHasExpectedMarshallingSemantics($name, $version, $marshalled) { From 97de4521d0e3349e37d886026ebffc66a7d954b6 Mon Sep 17 00:00:00 2001 From: Wil Moore III Date: Wed, 28 Sep 2011 03:33:20 -0600 Subject: [PATCH 5/5] slight tweak to the casing of the provider method (providerversioningschemes -> providerVersioningSchemes) --- tests/Composer/Test/Package/MemoryPackageTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Composer/Test/Package/MemoryPackageTest.php b/tests/Composer/Test/Package/MemoryPackageTest.php index 1e6d90e34..7821185f3 100644 --- a/tests/Composer/Test/Package/MemoryPackageTest.php +++ b/tests/Composer/Test/Package/MemoryPackageTest.php @@ -22,7 +22,7 @@ class MemoryPackageTest extends \PHPUnit_Framework_TestCase * * demonstrates several versioning schemes */ - public function providerversioningschemes() + public function providerVersioningSchemes() { $provider[] = array('foo', '1-beta', 'foo-1-beta'); $provider[] = array('node', '0.5.6', 'node-0.5.6'); @@ -35,7 +35,7 @@ class MemoryPackageTest extends \PHPUnit_Framework_TestCase /** * Tests memory package naming semantics - * @dataProvider providerversioningschemes + * @dataProvider providerVersioningSchemes */ public function testMemoryPackageHasExpectedNamingSemantics($name, $version) { @@ -45,7 +45,7 @@ class MemoryPackageTest extends \PHPUnit_Framework_TestCase /** * Tests memory package versioning semantics - * @dataProvider providerversioningschemes + * @dataProvider providerVersioningSchemes */ public function testMemoryPackageHasExpectedVersioningSemantics($name, $version) { @@ -55,7 +55,7 @@ class MemoryPackageTest extends \PHPUnit_Framework_TestCase /** * Tests memory package marshalling/serialization semantics - * @dataProvider providerversioningschemes + * @dataProvider providerVersioningSchemes */ public function testMemoryPackageHasExpectedMarshallingSemantics($name, $version, $marshalled) {