Skip to content

Commit

Permalink
Merge pull request #2 from ivarb/master
Browse files Browse the repository at this point in the history
Fixed Project Versioner missing API method has()
  • Loading branch information
ivarb committed Apr 7, 2015
2 parents 794b503 + 00a17cc commit a9ea9ee
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Naneau/ProjectVersioner/Versioner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
11 changes: 11 additions & 0 deletions tests/Reader/ComposerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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));
}
}
21 changes: 21 additions & 0 deletions tests/Versioner/CombineReadersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/')
);
}
}
24 changes: 24 additions & 0 deletions tests/projects/composer/composer.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]"
}
],

"autoload": {
"psr-4": {"Naneau\\ProjectVersioner\\": "src/Naneau/ProjectVersioner/"}
},

"minimum-stability": "stable",
"require": {
"symfony/finder": "~2.5"
},
"require-dev": {
"phpunit/phpunit": "~4.2"
}
}

0 comments on commit a9ea9ee

Please sign in to comment.