From 8c1572b78e648601c06189f4d964af6836f82e6a Mon Sep 17 00:00:00 2001 From: Christoph Quadt Date: Mon, 2 Mar 2020 11:35:37 +0100 Subject: [PATCH 1/8] Added support for phpunit 9 --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index c6b7290..dd95dc0 100644 --- a/composer.json +++ b/composer.json @@ -9,15 +9,15 @@ } ], "require": { - "php": "^7.2", + "php": "^7.2 || ^7.3", "flow/jsonpath": "^0.5.0", "justinrainbow/json-schema": "^5.0" }, "conflict": { - "phpunit/phpunit": "<8.0 || >= 9.0" + "phpunit/phpunit": "<8.0" }, "require-dev": { - "phpunit/phpunit": "^8.0" + "phpunit/phpunit": "^8.0 || ^9.0" }, "autoload": { "psr-4": { From a0ed77cb71e31f17f7bf50ced054ae1e21998474 Mon Sep 17 00:00:00 2001 From: Christoph Quadt Date: Mon, 2 Mar 2020 11:58:32 +0100 Subject: [PATCH 2/8] Fixed unit tests due to redeclared functions --- composer.json | 1 - tests/Functional/JsonValueMatchesFluentTest.php | 12 ++++++------ .../Functional/JsonValueMatchesSchemaFluentTest.php | 4 ++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index dd95dc0..4c3dac3 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,6 @@ }, "autoload-dev": { "files": [ - "vendor/phpunit/phpunit/src/Framework/Assert/Functions.php", "src/Functions.php" ] }, diff --git a/tests/Functional/JsonValueMatchesFluentTest.php b/tests/Functional/JsonValueMatchesFluentTest.php index 3e6dd8c..e912241 100644 --- a/tests/Functional/JsonValueMatchesFluentTest.php +++ b/tests/Functional/JsonValueMatchesFluentTest.php @@ -28,20 +28,20 @@ class JsonValueMatchesFluentTest extends TestCase public function testAssertThatJsonDocumentContainsJsonValue() { - assertThat(self::$exampleDocument, containsJsonValue('$.identifier', 1234)); + $this->assertThat(self::$exampleDocument, containsJsonValue('$.identifier', 1234)); } public function testAssertThatJsonDocumentMatchesJsonConstraints() { - assertThat( + $this->assertThat( self::$exampleDocument, matchesJsonConstraints( [ - '$.owner.name' => equalTo('Max Mustermann'), - '$.products[*].identifier' => greaterThanOrEqual(500), - '$.products[*].name' => logicalNot(equalTo('Weißbrot')) + '$.owner.name' => $this->equalTo('Max Mustermann'), + '$.products[*].identifier' => $this->greaterThanOrEqual(500), + '$.products[*].name' => $this->logicalNot($this->equalTo('Weißbrot')) ] ) ); } -} \ No newline at end of file +} diff --git a/tests/Functional/JsonValueMatchesSchemaFluentTest.php b/tests/Functional/JsonValueMatchesSchemaFluentTest.php index b3757cb..616dbac 100644 --- a/tests/Functional/JsonValueMatchesSchemaFluentTest.php +++ b/tests/Functional/JsonValueMatchesSchemaFluentTest.php @@ -31,7 +31,7 @@ class JsonValueMatchesSchemaFluentTest extends TestCase public function testJsonDocumentMatchesSchema() { - assertThat(static::$exampleDocument, matchesJsonSchema([ + $this->assertThat(static::$exampleDocument, matchesJsonSchema([ 'type' => 'object', 'required' => ['identifier', 'owner', 'products'], 'properties' => [ @@ -64,7 +64,7 @@ public function testJsonDocumentDoesNotMatchSchema() { $this->expectException(AssertionFailedError::class); - assertThat(static::$exampleDocument, matchesJsonSchema([ + $this->assertThat(static::$exampleDocument, matchesJsonSchema([ 'type' => 'object', 'required' => ['foobar'], 'properties' => [ From 9cebba9d7d4e3e7b30aaf56f613749761125165a Mon Sep 17 00:00:00 2001 From: Christoph Quadt Date: Mon, 2 Mar 2020 22:44:44 +0100 Subject: [PATCH 3/8] Restrict package to be used with future versions of phpunit. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4c3dac3..1deb833 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "justinrainbow/json-schema": "^5.0" }, "conflict": { - "phpunit/phpunit": "<8.0" + "phpunit/phpunit": "<8.0 || >= 10.0" }, "require-dev": { "phpunit/phpunit": "^8.0 || ^9.0" From aa56581e2691d4cb2f2ab651feea7e529ff7f413 Mon Sep 17 00:00:00 2001 From: Christoph Quadt Date: Mon, 2 Mar 2020 22:53:53 +0100 Subject: [PATCH 4/8] Added function usage to support functional interface. --- tests/Functional/JsonValueMatchesFluentTest.php | 14 +++++++++----- .../JsonValueMatchesSchemaFluentTest.php | 5 +++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/tests/Functional/JsonValueMatchesFluentTest.php b/tests/Functional/JsonValueMatchesFluentTest.php index e912241..a500247 100644 --- a/tests/Functional/JsonValueMatchesFluentTest.php +++ b/tests/Functional/JsonValueMatchesFluentTest.php @@ -2,6 +2,10 @@ namespace Helmich\JsonAssert\Tests\Functional; use PHPUnit\Framework\TestCase; +use function PHPUnit\Framework\assertThat; +use function PHPUnit\Framework\equalTo; +use function PHPUnit\Framework\greaterThanOrEqual; +use function PHPUnit\Framework\logicalNot; class JsonValueMatchesFluentTest extends TestCase { @@ -28,18 +32,18 @@ class JsonValueMatchesFluentTest extends TestCase public function testAssertThatJsonDocumentContainsJsonValue() { - $this->assertThat(self::$exampleDocument, containsJsonValue('$.identifier', 1234)); + assertThat(self::$exampleDocument, containsJsonValue('$.identifier', 1234)); } public function testAssertThatJsonDocumentMatchesJsonConstraints() { - $this->assertThat( + assertThat( self::$exampleDocument, matchesJsonConstraints( [ - '$.owner.name' => $this->equalTo('Max Mustermann'), - '$.products[*].identifier' => $this->greaterThanOrEqual(500), - '$.products[*].name' => $this->logicalNot($this->equalTo('Weißbrot')) + '$.owner.name' => equalTo('Max Mustermann'), + '$.products[*].identifier' => greaterThanOrEqual(500), + '$.products[*].name' => logicalNot(equalTo('Weißbrot')) ] ) ); diff --git a/tests/Functional/JsonValueMatchesSchemaFluentTest.php b/tests/Functional/JsonValueMatchesSchemaFluentTest.php index 616dbac..fdcccd6 100644 --- a/tests/Functional/JsonValueMatchesSchemaFluentTest.php +++ b/tests/Functional/JsonValueMatchesSchemaFluentTest.php @@ -4,6 +4,7 @@ use Helmich\JsonAssert\JsonAssertions; use PHPUnit\Framework\AssertionFailedError; use PHPUnit\Framework\TestCase; +use function PHPUnit\Framework\assertThat; class JsonValueMatchesSchemaFluentTest extends TestCase { @@ -31,7 +32,7 @@ class JsonValueMatchesSchemaFluentTest extends TestCase public function testJsonDocumentMatchesSchema() { - $this->assertThat(static::$exampleDocument, matchesJsonSchema([ + assertThat(static::$exampleDocument, matchesJsonSchema([ 'type' => 'object', 'required' => ['identifier', 'owner', 'products'], 'properties' => [ @@ -64,7 +65,7 @@ public function testJsonDocumentDoesNotMatchSchema() { $this->expectException(AssertionFailedError::class); - $this->assertThat(static::$exampleDocument, matchesJsonSchema([ + assertThat(static::$exampleDocument, matchesJsonSchema([ 'type' => 'object', 'required' => ['foobar'], 'properties' => [ From ee6e06d9cdf76a6c71aab78f8b86d8b754280c03 Mon Sep 17 00:00:00 2001 From: Martin Helmich Date: Sat, 28 Mar 2020 14:13:43 +0100 Subject: [PATCH 5/8] Revert "Added function usage to support functional interface." This reverts commit aa56581e2691d4cb2f2ab651feea7e529ff7f413. --- tests/Functional/JsonValueMatchesFluentTest.php | 14 +++++--------- .../JsonValueMatchesSchemaFluentTest.php | 5 ++--- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/tests/Functional/JsonValueMatchesFluentTest.php b/tests/Functional/JsonValueMatchesFluentTest.php index a500247..e912241 100644 --- a/tests/Functional/JsonValueMatchesFluentTest.php +++ b/tests/Functional/JsonValueMatchesFluentTest.php @@ -2,10 +2,6 @@ namespace Helmich\JsonAssert\Tests\Functional; use PHPUnit\Framework\TestCase; -use function PHPUnit\Framework\assertThat; -use function PHPUnit\Framework\equalTo; -use function PHPUnit\Framework\greaterThanOrEqual; -use function PHPUnit\Framework\logicalNot; class JsonValueMatchesFluentTest extends TestCase { @@ -32,18 +28,18 @@ class JsonValueMatchesFluentTest extends TestCase public function testAssertThatJsonDocumentContainsJsonValue() { - assertThat(self::$exampleDocument, containsJsonValue('$.identifier', 1234)); + $this->assertThat(self::$exampleDocument, containsJsonValue('$.identifier', 1234)); } public function testAssertThatJsonDocumentMatchesJsonConstraints() { - assertThat( + $this->assertThat( self::$exampleDocument, matchesJsonConstraints( [ - '$.owner.name' => equalTo('Max Mustermann'), - '$.products[*].identifier' => greaterThanOrEqual(500), - '$.products[*].name' => logicalNot(equalTo('Weißbrot')) + '$.owner.name' => $this->equalTo('Max Mustermann'), + '$.products[*].identifier' => $this->greaterThanOrEqual(500), + '$.products[*].name' => $this->logicalNot($this->equalTo('Weißbrot')) ] ) ); diff --git a/tests/Functional/JsonValueMatchesSchemaFluentTest.php b/tests/Functional/JsonValueMatchesSchemaFluentTest.php index fdcccd6..616dbac 100644 --- a/tests/Functional/JsonValueMatchesSchemaFluentTest.php +++ b/tests/Functional/JsonValueMatchesSchemaFluentTest.php @@ -4,7 +4,6 @@ use Helmich\JsonAssert\JsonAssertions; use PHPUnit\Framework\AssertionFailedError; use PHPUnit\Framework\TestCase; -use function PHPUnit\Framework\assertThat; class JsonValueMatchesSchemaFluentTest extends TestCase { @@ -32,7 +31,7 @@ class JsonValueMatchesSchemaFluentTest extends TestCase public function testJsonDocumentMatchesSchema() { - assertThat(static::$exampleDocument, matchesJsonSchema([ + $this->assertThat(static::$exampleDocument, matchesJsonSchema([ 'type' => 'object', 'required' => ['identifier', 'owner', 'products'], 'properties' => [ @@ -65,7 +64,7 @@ public function testJsonDocumentDoesNotMatchSchema() { $this->expectException(AssertionFailedError::class); - assertThat(static::$exampleDocument, matchesJsonSchema([ + $this->assertThat(static::$exampleDocument, matchesJsonSchema([ 'type' => 'object', 'required' => ['foobar'], 'properties' => [ From 415ae9a1fdac41270275c3bf0bb1f15218f14dbe Mon Sep 17 00:00:00 2001 From: Martin Helmich Date: Sat, 28 Mar 2020 14:14:06 +0100 Subject: [PATCH 6/8] Configure Github workflow for testing --- .github/workflows/php.yml | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/php.yml diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml new file mode 100644 index 0000000..58522d8 --- /dev/null +++ b/.github/workflows/php.yml @@ -0,0 +1,40 @@ +name: PHP type checking and unit testing + +on: [push] + +jobs: + build: + strategy: + matrix: + php: ['7.2', '7.3', '7.4'] + phpunit: ['8.0', '9.0'] + exclude: + - php: '7.2' + phpunit: '9.0' + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + + - name: Setup PHP + uses: shivammathur/setup-php@v1 + with: + php-version: ${{ matrix.php }} + extensions: mbstring, intl, json + coverage: pcov + + - name: Validate composer.json and composer.lock + run: composer validate + + - name: Declare required PHPUnit version + run: | + composer require --no-update --dev phpunit/phpunit ~${{ matrix.phpunit }} + + - name: Install dependencies + run: composer install --prefer-dist --no-progress --no-suggest + + #- name: Run type checker + # run: ./vendor/bin/psalm + + - name: Run unit tests + run: ./vendor/bin/phpunit --testdox From 45ce17389f72dc308372bfb98400cb7a5ed1b750 Mon Sep 17 00:00:00 2001 From: Martin Helmich Date: Sat, 28 Mar 2020 14:15:56 +0100 Subject: [PATCH 7/8] Adjust compatibility matrix --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3ebd4e1..3ffe140 100644 --- a/README.md +++ b/README.md @@ -23,11 +23,11 @@ This library is [MIT-licensed](LICENSE.txt). There are several release branches of this library, each of these being compatible with different releases of PHPUnit and PHP. The following table should give an easy overview: -| "JSON assertion" version | PHPUnit 4 | PHPUnit 5 | PHPUnit 6 | PHPUnit 7 | PHPUnit 8 | -| ------------------------ | --------- | --------- | --------- | --------- | --------- | -| v1 (branch `v1`), **unsupported** | :white_check_mark: | :white_check_mark: | :no_entry_sign: | :no_entry_sign: | :no_entry_sign: | -| v2 (branch `v2`) | :no_entry_sign: | :no_entry_sign: | :white_check_mark: | :white_check_mark: | :no_entry_sign: | -| v3 (branch `master`) | :no_entry_sign: | :no_entry_sign: | :no_entry_sign: | :no_entry_sign: | :white_check_mark: | +| "JSON assertion" version | PHPUnit 4 | PHPUnit 5 | PHPUnit 6 | PHPUnit 7 | PHPUnit 8 | PHPUnit 9 | +| ------------------------ | --------- | --------- | --------- | --------- | --------- | --------- | +| v1 (branch `v1`), **unsupported** | :white_check_mark: | :white_check_mark: | :no_entry_sign: | :no_entry_sign: | :no_entry_sign: | :no_entry_sign: | +| v2 (branch `v2`) | :no_entry_sign: | :no_entry_sign: | :white_check_mark: | :white_check_mark: | :no_entry_sign: | :no_entry_sign: | +| v3 (branch `master`) | :no_entry_sign: | :no_entry_sign: | :no_entry_sign: | :no_entry_sign: | :white_check_mark: | :white_check_mark: | When you are using `composer require` and have already declared a dependency to `phpunit/phpunit` in your `composer.json` file, Composer should pick latest compatible version automatically. From 90c76a341cb83cb09cc9220e7f03857bb211044e Mon Sep 17 00:00:00 2001 From: Martin Helmich Date: Sat, 28 Mar 2020 14:17:16 +0100 Subject: [PATCH 8/8] Relax PHP version constaint in composer.json --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 1deb833..b07bccc 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ } ], "require": { - "php": "^7.2 || ^7.3", + "php": "^7.2", "flow/jsonpath": "^0.5.0", "justinrainbow/json-schema": "^5.0" }, @@ -32,4 +32,4 @@ "config": { "sort-packages": true } -} +} \ No newline at end of file