Skip to content
This repository was archived by the owner on Mar 15, 2020. It is now read-only.

Commit d01d3b8

Browse files
luckyraultheofidry
authored andcommitted
Add a random string to skip packagist json cache (#57)
1 parent fb9d3b1 commit d01d3b8

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/Strategy/GithubStrategy.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020

2121
class GithubStrategy implements StrategyInterface
2222
{
23-
24-
const API_URL = 'https://packagist.org/packages/%s.json';
23+
const API_URL = 'https://packagist.org/p/%s.json';
2524

2625
const STABLE = 'stable';
2726

@@ -101,7 +100,7 @@ public function getCurrentRemoteVersion(Updater $updater)
101100
);
102101
}
103102

104-
$versions = array_keys($package['package']['versions']);
103+
$versions = array_keys($package['packages'][$this->getPackageName()]);
105104
$versionParser = new VersionParser($versions);
106105
if ($this->getStability() === self::STABLE) {
107106
$this->remoteVersion = $versionParser->getMostRecentStable();
@@ -217,7 +216,7 @@ protected function getDownloadUrl(array $package)
217216
$baseUrl = preg_replace(
218217
'{\.git$}',
219218
'',
220-
$package['package']['versions'][$this->remoteVersion]['source']['url']
219+
$package['packages'][$this->getPackageName()][$this->remoteVersion]['source']['url']
221220
);
222221
$downloadUrl = sprintf(
223222
'%s/releases/download/%s/%s',

tests/Humbug/Test/SelfUpdate/UpdaterGithubStrategyTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function testUpdatePhar()
109109
$updater = new Updater($this->tmp . '/old.phar');
110110
$updater->setStrategyObject(new GithubTestStrategy);
111111
$updater->getStrategy()->setPharName('new.phar');
112-
$updater->getStrategy()->setPackageName(''); // not used in this test
112+
$updater->getStrategy()->setPackageName('humbug/test-phar');
113113
$updater->getStrategy()->setCurrentLocalVersion('1.0.0');
114114

115115
$this->assertTrue($updater->update());
@@ -132,7 +132,7 @@ private function deleteTempPhars()
132132
@unlink($this->tmp . '/releases/download/1.0.1/new.phar');
133133
@unlink($this->tmp . '/releases/download/1.0.1/new.phar.pubkey');
134134
@unlink($this->tmp . '/old.1c7049180abee67826d35ce308c38272242b64b8.phar');
135-
@unlink($this->tmp . '/package.json');
135+
@unlink($this->tmp . '/packages.json');
136136
}
137137

138138
private function createTestPharAndKey()
@@ -145,9 +145,9 @@ private function createTestPharAndKey()
145145
);
146146
@mkdir($this->tmp.'/releases/download/1.0.1', 0755, true);
147147
copy($this->files.'/build/new.phar', $this->tmp.'/releases/download/1.0.1/new.phar');
148-
file_put_contents($this->tmp . '/package.json', json_encode(array(
149-
'package' => array(
150-
'versions' => array(
148+
file_put_contents($this->tmp . '/packages.json', json_encode(array(
149+
'packages' => array(
150+
'humbug/test-phar' => array(
151151
'1.0.1' => array(
152152
'source' => array(
153153
'url' => 'file://' . $this->tmp . '.git'
@@ -165,6 +165,6 @@ class GithubTestStrategy extends GithubStrategy
165165
{
166166
protected function getApiUrl()
167167
{
168-
return 'file://' . sys_get_temp_dir() . '/package.json';
168+
return 'file://' . sys_get_temp_dir() . '/packages.json';
169169
}
170170
}

0 commit comments

Comments
 (0)