-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #372 from Automattic/add/e2e-latest-release
Add initial E2E test for latest-release.php
- Loading branch information
Showing
5 changed files
with
167 additions
and
6 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
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 |
---|---|---|
|
@@ -118,6 +118,41 @@ jobs: | |
run: | | ||
rm -f tests/config-secrets.ini | ||
e2e-testing: | ||
name: Run E2E tests (PHP ${{ matrix.php }}) | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
php: | ||
- '8.0' | ||
- '8.1' | ||
- '8.2' | ||
steps: | ||
- name: Check out the source code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Ask git to fetch latest branch and other branches | ||
run: git fetch origin latest && git pull | ||
|
||
- name: Set up PHP | ||
uses: shivammathur/[email protected] | ||
with: | ||
coverage: none | ||
php-version: "${{ matrix.php }}" | ||
tools: phpunit:9 | ||
env: | ||
fail-fast: 'true' | ||
|
||
- name: Configure PHPUnit | ||
run: sed "s:PROJECT_DIR:$(pwd):g" phpunit.xml.dist > phpunit.xml | ||
|
||
- name: Run E2E tests | ||
run: phpunit --testsuite=e2e-tests | ||
env: | ||
VIPGOCI_TESTING_DEBUG_MODE: 'true' | ||
|
||
|
||
php-code-compatibility: | ||
name: PHP code compatibility (8.2) | ||
runs-on: ubuntu-latest | ||
|
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,115 @@ | ||
<?php | ||
/** | ||
* Verify that latest-release.php behaves as it should. | ||
* | ||
* @package Automattic/vip-go-ci | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Vipgoci\Tests\E2E; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Class that implements the testing. | ||
* | ||
* @runTestsInSeparateProcesses | ||
* @preserveGlobalState disabled | ||
*/ | ||
final class LatestReleaseTest extends TestCase { | ||
/** | ||
* Temporary file for contents of defines.php. | ||
* | ||
* @var $temp_file_name | ||
*/ | ||
private mixed $temp_file_name = ''; | ||
|
||
/** | ||
* Setup function. Require files, etc. | ||
* | ||
* @return void | ||
*/ | ||
protected function setUp() :void { | ||
$this->temp_file_name = tempnam( | ||
sys_get_temp_dir(), | ||
'vipgoci-defines-php-file' | ||
); | ||
} | ||
|
||
/** | ||
* Clean up. | ||
* | ||
* @return void | ||
*/ | ||
protected function tearDown() :void { | ||
if ( false !== $this->temp_file_name ) { | ||
unlink( $this->temp_file_name ); | ||
} | ||
} | ||
|
||
/** | ||
* Verify that return value from the script matches | ||
* real version number. Also verify that the format | ||
* is correct. | ||
* | ||
* @return void | ||
*/ | ||
public function testResults(): void { | ||
// phpcs:disable WordPress.PHP.DiscouragedPHPFunctions.system_calls_exec | ||
if ( false === $this->temp_file_name ) { | ||
$this->markTestSkipped( | ||
'Unable to create temporary file' | ||
); | ||
|
||
return; | ||
} | ||
|
||
/* | ||
* Get 'defines.php' from latest branch, | ||
* put contents of the file into temporary file | ||
* and then retrieve the version number | ||
* by including the file. | ||
*/ | ||
exec( 'git -C . show latest:defines.php > ' . $this->temp_file_name ); | ||
|
||
require_once $this->temp_file_name; | ||
|
||
$correct_version_number = VIPGOCI_VERSION; | ||
|
||
/* | ||
* Run latest-release.php to get latest version number. | ||
*/ | ||
$returned_version_number = exec( 'php latest-release.php' ); | ||
|
||
/* | ||
* Verify format of version number is correct. | ||
*/ | ||
$version_number_preg = '/^(\d+\.)?(\d+\.)?(\*|\d+)$/'; | ||
|
||
$this->assertSame( | ||
1, | ||
preg_match( | ||
$version_number_preg, | ||
$correct_version_number | ||
) | ||
); | ||
|
||
$this->assertSame( | ||
1, | ||
preg_match( | ||
$version_number_preg, | ||
$returned_version_number | ||
) | ||
); | ||
|
||
/* | ||
* Verify both version numbers match. | ||
*/ | ||
$this->assertSame( | ||
$correct_version_number, | ||
$returned_version_number | ||
); | ||
// phpcs:enable WordPress.PHP.DiscouragedPHPFunctions.system_calls_exec | ||
} | ||
} |