diff --git a/src/Service/PackageSynchronizer/ComposerPackageSynchronizer.php b/src/Service/PackageSynchronizer/ComposerPackageSynchronizer.php index 648ab61e..eda1d6bd 100644 --- a/src/Service/PackageSynchronizer/ComposerPackageSynchronizer.php +++ b/src/Service/PackageSynchronizer/ComposerPackageSynchronizer.php @@ -70,6 +70,14 @@ public function synchronize(Package $package): void return $a->getReleaseDate() <=> $b->getReleaseDate(); } + if ($a->getStability() === Version::STABILITY_STABLE && $b->getStability() !== Version::STABILITY_STABLE) { + return -1; + } + + if ($a->getStability() !== Version::STABILITY_STABLE && $b->getStability() === Version::STABILITY_STABLE) { + return 1; + } + return Comparator::greaterThan($a->getVersion(), $b->getVersion()) ? 1 : -1; }); diff --git a/tests/Resources/artifacts-mixed-sorting/a-dev-development.zip b/tests/Resources/artifacts-mixed-sorting/a-dev-development.zip new file mode 100644 index 00000000..1963a15d Binary files /dev/null and b/tests/Resources/artifacts-mixed-sorting/a-dev-development.zip differ diff --git a/tests/Resources/artifacts-mixed-sorting/b-1.0.0.zip b/tests/Resources/artifacts-mixed-sorting/b-1.0.0.zip new file mode 100644 index 00000000..8242f165 Binary files /dev/null and b/tests/Resources/artifacts-mixed-sorting/b-1.0.0.zip differ diff --git a/tests/Unit/Service/PackageSynchronizer/ComposerPackageSynchronizerTest.php b/tests/Unit/Service/PackageSynchronizer/ComposerPackageSynchronizerTest.php index a36849ed..79f6039a 100644 --- a/tests/Unit/Service/PackageSynchronizer/ComposerPackageSynchronizerTest.php +++ b/tests/Unit/Service/PackageSynchronizer/ComposerPackageSynchronizerTest.php @@ -111,6 +111,15 @@ public function testSynchronizePackageFromArtifacts(): void self::assertContains('suggests-buddy-works/suggests-You really should', $linkStrings); } + public function testWithMostRecentUnstable(): void + { + $this->downloader->addContent($this->resourcesDir.'artifacts-mixed-sorting', 'foobar'); + $package = PackageMother::withOrganization('artifact', $this->resourcesDir.'artifacts-mixed-sorting', 'buddy'); + $this->synchronizer->synchronize($package); + + self::assertEquals('v1.0.0', $this->getProperty($package, 'latestReleasedVersion')); + } + public function testSynchronizePackageThatAlreadyExists(): void { $path = $this->baseDir.'/buddy/p/buddy-works/alpha.json';