Skip to content

Commit

Permalink
Merge branch 'feature/bump-nikolaposa-version'
Browse files Browse the repository at this point in the history
Close #61
Ocramius committed May 26, 2018
2 parents 58d3a9b + 36ea4a9 commit 553f37e
Showing 7 changed files with 35 additions and 34 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -5,8 +5,8 @@
"php": "^7.2",
"beberlei/assert": "^2.9",
"composer/composer": "^1.6",
"nikolaposa/version": "^2.2",
"roave/better-reflection": "^3.0",
"nikolaposa/version": "^3.0",
"roave/better-reflection": "^3.0",
"symfony/console": "^4.0",
"symfony/process": "^4.0"
},
27 changes: 12 additions & 15 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Git/GetVersionCollectionFromGitRepository.php
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ public function fromRepository(CheckedOutRepository $checkedOutRepository) : Ver
->mustRun()
->getOutput();

return VersionsCollection::fromArray(array_filter(
return new VersionsCollection(...array_filter(
array_map(function (string $maybeVersion) : ?Version {
try {
return Version::fromString($maybeVersion);
11 changes: 7 additions & 4 deletions src/Git/PickLastMinorVersionFromCollection.php
Original file line number Diff line number Diff line change
@@ -4,11 +4,12 @@

namespace Roave\BackwardCompatibility\Git;

use Assert\Assert;
use Symfony\Component\Process\Exception\LogicException;
use Symfony\Component\Process\Exception\RuntimeException;
use Version\Version;
use Version\VersionsCollection;
use function iterator_to_array;
use function reset;

final class PickLastMinorVersionFromCollection implements PickVersionFromVersionCollection
{
@@ -19,18 +20,20 @@ final class PickLastMinorVersionFromCollection implements PickVersionFromVersion
*/
public function forVersions(VersionsCollection $versions) : Version
{
Assert::that($versions->count())->greaterOrEqualThan(1);

$versions->sort(VersionsCollection::SORT_DESC);

/** @var Version[] $versionsAsArray */
$versionsAsArray = iterator_to_array($versions->getIterator());
/** @var Version $lastVersion */
$lastVersion = $versions->getIterator()->current();
$lastVersion = reset($versionsAsArray);
$previousVersionInIteration = $lastVersion;

/** @var Version $version */
foreach ($versions as $version) {
if ($lastVersion->getMinor() !== $version->getMinor()) {
return $previousVersionInIteration;
}

$previousVersionInIteration = $version;
}

2 changes: 1 addition & 1 deletion test/unit/Command/AssertBackwardsCompatibleTest.php
Original file line number Diff line number Diff line change
@@ -280,7 +280,7 @@ public function testExecuteWithDefaultRevisionsNotProvided() : void
{
$fromSha = sha1('fromRevision', false);
$toSha = sha1('toRevision', false);
$versions = VersionsCollection::fromArray(['1.0.0', '1.0.1']);
$versions = new VersionsCollection(Version::fromString('1.0.0'), Version::fromString('1.0.1'));
$pickedVersion = Version::fromString('1.0.0');

$this->input->expects(self::any())->method('hasOption')->willReturn(false);
7 changes: 7 additions & 0 deletions test/unit/Git/GetVersionCollectionFromGitRepositoryTest.php
Original file line number Diff line number Diff line change
@@ -71,4 +71,11 @@ public function testFromRepositoryIgnoresInvalidVersions() : void

self::assertSame(['1.0.0', '1.1.0'], $this->getTags());
}

public function testFromRepositoryAllowsVersionPrefix() : void
{
$this->makeTag('v1.0.0');

self::assertSame(['1.0.0'], $this->getTags());
}
}
16 changes: 5 additions & 11 deletions test/unit/Git/PickLastMinorVersionFromCollectionTest.php
Original file line number Diff line number Diff line change
@@ -4,10 +4,11 @@

namespace RoaveTest\BackwardCompatibility\Git;

use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
use Roave\BackwardCompatibility\Git\PickLastMinorVersionFromCollection;
use Version\Version;
use Version\VersionsCollection;
use function array_map;

/**
* @covers \Roave\BackwardCompatibility\Git\PickLastMinorVersionFromCollection
@@ -36,17 +37,10 @@ public function testForRepository(string $expectedVersion, array $collectionOfVe
self::assertSame(
$expectedVersion,
(new PickLastMinorVersionFromCollection())->forVersions(
VersionsCollection::fromArray($collectionOfVersions)
new VersionsCollection(...array_map(function (string $version) : Version {
return Version::fromString($version);
}, $collectionOfVersions))
)->getVersionString()
);
}

public function testEmptyVersionCollectionResultsInException() : void
{
$versions = VersionsCollection::fromArray([]);
$determiner = new PickLastMinorVersionFromCollection();

$this->expectException(InvalidArgumentException::class);
$determiner->forVersions($versions);
}
}

0 comments on commit 553f37e

Please sign in to comment.