From a4645bb340c7086a32bf4b66976afb58d841edfe Mon Sep 17 00:00:00 2001 From: Ciaran McNulty Date: Thu, 5 Jan 2023 17:27:07 +0000 Subject: [PATCH 1/3] Look in local folder for CCK samples and fail if not present --- php/phpunit.xml | 7 +++++-- php/tests/{AcceptanceTest.php => CckTest.php} | 11 +++++++++-- php/tests/cck-samples/.gitignore | 1 + php/tests/{ => unit}/EnvelopeTest.php | 2 ++ php/tests/{ => unit}/Id/IdGeneratorTestTrait.php | 4 +++- .../{ => unit}/Id/IncrementingIdGeneratorTest.php | 3 ++- php/tests/{ => unit}/Id/UuidIdGeneratorTest.php | 3 ++- php/tests/{ => unit}/JsonDecodingTraitTest.php | 0 8 files changed, 24 insertions(+), 7 deletions(-) rename php/tests/{AcceptanceTest.php => CckTest.php} (87%) create mode 100644 php/tests/cck-samples/.gitignore rename php/tests/{ => unit}/EnvelopeTest.php (96%) rename php/tests/{ => unit}/Id/IdGeneratorTestTrait.php (84%) rename php/tests/{ => unit}/Id/IncrementingIdGeneratorTest.php (86%) rename php/tests/{ => unit}/Id/UuidIdGeneratorTest.php (90%) rename php/tests/{ => unit}/JsonDecodingTraitTest.php (100%) diff --git a/php/phpunit.xml b/php/phpunit.xml index fd5e5582..ea739e52 100644 --- a/php/phpunit.xml +++ b/php/phpunit.xml @@ -12,8 +12,11 @@ failOnWarning="true" verbose="true"> - - tests + + tests/unit + + + tests/CckTest.php diff --git a/php/tests/AcceptanceTest.php b/php/tests/CckTest.php similarity index 87% rename from php/tests/AcceptanceTest.php rename to php/tests/CckTest.php index a3ce4ca4..11c84d43 100644 --- a/php/tests/AcceptanceTest.php +++ b/php/tests/CckTest.php @@ -5,7 +5,7 @@ use Cucumber\Messages\Streams\NdJson\NdJsonStreamWriter; use PHPUnit\Framework\TestCase; -class AcceptanceTest extends TestCase +class CckTest extends TestCase { /** @dataProvider provideJsonLines */ public function testAllNdJsonSurvivesDecodingThenEncoding(string $json): void @@ -74,6 +74,13 @@ public function provideNdJsonFilenames(): Generator */ private function getSampleFiles(): array { - return glob(__DIR__ . '/../../../node_modules/@cucumber/compatibility-kit/features/**/*.ndjson') ?: []; + $files = glob(pattern:__DIR__ . '/cck-samples/**/*.ndjson'); + + // glob doesn't error if dir is empty + if ($files === []) { + throw new Exception('CCK sample files not found. Perhaps you want to run the "unit" testsuite?'); + } + + return $files; } } diff --git a/php/tests/cck-samples/.gitignore b/php/tests/cck-samples/.gitignore new file mode 100644 index 00000000..72e8ffc0 --- /dev/null +++ b/php/tests/cck-samples/.gitignore @@ -0,0 +1 @@ +* diff --git a/php/tests/EnvelopeTest.php b/php/tests/unit/EnvelopeTest.php similarity index 96% rename from php/tests/EnvelopeTest.php rename to php/tests/unit/EnvelopeTest.php index a47922e6..211210a4 100644 --- a/php/tests/EnvelopeTest.php +++ b/php/tests/unit/EnvelopeTest.php @@ -1,5 +1,7 @@ Date: Fri, 6 Jan 2023 10:33:59 +0000 Subject: [PATCH 2/3] Ensure CCK is downloaded during docker builds --- docker-bake.hcl | 2 ++ php/Dockerfile | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/docker-bake.hcl b/docker-bake.hcl index a5600dc0..a345b98a 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -112,6 +112,8 @@ target "php-test" { context = "php" target = "tested" contexts = { + # replaces the stage that does `git clone` and ensures we get a fresh version + cck = "https://github.com/cucumber/compatibility-kit.git#main:devkit", schema-codegen = "target:php-codegen", } } diff --git a/php/Dockerfile b/php/Dockerfile index d3ceee5d..67af39bb 100644 --- a/php/Dockerfile +++ b/php/Dockerfile @@ -9,6 +9,15 @@ WORKDIR /cucumber FROM scratch AS schema-codegen +# Stage to download the CCK data, overridden in main build but included here in case building in the subfolder +# NB - when buildkit 1.5 is released this can be replaced with an ADD from the git URL +FROM bitnami/git AS cck +RUN git clone https://github.com/cucumber/compatibility-kit.git \ + && cd compatibility-kit \ + && git checkout main \ + && cp -R ./devkit/samples /samples + + FROM php AS with-dependencies COPY --link composer.json . @@ -23,6 +32,7 @@ FROM php AS tested COPY --link . . COPY --link --from=with-dependencies /cucumber/vendor vendor COPY --link --from=schema-codegen / src-generated +COPY --link --from=cck /samples/ ./tests/cck-samples RUN vendor/bin/php-cs-fixer --dry-run --diff fix RUN vendor/bin/psalm --no-cache RUN vendor/bin/phpunit From ca4129396cbeac2903a24bc35f1644466ed176b9 Mon Sep 17 00:00:00 2001 From: Ciaran McNulty Date: Fri, 6 Jan 2023 10:58:29 +0000 Subject: [PATCH 3/3] Fix namespaces and autoloading --- php/composer.json | 3 ++- php/tests/CckTest.php | 5 ++++- php/tests/unit/EnvelopeTest.php | 6 +----- php/tests/unit/Id/IdGeneratorTestTrait.php | 4 +--- php/tests/unit/Id/IncrementingIdGeneratorTest.php | 3 +-- php/tests/unit/Id/UuidIdGeneratorTest.php | 3 +-- php/tests/unit/JsonDecodingTraitTest.php | 5 ++++- 7 files changed, 14 insertions(+), 15 deletions(-) diff --git a/php/composer.json b/php/composer.json index 8349570d..cda2780f 100644 --- a/php/composer.json +++ b/php/composer.json @@ -28,7 +28,8 @@ "Cucumber\\Messages\\": [ "src", "src-generated", - "tests" + "tests", + "tests/unit" ] } } diff --git a/php/tests/CckTest.php b/php/tests/CckTest.php index 11c84d43..151af1c7 100644 --- a/php/tests/CckTest.php +++ b/php/tests/CckTest.php @@ -1,8 +1,11 @@