From f2aa72f86e6cfdc44795167169d55cee06e5c40c Mon Sep 17 00:00:00 2001 From: Ivar van der Burg Date: Tue, 7 Apr 2015 13:35:04 +0200 Subject: [PATCH 1/3] Re-add missing has() method --- src/Naneau/ProjectVersioner/Versioner.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Naneau/ProjectVersioner/Versioner.php b/src/Naneau/ProjectVersioner/Versioner.php index 0df4cd5..888f0a4 100644 --- a/src/Naneau/ProjectVersioner/Versioner.php +++ b/src/Naneau/ProjectVersioner/Versioner.php @@ -92,6 +92,23 @@ public function getCombined($directory, $separator = '-') return implode($separator, $found); } + /** + * Does a directory have a version? + * + * @param string $directory + * @return bool + **/ + public function has($directory) + { + foreach ($this->getReaders() as $reader) { + if ($reader->canRead($directory)) { + return true; + } + } + + return false; + } + /** * Get the set of readers * From 3aa2d27cbbb0402a4786d46ff819f712b553ff8c Mon Sep 17 00:00:00 2001 From: Ivar van der Burg Date: Tue, 7 Apr 2015 13:35:32 +0200 Subject: [PATCH 2/3] Test has() method --- tests/Versioner/CombineReadersTest.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/Versioner/CombineReadersTest.php b/tests/Versioner/CombineReadersTest.php index 91ae885..9c8cd88 100644 --- a/tests/Versioner/CombineReadersTest.php +++ b/tests/Versioner/CombineReadersTest.php @@ -79,4 +79,25 @@ public function testFileFirstWithCombine() ) ); } + + public function testHasAVersion() + { + $versioner = new Versioner; + + // This one should have a version + $versioner->setReaders( + array(new FileReader('VERSION')) + ); + return $this->assertTrue( + $versioner->has(__DIR__ . '/../projects/composer-file/') + ); + + // Should not have a version + $versioner->setReaders( + array(new FileReader('FOO')) + ); + return $this->assertFalse( + $versioner->has(__DIR__ . '/../projects/composer-file/') + ); + } } From 00a17cc88dbbc93ddb75f4b7017ba7cb86ca4814 Mon Sep 17 00:00:00 2001 From: Ivar van der Burg Date: Tue, 7 Apr 2015 13:35:40 +0200 Subject: [PATCH 3/3] Added composer JSON tests --- tests/Reader/ComposerTest.php | 11 +++++++++++ tests/projects/composer/composer.json | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 tests/projects/composer/composer.json diff --git a/tests/Reader/ComposerTest.php b/tests/Reader/ComposerTest.php index aade2a7..5191f39 100644 --- a/tests/Reader/ComposerTest.php +++ b/tests/Reader/ComposerTest.php @@ -3,6 +3,7 @@ use Naneau\ProjectVersioner\Versioner; use Naneau\ProjectVersioner\Reader\Composer as ComposerReader; use Naneau\ProjectVersioner\Reader\ComposerPackage as ComposerPackageReader; +use Naneau\ProjectVersioner\Reader\ComposerJson as ComposerJsonReader; class ComposerTest extends \PHPUnit_Framework_TestCase { @@ -27,4 +28,14 @@ public function testPackageRead() $this->assertEquals('v2.5.4', $versioner->get($directory)); } + + public function testComposerJsonRead() + { + $directory = __DIR__ . '/../projects/composer'; + + $readers = array(new ComposerJsonReader); + $versioner = new Versioner($readers); + + $this->assertEquals('1.0.0', $versioner->get($directory)); + } } diff --git a/tests/projects/composer/composer.json b/tests/projects/composer/composer.json new file mode 100644 index 0000000..e59b9ac --- /dev/null +++ b/tests/projects/composer/composer.json @@ -0,0 +1,24 @@ +{ + "name": "naneau/project-versioner", + "description": "A tool to maintain project/sub-project versions based on Composer, file mtimes, etc.", + "license": "MIT", + "version": "1.0.0", + "authors": [ + { + "name": "Maurice Fonk", + "email": "maurice@naneau.net" + } + ], + + "autoload": { + "psr-4": {"Naneau\\ProjectVersioner\\": "src/Naneau/ProjectVersioner/"} + }, + + "minimum-stability": "stable", + "require": { + "symfony/finder": "~2.5" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + } +}