From de1f2c3efac144529cdcbc71511040d540d35516 Mon Sep 17 00:00:00 2001 From: Marick van Tuil Date: Sun, 30 Apr 2023 07:37:35 +0200 Subject: [PATCH] Fix no stable release sorting bug (#617) * Fix no stable release sorting bug * Try with Composer 1 * Fix assertion * Fix buddy yaml --------- Co-authored-by: Marick Co-authored-by: Arkadiusz Kondas --- .../ComposerPackageSynchronizer.php | 8 ++++++++ .../artifacts-mixed-sorting/a-dev-development.zip | Bin 0 -> 652 bytes .../Resources/artifacts-mixed-sorting/b-1.0.0.zip | Bin 0 -> 797 bytes .../ComposerPackageSynchronizerTest.php | 9 +++++++++ 4 files changed, 17 insertions(+) create mode 100644 tests/Resources/artifacts-mixed-sorting/a-dev-development.zip create mode 100644 tests/Resources/artifacts-mixed-sorting/b-1.0.0.zip 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 0000000000000000000000000000000000000000..1963a15d67b38c2bcd22feca8d0a8417295ce80c GIT binary patch literal 652 zcmWIWW@Zs#-~d9KJd;ocDChywybKBq$@#ej`NgS4dRfK!d7&Y^4D3%@Ffi!$`f?pI5NY{tdGzsG-er;Bq~<-i$s={^&x9jlg74QE9^%>j z!*0fOrAHc!Hp21p=WM@DJQa0*)6?A_RwlRa5}7~Se`EA?5r?7$-_CAYQ*>CMe9Eus zGG%{tw@qPAlHT+4V{)(QEuUKvv)=sSUcLPnLx49s$MX4mjq-t3gWMZ{)hCaEG7>6PKWXN4zQA(H z4ps??B?4JRLfzh8-NC^@Lf%1BnVTHDyu2@!=&s@I_3hy~tE=mCZp{TBHqP%x?jM^n zz+UCxeAd?r^bE*D0p5&EBFuBXpYaXd6cpg47FxkYUthz2rk0HRDokOlgJ3IquC&-}zSiR5ybe06r3-R&3j?VtU5&C-ZxP4O( z@)fFYk`qLe(-V>sKKS~Cec%u42xwrMAi=CIAZ=)1@QX21VgAO(MvVs&LP9KwjU@&} z43eT5UNaUx`oqKX=;Y6xRh_J?mMg0iSBk2xt33Hrb7tjBfxnL&oEjP(xfZIaZ``qD zi-oDG>PD4NO9hFneya%`DG3JdD^C0Bda|tY+;Zw$=|@i=ud|){M#e_o=lqQIbp7?u zo;30DHSu5RrLSS)tIe9Fr|Wrn>jpCuGeaYj?OO~qpHb$Ou zx~SxSX7088J2%UpZHc;Z{JnU6TlMj?Gs_~nR{vY@|4{jIb3c!jOyDR;n|tq|EHIEk z0UhAY$RxsyNJq%g14>6Qu%r>h!W|Fbl!Y1(=td)33yNPDSkibH$Rszm1H4(;KqfH( M;Xxqn#suO40LL!?-T(jq literal 0 HcmV?d00001 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';