Skip to content
Open
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
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
"require": {
"php": ">=8.1",
"ext-json": ">=8.1",
"composer/semver": "3.4.3",
"guzzlehttp/guzzle": "7.9.3",
"composer/semver": "3.4.4",
"guzzlehttp/guzzle": "7.10.0",
"vanilla/garden-cli": "v4.0",
"wp-cli/php-cli-tools": "v0.12.5"
},
"require-dev": {
"phpunit/phpunit": "10.5.44",
"phpunit/phpunit": "10.5.47",
"mockery/mockery": "1.6.12"
},
"autoload": {
Expand Down
158 changes: 81 additions & 77 deletions composer.lock

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions src/Calculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,16 @@ private function updateVersionInfo(Dependency $dependency, array $repositories,
}

/**
* @param array $releases
* @param array $package_data
* @return DateTimeInterface[]
*/
private static function getVersions(array $releases): array
private static function getVersions(array $package_data): array
{
$versions = [];
foreach ($releases as $release) {
$versions[$release['version']] = self::findReleaseDate($release);
if (isset($package_data['versions'])) {
foreach ($package_data['versions'] as $version => $version_data) {
$versions[$version] = self::findReleaseDate($version_data);
}
}
return array_filter($versions);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ComposerFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class ComposerFile
{
const DEFAULT_URL = 'https://repo.packagist.org';
const DEFAULT_URL = 'https://packagist.org';

private FileSystem $file_system;

Expand Down
8 changes: 7 additions & 1 deletion src/RepositoryAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public function getInfo(string $url, bool $verbose): ?Repository
try {
$response = $this->http_client->request('GET', "$url/packages.json");
$result = json_decode($response->getBody()->getContents(), true) ?? [];

// For the new packagist.org, override the deprecated metadata-url
if ($url === 'https://packagist.org') {
return new Repository($url, '/packages/%package%.json');
}

return new Repository($url, array_key_exists('metadata-url', $result) ? $result['metadata-url'] : null);
Comment on lines 28 to 36
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks -- everything else looks good, but I want to think a little more on this part...it feels off, but it's also been years since I've really worked with this app's code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm yeah makes sense. If I find the time I will have a look as well if we need that URL compare at all.

} catch (GuzzleException $e) {
if ($verbose) {
Expand All @@ -42,7 +48,7 @@ public function getPackageInfo(string $package, Repository $repository, bool $ve
$url = $repository->getMetadataURL($package);
$response = $this->http_client->request('GET', $url);
$json = json_decode($response->getBody()->getContents(), true);
return $json['packages'][$package] ?? [];
return $json['package'] ?? [];
} catch (GuzzleException $e) {
if ($verbose) {
fwrite($this->stderr, "Could not find info for $package on $repository->url\n");
Expand Down
16 changes: 9 additions & 7 deletions tests/CalculatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CalculatorTest extends TestCase
public function testCanFillOutDependencyInfo()
{
//arrange
$repository = new Repository('https://repo.packagist.org', '/p2/%package%.json');
$repository = new Repository('https://packagist.org', '/packages/%package%.json');
$dependency = new Dependency('vendor_name/package_name', '1.2.3');
$composer = Mockery::mock(ComposerFile::class, [
'getRepositories' => [$repository->url],
Expand All @@ -30,8 +30,10 @@ public function testCanFillOutDependencyInfo()
$api = Mockery::mock(RepositoryAPI::class, [
'getInfo' => $repository,
'getPackageInfo' => [
['version' => '1.2.3', 'time' => '2018-07-01'],
['version' => '2.3.4', 'extra' => ['drupal' => ['datestamp' => '1577836800']]]
'versions' => [
'1.2.3' => ['time' => '2018-07-01'],
'2.3.4' => ['extra' => ['drupal' => ['datestamp' => '1577836800']]]
]
]
]);
$progress = Mockery::mock(Progress::class, [
Expand Down Expand Up @@ -65,7 +67,7 @@ public function testSkipsFillingOutMissingInfo()
$api = Mockery::mock(RepositoryAPI::class);
$api->shouldReceive('getPackageInfo')->andReturn(
[
['version' => '1.2.4', 'time' => '2018-07-01']
'versions' => ['1.2.4' => ['time' => '2018-07-01']]
],
[
[]
Expand Down Expand Up @@ -101,7 +103,7 @@ public function testSkipsBadRepositories()

$api = Mockery::mock(RepositoryAPI::class, [
'getPackageInfo' => [
['version' => '1.2.4', 'time' => '2018-07-01']
'versions' => ['1.2.4' => ['time' => '2018-07-01']]
]
]);
$repo1 = null;
Expand Down Expand Up @@ -172,7 +174,7 @@ public function testInfoInFirstRepoSkipsSubsequentOnes()
$api = Mockery::mock(RepositoryAPI::class);
$api->shouldReceive('getInfo')->andReturn($repo1, $repo2);
$api->shouldReceive('getPackageInfo')->with($dependency->name, $repo1, false)->andReturn([
['version' => '1.2.4', 'time' => '2018-07-01']
'versions' => ['1.2.4' => ['time' => '2018-07-01']]
]);
$api->shouldNotReceive('getPackageInfo')->with($dependency->name, $repo2);

Expand Down Expand Up @@ -207,7 +209,7 @@ public function testInfoNotInFirstRepoUsesSubsequentOnes()
$api->shouldReceive('getInfo')->andReturn($repo1, $repo2);
$api->shouldReceive('getPackageInfo')->with($dependency->name, $repo1, false)->andReturn([]);
$api->shouldReceive('getPackageInfo')->with($dependency->name, $repo2, false)->andReturn([
['version' => '1.2.4', 'time' => '2018-07-01']
'versions' => ['1.2.4' => ['time' => '2018-07-01']]
]);

$progress = Mockery::mock(Progress::class, [
Expand Down
4 changes: 2 additions & 2 deletions tests/ComposerFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function testCanGetDefaultRepositoryFromComposerFile()
$repositories = $composer->getRepositories('.');

//assert
$this->assertEquals(['https://repo.packagist.org'], $repositories);
$this->assertEquals(['https://packagist.org'], $repositories);
}

public function testCachesFileSystemResponses()
Expand Down Expand Up @@ -88,7 +88,7 @@ public function testCanGetCustomRepositoryFromComposerFile()
$expected = [
'https://composer.example.com',
'https://composer.example.org',
'https://repo.packagist.org'
'https://packagist.org'
];
$this->assertEquals($expected, $repositories);
}
Expand Down
22 changes: 9 additions & 13 deletions tests/RepositoryAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,13 @@ public function testRepositoryDisplaysErrorInVerboseMode()
public function testGetPackageInfoCallsCorrectURL()
{
//arrange
$repo = new Repository('https://repo.packagist.org', '/packages/%package%.json');
$repo = new Repository('https://packagist.org', '/packages/%package%.json');
$http_client = Mockery::mock(ClientInterface::class, [
'request' => Mockery::mock(ResponseInterface::class, [
'getStatusCode' => 200,
'getBody' => Mockery::mock(StreamInterface::class, [
'getContents' => json_encode([
'packages' => [
'vendor_name/package_name' => []
]
'package' => []
])
])
])
Expand All @@ -128,22 +126,20 @@ public function testGetPackageInfoCallsCorrectURL()

//assert
$http_client->shouldHaveReceived('request')
->with('GET', 'https://repo.packagist.org/packages/vendor_name/package_name.json');
->with('GET', 'https://packagist.org/packages/vendor_name/package_name.json');
}

public function testCanGetPackageInfo()
{
//arrange
$repo = new Repository('https://repo.packagist.org', '/packages/%package%.json');
$repo = new Repository('https://packagist.org', '/packages/%package%.json');
$http_client = Mockery::mock(ClientInterface::class, [
'request' => Mockery::mock(ResponseInterface::class, [
'getStatusCode' => 200,
'getBody' => Mockery::mock(StreamInterface::class, [
'getContents' => json_encode([
'packages' => [
'vendor_name/package_name' => [
'test_field' => 'test value'
]
'package' => [
'test_field' => 'test value'
]
])
])
Expand All @@ -163,7 +159,7 @@ public function testCanGetPackageInfo()
public function testGetPackageInfoCanHandleBadResponse()
{
//arrange
$repo = new Repository('https://repo.packagist.org', '/packages/%package%.json');
$repo = new Repository('https://packagist.org', '/packages/%package%.json');
$http_client = Mockery::mock(ClientInterface::class, [
'request' => Mockery::mock(ResponseInterface::class, [
'getStatusCode' => 200,
Expand All @@ -186,7 +182,7 @@ public function testGetPackageInfoCanHandleBadResponse()
public function testPackageInfoIsEmptyOnException()
{
//arrange
$repo = new Repository('https://repo.packagist.org', '/packages/%package%.json');
$repo = new Repository('https://packagist.org', '/packages/%package%.json');
$http_client = Mockery::mock(ClientInterface::class);
$http_client->shouldReceive('request')->andThrow(new ConnectException('', new Request('GET', '')));

Expand All @@ -207,7 +203,7 @@ public function testPackageInfoIsEmptyOnException()
public function testPackageInfoDisplaysErrorInVerboseMode()
{
//arrange
$repo = new Repository('https://repo.packagist.org', '/packages/%package%.json');
$repo = new Repository('https://packagist.org', '/packages/%package%.json');
$http_client = Mockery::mock(ClientInterface::class);
$http_client->shouldReceive('request')->andThrow(new ConnectException('', new Request('GET', '')));

Expand Down