Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: cucumber/messages-php
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v22.0.0
Choose a base ref
...
head repository: cucumber/messages-php
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v23.0.0
Choose a head ref
  • 1 commit
  • 5 files changed
  • 2 contributors

Commits on Aug 13, 2023

  1. chore(deps): update dependency phpunit/phpunit to v10 (#138)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    Co-authored-by: M.P. Korstanje <rien.korstanje@gmail.com>
    renovate[bot] and mpkorstanje authored Aug 13, 2023
    Copy the full SHA
    d402f2f View commit details
Showing with 50 additions and 27 deletions.
  1. +2 −2 composer.json
  2. +8 −13 phpunit.xml
  3. +2 −0 src/JsonEncodingTrait.php
  4. +26 −12 tests/AcceptanceTest.php
  5. +12 −0 tests/Samples/minimal.feature.ndjson
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -9,8 +9,8 @@
"ext-json": "*"
},
"require-dev": {
"vimeo/psalm": "^5.0",
"phpunit/phpunit": "^9.5",
"vimeo/psalm": "^5.5",
"phpunit/phpunit": "^10.3",
"psalm/plugin-phpunit": "^0.18.0",
"friendsofphp/php-cs-fixer": "^3.5",
"ramsey/uuid": "^4.5.0"
21 changes: 8 additions & 13 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
convertDeprecationsToExceptions="true"
failOnRisky="true"
failOnWarning="true"
verbose="true">
failOnRisky="true" failOnWarning="true"
cacheDirectory=".phpunit.cache"
beStrictAboutCoverageMetadata="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<coverage/>
<source>
<include>
<directory suffix=".php">src</directory>
<directory>src</directory>
</include>
</coverage>
</source>
</phpunit>
2 changes: 2 additions & 0 deletions src/JsonEncodingTrait.php
Original file line number Diff line number Diff line change
@@ -42,6 +42,8 @@ public static function fromJson(string $json): self

/**
* Serialise the message into a JSON string
*
* @psalm-return non-empty-string
*/
public function asJson(): string
{
38 changes: 26 additions & 12 deletions tests/AcceptanceTest.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
<?php


use Cucumber\Messages\DecodingException;
use Cucumber\Messages\Envelope;
use Cucumber\Messages\Streams\NdJson\NdJsonStreamReader;
use Cucumber\Messages\Streams\NdJson\NdJsonStreamWriter;
use PHPUnit\Framework\TestCase;

class AcceptanceTest extends TestCase
{
/** @dataProvider provideJsonLines */
/** @dataProvider provideJsonLines
* @throws DecodingException
* @throws JsonException
*/
public function testAllNdJsonSurvivesDecodingThenEncoding(string $json): void
{
self::assertNotEmpty($json);

$envelope = Envelope::fromJson($json);
$newJson = $envelope->asJson();

@@ -34,11 +41,11 @@ public function testAllFileStreamsSurviveDecodingThenEncoding(string $filename):
$sourceLine = fgets($sourceHandle);
$destLine = fgets($destHandle);

if (!$sourceLine && !$destLine) {
break;
if (empty($sourceLine) || empty($destLine)) {
self::assertEquals($sourceLine, $destLine);
} else {
self::assertJsonStringEqualsJsonString($sourceLine, $destLine);
}

self::assertJsonStringEqualsJsonString($sourceLine, $destLine);
}

// we exhausted source so dest should also be at end
@@ -48,9 +55,9 @@ public function testAllFileStreamsSurviveDecodingThenEncoding(string $filename):
/**
* @return Generator<string, array{0: string}>
*/
public function provideJsonLines(): Generator
public static function provideJsonLines(): Generator
{
foreach ($this->getSampleFiles() as $filename) {
foreach (AcceptanceTest::getSampleFiles() as $filename) {
foreach (file($filename) ?: [] as $lineNumber => $line) {
// key is provided for better error messages
$key = realpath($filename) . ':' . $lineNumber;
@@ -62,18 +69,25 @@ public function provideJsonLines(): Generator
/**
* @return Generator<string, array{0: string}>
*/
public function provideNdJsonFilenames(): Generator
public static function provideNdJsonFilenames(): Generator
{
foreach ($this->getSampleFiles() as $filename) {
foreach (AcceptanceTest::getSampleFiles() as $filename) {
yield $filename => [$filename];
}
}

/**
* @return list<string>
* @return array<string>
*/
private function getSampleFiles(): array
private static function getSampleFiles(): array
{
return glob(__DIR__ . '/../../../node_modules/@cucumber/compatibility-kit/features/**/*.ndjson') ?: [];
// Note: This test setup is not ideal. The minimal.feature.ndjson
// will break whenever the schema for a feature file is updated.
//
// It would be better to specifically target known problems.
// However there are currently no known problems (because these
// tests originally tested against the CCK but that caused
// circular dependencies).
return glob(__DIR__ . '/Samples/*.ndjson') ?: [];
}
}
12 changes: 12 additions & 0 deletions tests/Samples/minimal.feature.ndjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{"meta":{"ci":{"buildNumber":"154666429","git":{"remote":"https://github.com/cucumber-ltd/shouty.rb.git","revision":"99684bcacf01d95875834d87903dcb072306c9ad"},"name":"GitHub Actions","url":"https://github.com/cucumber-ltd/shouty.rb/actions/runs/154666429"},"cpu":{"name":"x64"},"implementation":{"name":"fake-cucumber","version":"16.3.0"},"os":{"name":"darwin","version":"22.4.0"},"protocolVersion":"22.0.0","runtime":{"name":"node.js","version":"19.7.0"}}}
{"source":{"data":"Feature: minimal\n \n Cucumber doesn't execute this markdown, but @cucumber/react renders it\n \n * This is\n * a bullet\n * list\n \n Scenario: cukes\n Given I have 42 cukes in my belly\n","mediaType":"text/x.cucumber.gherkin+plain","uri":"samples/minimal/minimal.feature"}}
{"gherkinDocument":{"comments":[],"feature":{"children":[{"scenario":{"description":"","examples":[],"id":"2","keyword":"Scenario","location":{"column":3,"line":9},"name":"cukes","steps":[{"id":"1","keyword":"Given ","keywordType":"Context","location":{"column":5,"line":10},"text":"I have 42 cukes in my belly"}],"tags":[]}}],"description":" Cucumber doesn't execute this markdown, but @cucumber/react renders it\n \n * This is\n * a bullet\n * list","keyword":"Feature","language":"en","location":{"column":1,"line":1},"name":"minimal","tags":[]},"uri":"samples/minimal/minimal.feature"}}
{"pickle":{"astNodeIds":["2"],"id":"4","language":"en","name":"cukes","steps":[{"astNodeIds":["1"],"id":"3","text":"I have 42 cukes in my belly","type":"Context"}],"tags":[],"uri":"samples/minimal/minimal.feature"}}
{"stepDefinition":{"id":"0","pattern":{"source":"I have {int} cukes in my belly","type":"CUCUMBER_EXPRESSION"},"sourceReference":{"location":{"line":4},"uri":"samples/minimal/minimal.feature.ts"}}}
{"testRunStarted":{"timestamp":{"nanos":0,"seconds":0}}}
{"testCase":{"id":"6","pickleId":"4","testSteps":[{"id":"5","pickleStepId":"3","stepDefinitionIds":["0"],"stepMatchArgumentsLists":[{"stepMatchArguments":[{"group":{"children":[],"start":7,"value":"42"},"parameterTypeName":"int"}]}]}]}}
{"testCaseStarted":{"attempt":0,"id":"7","testCaseId":"6","timestamp":{"nanos":1000000,"seconds":0}}}
{"testStepStarted":{"testCaseStartedId":"7","testStepId":"5","timestamp":{"nanos":2000000,"seconds":0}}}
{"testStepFinished":{"testCaseStartedId":"7","testStepId":"5","testStepResult":{"duration":{"nanos":1000000,"seconds":0},"status":"PASSED"},"timestamp":{"nanos":3000000,"seconds":0}}}
{"testCaseFinished":{"testCaseStartedId":"7","timestamp":{"nanos":4000000,"seconds":0},"willBeRetried":false}}
{"testRunFinished":{"success":true,"timestamp":{"nanos":5000000,"seconds":0}}}