Skip to content

Commit

Permalink
test: Add a test for the min PHP version (#890)
Browse files Browse the repository at this point in the history
The autoload modified by PHP-Scoper should be compatible with PHP 7.2.
  • Loading branch information
theofidry authored Nov 4, 2023
1 parent cbef87b commit 83a0211
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .github/workflows/e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ jobs:
composer:
- 'composer:2.2'
- 'composer'
include:
- e2e: 'e2e_039'
php: '8.1'
composer: 'composer:2.2'

steps:
- name: Checkout
Expand Down
26 changes: 26 additions & 0 deletions .makefile/e2e.file
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,32 @@ _e2e_038:
@# To keep in sync with .github/workflows/e2e-tests.yaml#test-phpunit-scoping
cd $(E2E_PHPUNIT_DIR); XDEBUG_MODE=coverage ant run-phar-specific-tests

.PHONY: e2e_039
e2e_039: # Runs end-to-end tests for the fixture set e2e_037 — Codebase using scoped code
e2e_039: $(PHP_SCOPER_PHAR_BIN)
rm -rf fixtures/set039-min-php-version/vendor || true

composer --working-dir=fixtures/set039-min-php-version install

$(PHP_SCOPER_PHAR) add-prefix . \
--working-dir=fixtures/set039-min-php-version \
--output-dir=../../build/set039 \
--force \
--no-interaction \
--stop-on-failure
composer --working-dir=build/set039 dump-autoload

docker run \
--interactive \
--platform=linux/amd64 \
--rm \
--workdir=/opt/php-scoper \
--volume="$$PWD":/opt/php-scoper \
php:7.2-cli-alpine \
php build/set039/index.php \
> build/set039/output
diff fixtures/set039-min-php-version/expected-output build/set039/output


#
# Rules from files
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ e2e: e2e_004 \
e2e_035 \
e2e_036 \
e2e_037 \
e2e_038
e2e_038 \
e2e_039

.PHONY: blackfire
blackfire: ## Runs Blackfire profiling
Expand Down
2 changes: 2 additions & 0 deletions fixtures/set039-min-php-version/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
18 changes: 18 additions & 0 deletions fixtures/set039-min-php-version/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions fixtures/set039-min-php-version/expected-output
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OK
11 changes: 11 additions & 0 deletions fixtures/set039-min-php-version/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App;

require file_exists(__DIR__.'/vendor/scoper-autoload.php')
? __DIR__.'/vendor/scoper-autoload.php'
: __DIR__.'/vendor/autoload.php';

class Greeter {}

echo "OK\n";
26 changes: 26 additions & 0 deletions fixtures/set039-min-php-version/scoper.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

use Isolated\Symfony\Component\Finder\Finder;

// You can do your own things here, e.g. collecting symbols to expose dynamically
// or files to exclude.
// However beware that this file is executed by PHP-Scoper, hence if you are using
// the PHAR it will be loaded by the PHAR. So it is highly recommended to avoid
// to auto-load any code here: it can result in a conflict or even corrupt
// the PHP-Scoper analysis.

// Example of collecting files to include in the scoped build but to not scope
// leveraging the isolated finder.
$excludedFiles = array_map(
static fn (SplFileInfo $fileInfo) => $fileInfo->getPathName(),
iterator_to_array(
Finder::create()->files()->in(__DIR__),
false,
),
);

return [
'expose-classes' => ['App\Greeter'],
];
1 change: 1 addition & 0 deletions tests/AutoReview/GAE2ETest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class GAE2ETest extends TestCase
{
private const IGNORED_E2E_TESTS = [
'e2e_038',
'e2e_039',
];

public function test_github_actions_executes_all_the_e2e_tests(): void
Expand Down

0 comments on commit 83a0211

Please sign in to comment.