Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade nikolaposa/version to 4.0.0 #179

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"ext-json": "*",
"beberlei/assert": "^3.2.6",
"composer/composer": "^1.9.0",
"nikolaposa/version": "^3.2.0",
"nikolaposa/version": "^4.0.0",
"ocramius/package-versions": "^1.5.1",
"roave/better-reflection": "^3.5.0",
"symfony/console": "^4.3.4",
Expand Down
29 changes: 15 additions & 14 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/Command/AssertBackwardsCompatible.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ private function determineFromRevisionFromRepository(
Assert::that($versions->count())
->greaterThan(0, 'Could not detect any released versions for the given repository');

$versionString = $this->pickFromVersion->forVersions($versions)->getVersionString();
$versionString = $this->pickFromVersion->forVersions($versions)->toString();

$output->writeln(sprintf('Detected last minor version: %s', $versionString));

Expand Down
4 changes: 2 additions & 2 deletions src/Git/GetVersionCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Roave\BackwardCompatibility\Git;

use Version\VersionsCollection;
use Version\VersionCollection;

interface GetVersionCollection
{
public function fromRepository(CheckedOutRepository $repository) : VersionsCollection;
public function fromRepository(CheckedOutRepository $repository) : VersionCollection;
}
10 changes: 5 additions & 5 deletions src/Git/GetVersionCollectionFromGitRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Exception\RuntimeException;
use Symfony\Component\Process\Process;
use Version\Exception\InvalidVersionStringException;
use Version\Exception\InvalidVersionString;
use Version\Version;
use Version\VersionsCollection;
use Version\VersionCollection;
use function array_filter;
use function array_map;
use function explode;
Expand All @@ -24,18 +24,18 @@ final class GetVersionCollectionFromGitRepository implements GetVersionCollectio
* @throws LogicException
* @throws RuntimeException
*/
public function fromRepository(CheckedOutRepository $checkedOutRepository) : VersionsCollection
public function fromRepository(CheckedOutRepository $checkedOutRepository) : VersionCollection
{
$output = (new Process(['git', 'tag', '-l']))
->setWorkingDirectory($checkedOutRepository->__toString())
->mustRun()
->getOutput();

return new VersionsCollection(...array_filter(
return new VersionCollection(...array_filter(
array_map(static function (string $maybeVersion) : ?Version {
try {
return Version::fromString($maybeVersion);
} catch (InvalidVersionStringException $e) {
} catch (InvalidVersionString $e) {
return null;
}
}, explode("\n", $output))
Expand Down
22 changes: 9 additions & 13 deletions src/Git/PickLastMinorVersionFromCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
use Assert\Assert;
use Symfony\Component\Process\Exception\LogicException;
use Symfony\Component\Process\Exception\RuntimeException;
use Version\Constraint\ComparisonConstraint;
use Version\Constraint\CompositeConstraint;
use Version\Constraint\ConstraintInterface;
use Version\Comparison\Constraint\CompositeConstraint;
use Version\Comparison\Constraint\Constraint;
use Version\Comparison\Constraint\OperationConstraint;
use Version\Version;
use Version\VersionsCollection;
use Version\VersionCollection;

final class PickLastMinorVersionFromCollection implements PickVersionFromVersionCollection
{
Expand All @@ -21,12 +21,12 @@ final class PickLastMinorVersionFromCollection implements PickVersionFromVersion
* @throws LogicException
* @throws RuntimeException
*/
public function forVersions(VersionsCollection $versions) : Version
public function forVersions(VersionCollection $versions) : Version
{
Assert::that($versions->count())
->greaterThan(0, 'Cannot determine latest minor version from an empty collection');

$stableVersions = $versions->matching(new class implements ConstraintInterface {
$stableVersions = $versions->matching(new class implements Constraint {
public function assert(Version $version) : bool
{
return ! $version->isPreRelease();
Expand All @@ -38,13 +38,9 @@ public function assert(Version $version) : bool
$lastVersion = $versionsSortedDescending->first();

$matchingMinorVersions = $stableVersions
->matching(new CompositeConstraint(
CompositeConstraint::OPERATOR_AND,
new ComparisonConstraint(ComparisonConstraint::OPERATOR_LTE, $lastVersion),
new ComparisonConstraint(
ComparisonConstraint::OPERATOR_GTE,
Version::fromString($lastVersion->getMajor() . '.' . $lastVersion->getMinor() . '.0')
)
->matching(CompositeConstraint::and(
OperationConstraint::lessOrEqualTo($lastVersion),
nikolaposa marked this conversation as resolved.
Show resolved Hide resolved
OperationConstraint::greaterOrEqualTo(Version::fromString($lastVersion->getMajor() . '.' . $lastVersion->getMinor() . '.0'))
))
->sortedAscending();

Expand Down
4 changes: 2 additions & 2 deletions src/Git/PickVersionFromVersionCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Roave\BackwardCompatibility\Git;

use Version\Version;
use Version\VersionsCollection;
use Version\VersionCollection;

interface PickVersionFromVersionCollection
{
public function forVersions(VersionsCollection $versionsCollection) : Version;
public function forVersions(VersionCollection $versionsCollection) : Version;
}
18 changes: 9 additions & 9 deletions test/unit/Command/AssertBackwardsCompatibleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Version\Version;
use Version\VersionsCollection;
use Version\VersionCollection;
use function Safe\chdir;
use function Safe\realpath;
use function sha1;
Expand Down Expand Up @@ -320,7 +320,7 @@ public function testExecuteWithDefaultRevisionsNotProvidedAndNoDetectedTags() :
->getVersions
->expects(self::once())
->method('fromRepository')
->willReturn(new VersionsCollection());
->willReturn(new VersionCollection());
$this
->pickVersion
->expects(self::never())
Expand All @@ -336,9 +336,9 @@ public function testExecuteWithDefaultRevisionsNotProvidedAndNoDetectedTags() :
}

/**
* @dataProvider validVersionsCollections
* @dataProvider validVersionCollections
*/
public function testExecuteWithDefaultRevisionsNotProvided(VersionsCollection $versions) : void
public function testExecuteWithDefaultRevisionsNotProvided(VersionCollection $versions) : void
{
$fromSha = sha1('fromRevision', false);
$toSha = sha1('toRevision', false);
Expand Down Expand Up @@ -404,22 +404,22 @@ public function testExecuteWithDefaultRevisionsNotProvided(VersionsCollection $v
self::assertSame(0, $this->compare->execute($this->input, $this->output));
}

/** @return VersionsCollection[][] */
public function validVersionsCollections() : array
/** @return VersionCollection[][] */
public function validVersionCollections() : array
{
return [
[new VersionsCollection(
[new VersionCollection(
Version::fromString('1.0.0'),
Version::fromString('1.0.1'),
Version::fromString('1.0.2')
),
],
[new VersionsCollection(
[new VersionCollection(
Version::fromString('1.0.0'),
Version::fromString('1.0.1')
),
],
[new VersionsCollection(Version::fromString('1.0.0'))],
[new VersionCollection(Version::fromString('1.0.0'))],
];
}
}
4 changes: 2 additions & 2 deletions test/unit/Git/GetVersionCollectionFromGitRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private function getTags() : array
{
return array_map(
static function (Version $version) : string {
return $version->getVersionString();
return $version->toString();
},
iterator_to_array((new GetVersionCollectionFromGitRepository())->fromRepository($this->repoPath))
);
Expand All @@ -76,6 +76,6 @@ public function testFromRepositoryAllowsVersionPrefix() : void
{
$this->makeTag('v1.0.0');

self::assertSame(['1.0.0'], $this->getTags());
self::assertSame(['v1.0.0'], $this->getTags());
Ocramius marked this conversation as resolved.
Show resolved Hide resolved
}
}
8 changes: 4 additions & 4 deletions test/unit/Git/PickLastMinorVersionFromCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PHPUnit\Framework\TestCase;
use Roave\BackwardCompatibility\Git\PickLastMinorVersionFromCollection;
use Version\Version;
use Version\VersionsCollection;
use Version\VersionCollection;
use function array_map;

/**
Expand Down Expand Up @@ -48,10 +48,10 @@ public function testForRepository(string $expectedVersion, array $collectionOfVe
self::assertSame(
$expectedVersion,
(new PickLastMinorVersionFromCollection())->forVersions(
new VersionsCollection(...array_map(static function (string $version) : Version {
new VersionCollection(...array_map(static function (string $version) : Version {
return Version::fromString($version);
}, $collectionOfVersions))
)->getVersionString()
)->toString()
);
}

Expand All @@ -61,6 +61,6 @@ public function testWillRejectEmptyCollection() : void

$this->expectException(AssertionFailedException::class);

$pick->forVersions(new VersionsCollection());
$pick->forVersions(new VersionCollection());
}
}