From 89356a907ebf0ac56aaa172c8235d8a6b024e026 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 3 Aug 2022 15:52:10 +1200 Subject: [PATCH] ENH Require graphql3 for the first endtoend test --- job_creator.php | 4 ++- tests/JobCreatorTest.php | 76 +++++++++++++++++++++++++++++++++------- 2 files changed, 66 insertions(+), 14 deletions(-) diff --git a/job_creator.php b/job_creator.php index 09b1358..991f4fb 100644 --- a/job_creator.php +++ b/job_creator.php @@ -344,9 +344,11 @@ private function buildDynamicMatrix( } // endtoend / behat if ($run['endtoend'] && file_exists('behat.yml')) { + $graphql3 = !$simpleMatrix && $this->getCmsMajorFromBranch() == '4'; $job = $this->createJob(0, [ 'endtoend' => true, - 'endtoend_suite' => 'root' + 'endtoend_suite' => 'root', + 'composer_require_extra' => $graphql3 ? 'silverstripe/graphql:^3' : '' ]); // use minimum version of 7.4 for endtoend because was having apt dependency issues // in CI when using php 7.3: diff --git a/tests/JobCreatorTest.php b/tests/JobCreatorTest.php index 0a9b308..45cc6e2 100644 --- a/tests/JobCreatorTest.php +++ b/tests/JobCreatorTest.php @@ -414,20 +414,23 @@ public function testGetPhpVersion($composerPhpConstraint, $expectedPhps): void github_my_ref: '$minorVersion' EOT ]); - $creator = new JobCreator(); - $creator->composerJsonPath = '__composer.json'; - $composer = new stdClass(); - $composer->require = new stdClass(); - if ($composerPhpConstraint) { - $composer->require->php = $composerPhpConstraint; - } - file_put_contents('__composer.json', json_encode($composer, JSON_PRETTY_PRINT + JSON_UNESCAPED_SLASHES)); - $json = json_decode($creator->createJson($yml)); - foreach ($json->include as $i => $job) { - $expectedPhp = $expectedPhps[$i]; - $this->assertSame($expectedPhp, $job->php); + try { + $creator = new JobCreator(); + $creator->composerJsonPath = '__composer.json'; + $composer = new stdClass(); + $composer->require = new stdClass(); + if ($composerPhpConstraint) { + $composer->require->php = $composerPhpConstraint; + } + file_put_contents('__composer.json', json_encode($composer, JSON_PRETTY_PRINT + JSON_UNESCAPED_SLASHES)); + $json = json_decode($creator->createJson($yml)); + foreach ($json->include as $i => $job) { + $expectedPhp = $expectedPhps[$i]; + $this->assertSame($expectedPhp, $job->php); + } + } finally { + unlink('__composer.json'); } - unlink('__composer.json'); } public function provideGetPhpVersion(): array @@ -517,4 +520,51 @@ public function provideGitHubMyRefTags(): array ['4.10.6', '4.10.x-dev'], ]; } + + /** + * @dataProvider provideGraphql3 + */ + public function testGraphql3(string $simpleMatrix, string $githubMyRef, array $jobsRequiresGraphql3): void + { + if (!function_exists('yaml_parse')) { + $this->markTestSkipped('yaml extension is not installed'); + } + $yml = implode("\n", [ + $this->getGenericYml(), + // using silverstripe/recipe-cms because it there is currently support it for getting the + // major version of installer set based on github_my_ref + <<createJson($yml)); + $j = 0; + foreach ($json->include as $job) { + if ($job->endtoend == 'false') { + continue; + } + $b = !$jobsRequiresGraphql3[$j]; + $this->assertTrue(strpos($job->composer_require_extra, 'silverstripe/graphql:^3') !== $b); + $j++; + } + } finally { + unlink('behat.yml'); + } + } + + public function provideGraphql3(): array + { + return [ + ['false', '4.11', [true, false]], + ['true', '4.11', [false]], + ['false', '5.0', [false, false]], + ['true', '5.0', [false]], + ]; + } }