-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e32eac
commit 4936d41
Showing
7 changed files
with
209 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
ci: | ||
name: CI | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e # v2.4.2 | ||
|
||
- name: Install PHP | ||
uses: shivammathur/setup-php@3eda58347216592f618bb1dff277810b6698e4ca # v2.19.1 | ||
with: | ||
php-version: 8.1 | ||
extensions: yaml | ||
|
||
- name: Install PHPUnit | ||
run: wget https://phar.phpunit.de/phpunit-9.5.phar | ||
|
||
- name: PHPUnit | ||
run: php phpunit-9.5.phar --verbose --colors=always |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="tests/bootstrap.php" colors="true"> | ||
<testsuites> | ||
<testsuite name="Default"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<?php | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class JobCreatorTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider provideGetInstallerVersion | ||
*/ | ||
public function testGetInstallerVersion( | ||
string $githubRepository, | ||
string $branch, | ||
string $expected | ||
): void { | ||
$creator = new JobCreator(); | ||
$actual = $creator->getInstallerVersion($githubRepository, $branch); | ||
$this->assertSame($expected, $actual); | ||
} | ||
|
||
public function provideGetInstallerVersion(): array | ||
{ | ||
return [ | ||
// no-installer repo | ||
['myaccount/recipe-cms', '4', ''], | ||
['myaccount/recipe-cms', '4.10', ''], | ||
['myaccount/recipe-cms', 'burger', ''], | ||
['myaccount/recipe-cms', 'pulls/4/myfeature', ''], | ||
['myaccount/recipe-cms', 'pulls/4.10/myfeature', ''], | ||
['myaccount/recipe-cms', 'pulls/burger/myfeature', ''], | ||
// lockstepped repo with 4.* naming | ||
['myaccount/silverstripe-framework', '4', '4.x-dev'], | ||
['myaccount/silverstripe-framework', '4.10', '4.10.x-dev'], | ||
['myaccount/silverstripe-framework', 'burger', '4.11.x-dev'], | ||
['myaccount/silverstripe-framework', 'pulls/4/mybugfix', '4.x-dev'], | ||
['myaccount/silverstripe-framework', 'pulls/4.10/mybugfix', '4.10.x-dev'], | ||
['myaccount/silverstripe-framework', 'pulls/burger/myfeature', '4.11.x-dev'], | ||
// lockstepped repo with 1.* naming | ||
['myaccount/silverstripe-admin', '1', '4.x-dev'], | ||
['myaccount/silverstripe-admin', '1.10', '4.10.x-dev'], | ||
['myaccount/silverstripe-admin', 'burger', '4.11.x-dev'], | ||
['myaccount/silverstripe-admin', 'pulls/1/mybugfix', '4.x-dev'], | ||
['myaccount/silverstripe-admin', 'pulls/1.10/mybugfix', '4.10.x-dev'], | ||
['myaccount/silverstripe-admin', 'pulls/burger/myfeature', '4.11.x-dev'], | ||
// non-lockedstepped repo | ||
['myaccount/silverstripe-tagfield', '2', '4.11.x-dev'], | ||
['myaccount/silverstripe-tagfield', '2.9', '4.11.x-dev'], | ||
['myaccount/silverstripe-tagfield', 'burger', '4.11.x-dev'], | ||
['myaccount/silverstripe-tagfield', 'pulls/2/mybugfix', '4.11.x-dev'], | ||
['myaccount/silverstripe-tagfield', 'pulls/2.9/mybugfix', '4.11.x-dev'], | ||
['myaccount/silverstripe-tagfield', 'pulls/burger/myfeature', '4.11.x-dev'], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider provideGetInputsValid | ||
*/ | ||
public function testGetInputsValid(string $yml, array $expected) | ||
{ | ||
if (!function_exists('yaml_parse')) { | ||
$this->markTestSkipped('yaml extension is not installed'); | ||
} | ||
$creator = new JobCreator(); | ||
$actual = $creator->getInputs($yml); | ||
$this->assertSame($expected, $actual); | ||
} | ||
|
||
public function provideGetInputsValid(): array | ||
{ | ||
return [ | ||
[ | ||
<<<EOT | ||
endtoend: true | ||
js: true | ||
phpcoverage: false | ||
phpcoverage_force_off: false | ||
phplinting: true | ||
phpunit: true | ||
simple_matrix: false | ||
github_repository: 'myaccount/silverstripe-versioned' | ||
github_my_ref: 'pulls/1.10/module-standards' | ||
EOT, | ||
[ | ||
'endtoend' => true, | ||
'js' => true, | ||
'phpcoverage' => false, | ||
'phpcoverage_force_off' => false, | ||
'phplinting' => true, | ||
'phpunit' => true, | ||
'simple_matrix' => false, | ||
'github_repository' => 'myaccount/silverstripe-versioned', | ||
'github_my_ref'=> 'pulls/1.10/module-standards' | ||
] | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider provideGetInputsInvalid | ||
*/ | ||
public function testGetInputsInvalid(string $yml, string $expectedMessage) | ||
{ | ||
if (!function_exists('yaml_parse')) { | ||
$this->markTestSkipped('yaml extension is not installed'); | ||
} | ||
$this->expectException(Exception::class); | ||
$this->expectExceptionMessage($expectedMessage); | ||
$creator = new JobCreator(); | ||
$creator->getInputs($yml); | ||
} | ||
|
||
public function provideGetInputsInvalid(): array | ||
{ | ||
return [ | ||
// missing quotes around github_my_ref (would turn into an in, so 1.10 becomes 1.1) | ||
[ | ||
<<<EOT | ||
github_my_ref: 1.10 | ||
EOT, | ||
'github_my_ref needs to be surronded by single-quotes' | ||
], | ||
// invalid yml | ||
[ | ||
<<<EOT | ||
this: -- | ||
is: - total: ' nonsense | ||
" | ||
EOT, | ||
'Failed to parse yml' | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php | ||
// working directory will be root | ||
include 'consts.php'; | ||
include 'job_creator.php'; |