Skip to content

Commit 4160403

Browse files
authored
Merge pull request #285 from asgrim/flaky-tests-issue
Fix flakey tests caused by not using GH token correctly in CI
2 parents 411f5ad + 98409a4 commit 4160403

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ jobs:
3131
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3232
- uses: actions/checkout@v4
3333
- uses: ramsey/composer-install@v3
34+
- name: GH token
35+
if: matrix.operating-system != 'windows-latest'
36+
run: sudo composer config --global --auth github-oauth.github.com ${{ secrets.GITHUB_TOKEN }}
3437
- name: Run PHPUnit on Windows
3538
if: matrix.operating-system == 'windows-latest'
3639
run: vendor/bin/phpunit

src/Container.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Php\Pie;
66

7-
use Composer\Util\Platform;
7+
use Composer\Util\Platform as ComposerPlatform;
88
use Illuminate\Container\Container as IlluminateContainer;
99
use Php\Pie\Building\Build;
1010
use Php\Pie\Building\UnixBuild;
@@ -44,17 +44,39 @@
4444
use Symfony\Component\Console\Output\OutputInterface;
4545
use Symfony\Component\EventDispatcher\EventDispatcher;
4646

47+
use function defined;
48+
use function fopen;
4749
use function getcwd;
4850
use function str_starts_with;
4951

52+
use const STDIN;
53+
5054
/** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */
5155
final class Container
5256
{
5357
public static function factory(): ContainerInterface
5458
{
5559
$container = new IlluminateContainer();
5660
$container->instance(ContainerInterface::class, $container);
57-
$container->instance(InputInterface::class, new ArgvInput());
61+
$container->singleton(
62+
InputInterface::class,
63+
static function () {
64+
$input = new ArgvInput();
65+
66+
$stdin = defined('STDIN') ? STDIN : fopen('php://stdin', 'r');
67+
$noInteractionEnv = ComposerPlatform::getEnv('COMPOSER_NO_INTERACTION');
68+
if (
69+
$noInteractionEnv === false
70+
|| $noInteractionEnv === '1'
71+
|| $stdin === false
72+
|| ! ComposerPlatform::isTty($stdin)
73+
) {
74+
$input->setInteractive(false);
75+
}
76+
77+
return $input;
78+
},
79+
);
5880
$container->instance(OutputInterface::class, new ConsoleOutput());
5981
$container->singleton(EventDispatcher::class, static function () {
6082
$displayedBanner = false;
@@ -124,7 +146,7 @@ static function (ConsoleCommandEvent $event) use (&$displayedBanner): void {
124146
$container->singleton(
125147
Build::class,
126148
static function (ContainerInterface $container): Build {
127-
if (Platform::isWindows()) {
149+
if (ComposerPlatform::isWindows()) {
128150
return $container->get(WindowsBuild::class);
129151
}
130152

@@ -148,7 +170,7 @@ static function (ContainerInterface $container): Ini\SetupIniApproach {
148170
$container->singleton(
149171
Install::class,
150172
static function (ContainerInterface $container): Install {
151-
if (Platform::isWindows()) {
173+
if (ComposerPlatform::isWindows()) {
152174
return $container->get(WindowsInstall::class);
153175
}
154176

test/integration/DependencyResolver/ResolveDependencyWithComposerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static function validVersionsList(): array
4242
['dev-main#769f906413d6d1e12152f6d34134cbcd347ca253', 'dev-main', self::DOWNLOAD_URL_1_0_1],
4343
];
4444

45-
if (PHP_VERSION_ID >= 80300 && PHP_VERSION_ID <= 80300) {
45+
if (PHP_VERSION_ID >= 80300 && PHP_VERSION_ID <= 80399) {
4646
$versionsAndExpected[] = ['1.0.1-alpha.3@alpha', '1.0.1-alpha.3', self::DOWNLOAD_URL_1_0_1_ALPHA_3];
4747
$versionsAndExpected[] = ['^1.0', '1.0.1', self::DOWNLOAD_URL_1_0_1];
4848
$versionsAndExpected[] = ['^1.1.0@alpha', '1.1.0-beta.1', self::DOWNLOAD_URL_1_1_0_BETA_1];

test/integration/Downloading/GithubPackageReleaseAssetsTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Php\Pie\Platform\WindowsCompiler;
2323
use Php\Pie\Platform\WindowsExtensionAssetName;
2424
use PHPUnit\Framework\Attributes\CoversClass;
25+
use PHPUnit\Framework\Attributes\RequiresOperatingSystemFamily;
2526
use PHPUnit\Framework\TestCase;
2627

2728
use function getenv;
@@ -30,6 +31,7 @@
3031
#[CoversClass(GithubPackageReleaseAssets::class)]
3132
final class GithubPackageReleaseAssetsTest extends TestCase
3233
{
34+
#[RequiresOperatingSystemFamily('Windows')]
3335
public function testDeterminingReleaseAssetUrlForWindows(): void
3436
{
3537
$phpBinaryPath = $this->createMock(PhpBinaryPath::class);

0 commit comments

Comments
 (0)