From 8b54970aef2f90cc42b8497ded6b6b5f92e0bebb Mon Sep 17 00:00:00 2001 From: Florian Weber Date: Tue, 25 Jul 2017 18:13:54 +0200 Subject: [PATCH] Use the proper Packagist API (Fixes #10) --- src/Strategy/GithubStrategy.php | 6 +++--- .../Test/SelfUpdate/UpdaterGithubStrategyTest.php | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Strategy/GithubStrategy.php b/src/Strategy/GithubStrategy.php index 1a3a278..cfbc403 100644 --- a/src/Strategy/GithubStrategy.php +++ b/src/Strategy/GithubStrategy.php @@ -21,7 +21,7 @@ class GithubStrategy implements StrategyInterface { - const API_URL = 'https://packagist.org/packages/%s.json'; + const API_URL = 'https://packagist.org/p/%s.json'; const STABLE = 'stable'; @@ -101,7 +101,7 @@ public function getCurrentRemoteVersion(Updater $updater) ); } - $versions = array_keys($package['package']['versions']); + $versions = array_keys($package['packages'][$this->getPackageName()]); $versionParser = new VersionParser($versions); if ($this->getStability() === self::STABLE) { $this->remoteVersion = $versionParser->getMostRecentStable(); @@ -217,7 +217,7 @@ protected function getDownloadUrl(array $package) $baseUrl = preg_replace( '{\.git$}', '', - $package['package']['versions'][$this->remoteVersion]['source']['url'] + $package['packages'][$this->getPackageName()][$this->remoteVersion]['source']['url'] ); $downloadUrl = sprintf( '%s/releases/download/%s/%s', diff --git a/tests/Humbug/Test/SelfUpdate/UpdaterGithubStrategyTest.php b/tests/Humbug/Test/SelfUpdate/UpdaterGithubStrategyTest.php index b336b40..7265a5f 100644 --- a/tests/Humbug/Test/SelfUpdate/UpdaterGithubStrategyTest.php +++ b/tests/Humbug/Test/SelfUpdate/UpdaterGithubStrategyTest.php @@ -109,7 +109,7 @@ public function testUpdatePhar() $updater = new Updater($this->tmp . '/old.phar'); $updater->setStrategyObject(new GithubTestStrategy); $updater->getStrategy()->setPharName('new.phar'); - $updater->getStrategy()->setPackageName(''); // not used in this test + $updater->getStrategy()->setPackageName('humbug/test-phar'); $updater->getStrategy()->setCurrentLocalVersion('1.0.0'); $this->assertTrue($updater->update()); @@ -132,7 +132,7 @@ private function deleteTempPhars() @unlink($this->tmp . '/releases/download/1.0.1/new.phar'); @unlink($this->tmp . '/releases/download/1.0.1/new.phar.pubkey'); @unlink($this->tmp . '/old.1c7049180abee67826d35ce308c38272242b64b8.phar'); - @unlink($this->tmp . '/package.json'); + @unlink($this->tmp . '/packages.json'); } private function createTestPharAndKey() @@ -145,9 +145,9 @@ private function createTestPharAndKey() ); @mkdir($this->tmp.'/releases/download/1.0.1', 0755, true); copy($this->files.'/build/new.phar', $this->tmp.'/releases/download/1.0.1/new.phar'); - file_put_contents($this->tmp . '/package.json', json_encode(array( - 'package' => array( - 'versions' => array( + file_put_contents($this->tmp . '/packages.json', json_encode(array( + 'packages' => array( + 'humbug/test-phar' => array( '1.0.1' => array( 'source' => array( 'url' => 'file://' . $this->tmp . '.git' @@ -165,6 +165,6 @@ class GithubTestStrategy extends GithubStrategy { protected function getApiUrl() { - return 'file://' . sys_get_temp_dir() . '/package.json'; + return 'file://' . sys_get_temp_dir() . '/packages.json'; } }