Skip to content

Commit

Permalink
ENH Require graphql3 for the first endtoend test
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Aug 3, 2022
1 parent c39ccc2 commit 89356a9
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 14 deletions.
4 changes: 3 additions & 1 deletion job_creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
76 changes: 63 additions & 13 deletions tests/JobCreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
<<<EOT
github_repository: 'silverstripe/recipe-cms'
github_my_ref: '$githubMyRef'
simple_matrix: $simpleMatrix
EOT
]);
try {
// create a temporary fake behat.yml file so that the dynamic matrix include endtoend jobs
file_put_contents('behat.yml', '');
$creator = new JobCreator();
$json = json_decode($creator->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]],
];
}
}

0 comments on commit 89356a9

Please sign in to comment.