Skip to content

Applied fixes from StyleCI #1

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

Merged
merged 1 commit into from
Mar 16, 2016
Merged
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
20 changes: 11 additions & 9 deletions src/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use JsonSchema\Validator;

/**
* Asserts to validate JSON data
* Asserts to validate JSON data.
*
* - All assert methods expect deserialised JSON data (an actual object or array)
* since the deserialisation method should be up to the user.
Expand All @@ -25,7 +25,7 @@
trait Assert
{
/**
* Asserts that json content is valid according to the provided schema file
* Asserts that json content is valid according to the provided schema file.
*
* Example:
*
Expand All @@ -37,10 +37,10 @@ trait Assert
public static function assertJsonMatchesSchema($schema, $content)
{
$retriever = new UriRetriever();
$schema = $retriever->retrieve('file://' . realpath($schema));
$schema = $retriever->retrieve('file://'.realpath($schema));

$refResolver = new RefResolver($retriever);
$refResolver->resolve($schema, 'file://' . __DIR__ . '/../Resources/schemas/');
$refResolver->resolve($schema, 'file://'.__DIR__.'/../Resources/schemas/');

$validator = new Validator();
$validator->check($content, $schema);
Expand All @@ -49,13 +49,13 @@ public static function assertJsonMatchesSchema($schema, $content)
$messages = array_map(function ($e) use ($message) {
return sprintf($message, $e['property'], $e['constraint'], $e['message']);
}, $validator->getErrors());
$messages[] = '- Response: ' . json_encode($content);
$messages[] = '- Response: '.json_encode($content);

self::assertTrue($validator->isValid(), implode("\n", $messages));
}

/**
* Asserts that json content is valid according to the provided schema string
* Asserts that json content is valid according to the provided schema string.
*
* @param string $schema Schema data
* @param array|object $content JSON content
Expand All @@ -69,7 +69,7 @@ public static function assertJsonMatchesSchemaString($schema, $content)
}

/**
* Asserts if the value retrieved with the expression equals the expected value
* Asserts if the value retrieved with the expression equals the expected value.
*
* Example:
*
Expand All @@ -90,6 +90,7 @@ public static function assertJsonValueEquals($expected, $expression, $json)
/**
* @param $expression
* @param $data
*
* @return mixed|null
*/
public static function search($expression, $data)
Expand All @@ -98,13 +99,14 @@ public static function search($expression, $data)
}

/**
* Helper method to deserialise a JSON string into an object
* Helper method to deserialise a JSON string into an object.
*
* @param mixed $data The JSON string
*
* @return array|object
*/
public static function getJsonObject($data)
{
return (is_array($data) || is_object($data)) ? $data : json_decode($data);
}
}
}
11 changes: 10 additions & 1 deletion src/AssertClass.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
<?php

/*
* This file is part of the phpunit-json-assertions package.
*
* (c) Enrico Stahn <enrico.stahn@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace EnricoStahn\JsonAssert;

class AssertClass extends \PHPUnit_Framework_TestCase
{
use Assert;
}
}
2 changes: 1 addition & 1 deletion tests/AssertTraitImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
class AssertTraitImpl extends \PHPUnit_Framework_TestCase
{
use JsonAssert;
}
}
18 changes: 13 additions & 5 deletions tests/AssertTraitTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the phpunit-json-assertions package.
*
* (c) Enrico Stahn <enrico.stahn@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace EnricoStahn\JsonAssert\Tests;

class AssertTraitTest extends \PHPUnit_Framework_TestCase
Expand Down Expand Up @@ -48,12 +57,12 @@ public function testAssertJsonSchemaFailMessage()
}

/**
* Tests assertJsonValueEquals()
* Tests assertJsonValueEquals().
*
* @dataProvider assertJsonValueEqualsProvider
*
* @param string $expression
* @param mixed $value
* @param mixed $value
*/
public function testAssertJsonValueEquals($expression, $value)
{
Expand All @@ -66,7 +75,7 @@ public function assertJsonValueEqualsProvider()
{
return [
['foo', '123'],
['a.b.c[0].d[1][0]', 1]
['a.b.c[0].d[1][0]', 1],
];
}

Expand Down Expand Up @@ -94,8 +103,7 @@ public function testGetJsonObjectProvider()
[[], []],
[[], '[]'],
[new \stdClass(), new \stdClass()],
[new \stdClass(), '{}']
[new \stdClass(), '{}'],
];
}

}