Skip to content

Commit

Permalink
Ensure GithubPackageReleaseAssetsTest integration test uses GH token …
Browse files Browse the repository at this point in the history
…for API call
  • Loading branch information
asgrim committed Jan 3, 2025
1 parent 2a191c2 commit 7a21166
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v4
- run: composer config --global github-oauth.github.com ${{ secrets.GITHUB_TOKEN }}
# temporarily remove Psalm until ready for PHP 8.4
- name: remove psalm
if: matrix.php-versions == '8.4'
Expand Down
6 changes: 4 additions & 2 deletions src/Downloading/GithubPackageReleaseAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private function getReleaseAssetsForPackage(
Assert::notNull($package->downloadUrl);

try {
$decodedRepsonse = $httpDownloader->get(
$r = $httpDownloader->get(
$this->githubApiBaseUrl . '/repos/' . $package->githubOrgAndRepository() . '/releases/tags/' . $package->version,
[
'retry-auth-failure' => false,
Expand All @@ -86,7 +86,9 @@ private function getReleaseAssetsForPackage(
'header' => $authHelper->addAuthenticationHeader([], $this->githubApiBaseUrl, $package->downloadUrl),
],
],
)->decodeJson();
);
var_dump($r->getHeaders());

Check failure on line 90 in src/Downloading/GithubPackageReleaseAssets.php

View workflow job for this annotation

GitHub Actions / static-analysis

ForbiddenCode

src/Downloading/GithubPackageReleaseAssets.php:90:13: ForbiddenCode: Unsafe var_dump (see https://psalm.dev/002)
$decodedRepsonse = $r->decodeJson();
} catch (TransportException $t) {
/** @link https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#get-a-release-by-tag-name */
if ($t->getStatusCode() === 404) {
Expand Down
10 changes: 9 additions & 1 deletion test/integration/Downloading/GithubPackageReleaseAssetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Php\PieIntegrationTest\Downloading;

use Composer\Config;
use Composer\Factory;
use Composer\IO\BufferIO;
use Composer\IO\IOInterface;
use Composer\Package\CompletePackage;
use Composer\Util\AuthHelper;
Expand Down Expand Up @@ -59,7 +61,13 @@ public function testDeterminingReleaseAssetUrlForWindows(): void
99,
);

$io = $this->createMock(IOInterface::class);
$io = $this->createMock(IOInterface::class);
if (getenv('GITHUB_TOKEN')) {

Check failure on line 65 in test/integration/Downloading/GithubPackageReleaseAssetsTest.php

View workflow job for this annotation

GitHub Actions / static-analysis

RiskyTruthyFalsyComparison

test/integration/Downloading/GithubPackageReleaseAssetsTest.php:65:13: RiskyTruthyFalsyComparison: Operand of type false|string contains type string, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (see https://psalm.dev/356)
$io->method('hasAuthentication')
->willReturn(true);
$io->method('getAuthentication')
->willReturn(['username' => getenv('GITHUB_TOKEN'), 'password' => 'x-oauth-basic']);
}
$config = new Config();

self::assertSame(
Expand Down

0 comments on commit 7a21166

Please sign in to comment.