Skip to content

Bump actions/checkout from 2 to 3.1.0 #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 10 additions & 19 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
psalm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3.1.0

- name: Psalm
uses: docker://vimeo/psalm-github-actions
Expand All @@ -21,7 +21,7 @@ jobs:
# codecov:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# - uses: actions/checkout@v3.1.0
# with:
# fetch-depth: 0

Expand Down Expand Up @@ -51,25 +51,16 @@ jobs:
strategy:
matrix:
php:
- 7.1
# - 7.2
# - 7.3
# - 7.4
# - 8.0
- 7.4
- 8.0
include:
- php: 7.1
phpunit: 7.5.20
# - php: 7.2
# phpunit: 8.5.13
# - php: 7.3
# phpunit: 9.5.0
# - php: 7.4
# phpunit: 9.5.0
# - php: 8.0
# phpunit: 9.5.0
- php: 7.4
phpunit: 9.5.0
- php: 8.0
phpunit: 9.5.0

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3.1.0

- name: Cache Composer dependencies
uses: actions/cache@v2
Expand All @@ -81,7 +72,7 @@ jobs:
with:
php_version: ${{ matrix.php }}

- uses: php-actions/phpunit@v2
- uses: php-actions/phpunit@v9
with:
php_version: ${{ matrix.php }}
version: ${{ matrix.phpunit }}
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v2
- uses: actions/checkout@v3.1.0

- name: git/unshallow
run: git fetch --prune --unshallow
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
],
"minimum-stability": "stable",
"require": {
"php": "^7.0",
"php": "^7.4|^8.0",
"justinrainbow/json-schema": "^5.0",
"mtdowling/jmespath.php": "^2.3"
"mtdowling/jmespath.php": "^2.3",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^6",
"phpunit/phpunit": "^9",
"codacy/coverage": "dev-master",
"symfony/http-foundation": "^2.8|^3.0"
},
Expand Down
22 changes: 9 additions & 13 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- http://phpunit.de/manual/4.1/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
>
bootstrap="./vendor/autoload.php">
<testsuites>
<testsuite name="phpunit-json-assertions Test Suite">
<directory>tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<coverage>
<include>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>

<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>

</include>
<report>
<clover outputFile="./build/logs/clover.xml"/>
</report>
</coverage>
</phpunit>
44 changes: 14 additions & 30 deletions src/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace EnricoStahn\JsonAssert;

use JmesPath\Env;
use JsonSchema\Constraints\Factory;
use JsonSchema\SchemaStorage;
use JsonSchema\Validator;
Expand All @@ -26,9 +27,9 @@
trait Assert
{
/**
* @var SchemaStorage
* @var ?SchemaStorage
*/
private static $schemaStorage = null;
private static ?SchemaStorage $schemaStorage = null;

/**
* Asserts that json content is valid according to the provided schema file.
Expand All @@ -37,10 +38,10 @@ trait Assert
*
* static::assertJsonMatchesSchema(json_decode('{"foo":1}'), './schema.json')
*
* @param string|null $schema Path to the schema file
* @param array|object $content JSON array or object
* @param ?string $schema Path to the schema file
*/
public static function assertJsonMatchesSchema($content, $schema = null)
public static function assertJsonMatchesSchema($content, ?string $schema = null): void
{
if (self::$schemaStorage === null) {
self::$schemaStorage = new SchemaStorage();
Expand All @@ -60,7 +61,7 @@ public static function assertJsonMatchesSchema($content, $schema = null)
$validator = new Validator(new Factory(self::$schemaStorage));
$validator->validate($content, $schemaObject);

$message = '- Property: %s, Contraint: %s, Message: %s';
$message = '- Property: %s, Constraint: %s, Message: %s';
$messages = array_map(function ($exception) use ($message) {
return sprintf($message, $exception['property'], $exception['constraint'], $exception['message']);
}, $validator->getErrors());
Expand All @@ -69,30 +70,13 @@ public static function assertJsonMatchesSchema($content, $schema = null)
\PHPUnit\Framework\Assert::assertTrue($validator->isValid(), implode("\n", $messages));
}

/**
* Asserts that json content is valid according to the provided schema file.
*
* Example:
*
* static::assertJsonMatchesSchema(json_decode('{"foo":1}'), './schema.json')
*
* @param string|null $schema Path to the schema file
* @param array|object $content JSON array or object
*
* @deprecated This will be removed in the next major version (4.x).
*/
public static function assertJsonMatchesSchemaDepr($schema, $content)
{
self::assertJsonMatchesSchema($content, $schema);
}

/**
* Asserts that json content is valid according to the provided schema string.
*
* @param string $schema Schema data
* @param array|object $content JSON content
*/
public static function assertJsonMatchesSchemaString($schema, $content)
public static function assertJsonMatchesSchemaString(string $schema, $content): void
{
$file = tempnam(sys_get_temp_dir(), 'json-schema-');
file_put_contents($file, $schema);
Expand All @@ -107,17 +91,17 @@ public static function assertJsonMatchesSchemaString($schema, $content)
*
* static::assertJsonValueEquals(33, 'foo.bar[0]', $json);
*
* @param mixed $expected Expected value
* @param string $expression Expression to retrieve the result
* (e.g. locations[?state == 'WA'].name | sort(@))
* @param array|object $json JSON Content
* @param mixed $expected Expected value
* @param string $expression Expression to retrieve the result
* (e.g. locations[?state == 'WA'].name | sort(@))
* @param array|object|string $json JSON Content
*/
public static function assertJsonValueEquals($expected, $expression, $json)
public static function assertJsonValueEquals($expected, string $expression, $json): void
{
$result = \JmesPath\Env::search($expression, $json);
$result = Env::search($expression, $json);

\PHPUnit\Framework\Assert::assertEquals($expected, $result);
\PHPUnit\Framework\Assert::assertInternalType(strtolower(gettype($expected)), $result);
\PHPUnit\Framework\Assert::assertEquals(gettype($expected), gettype($result));
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/Extension/Symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ trait Symfony
* @param string $schema Path to the schema file
* @param Response $response JSON array or object
*/
public static function assertJsonMatchesSchema($schema, Response $response)
public static function assertJsonMatchesSchema(string $schema, Response $response): void
{
Assert::assertJsonMatchesSchemaDepr($schema, json_decode($response->getContent()));
Assert::assertJsonMatchesSchema(json_decode($response->getContent()), $schema);
}

/**
Expand All @@ -37,7 +37,7 @@ public static function assertJsonMatchesSchema($schema, Response $response)
* @param string $schema Schema data
* @param Response $response JSON content
*/
public static function assertJsonMatchesSchemaString($schema, Response $response)
public static function assertJsonMatchesSchemaString(string $schema, Response $response): void
{
Assert::assertJsonMatchesSchemaString($schema, json_decode($response->getContent()));
}
Expand All @@ -54,7 +54,7 @@ public static function assertJsonMatchesSchemaString($schema, Response $response
* (e.g. locations[?state == 'WA'].name | sort(@))
* @param Response $response JSON Content
*/
public static function assertJsonValueEquals($expected, $expression, $response)
public static function assertJsonValueEquals($expected, string $expression, Response $response): void
{
Assert::assertJsonValueEquals($expected, $expression, json_decode($response->getContent()));
}
Expand All @@ -67,7 +67,7 @@ public static function assertJsonValueEquals($expected, $expression, $response)
*
* @see \Bazinga\Bundle\RestExtraBundle\Test\WebTestCase::assertJsonResponse()
*/
public static function assertJsonResponse(Response $response, $statusCode = 200)
public static function assertJsonResponse(Response $response, int $statusCode = 200): void
{
\PHPUnit\Framework\Assert::assertEquals(
$statusCode,
Expand Down
8 changes: 4 additions & 4 deletions tests/AssertTraitImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ class AssertTraitImpl extends TestCase
{
use JsonAssert;

public function setUp()
public function setUp(): void
{
self::$schemaStorage = new SchemaStorage();
}

/**
* @param string $id
* @param string $schema
* @param string $id
* @param array|object $schema
*
* @return SchemaStorage
*/
public function testWithSchemaStore($id, $schema)
public function testWithSchemaStore(string $id, $schema): SchemaStorage
{
self::$schemaStorage->addSchema($id, $schema);

Expand Down
Loading