| Server IP : 54.233.248.239 / Your IP : 172.28.20.13 Web Server : Apache System : Linux ip-172-28-29-189 6.5.0-1014-aws #14~22.04.1-Ubuntu SMP Thu Feb 15 15:27:06 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.2.34-43+ubuntu22.04.1+deb.sury.org+1 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/vinumday2_0/vendor/phpunit/phpunit/tests/Framework/Constraint/ |
Upload File : |
<?php
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Framework\Constraint;
use PHPUnit\Framework\ExpectationFailedException;
use PHPUnit\Framework\TestCase;
class JsonMatchesTest extends TestCase
{
/**
* @dataProvider evaluateDataprovider
*/
public function testEvaluate($expected, $jsonOther, $jsonValue)
{
$constraint = new JsonMatches($jsonValue);
$this->assertEquals($expected, $constraint->evaluate($jsonOther, '', true));
}
/**
* @dataProvider evaluateThrowsExpectationFailedExceptionWhenJsonIsValidButDoesNotMatchDataprovider
*/
public function testEvaluateThrowsExpectationFailedExceptionWhenJsonIsValidButDoesNotMatch($jsonOther, $jsonValue)
{
$constraint = new JsonMatches($jsonValue);
try {
$constraint->evaluate($jsonOther, '', false);
$this->fail(\sprintf('Expected %s to be thrown.', ExpectationFailedException::class));
} catch (ExpectationFailedException $expectedException) {
$comparisonFailure = $expectedException->getComparisonFailure();
$this->assertNotNull($comparisonFailure);
$this->assertSame($jsonOther, $comparisonFailure->getExpectedAsString());
$this->assertSame($jsonValue, $comparisonFailure->getActualAsString());
$this->assertSame('Failed asserting that two json values are equal.', $comparisonFailure->getMessage());
}
}
public function testToString()
{
$jsonValue = \json_encode(['Mascott' => 'Tux']);
$constraint = new JsonMatches($jsonValue);
$this->assertEquals('matches JSON string "' . $jsonValue . '"', $constraint->toString());
}
public static function evaluateDataprovider()
{
return [
'valid JSON' => [true, \json_encode(['Mascott' => 'Tux']), \json_encode(['Mascott' => 'Tux'])],
'error syntax' => [false, '{"Mascott"::}', \json_encode(['Mascott' => 'Tux'])],
'error UTF-8' => [false, \json_encode('\xB1\x31'), \json_encode(['Mascott' => 'Tux'])],
'invalid JSON in class instantiation' => [false, \json_encode(['Mascott' => 'Tux']), '{"Mascott"::}'],
'string type not equals number' => [false, '{"age": "5"}', '{"age": 5}'],
'string type not equals boolean' => [false, '{"age": "true"}', '{"age": true}'],
'string type not equals null' => [false, '{"age": "null"}', '{"age": null}'],
'object fields are unordered' => [true, '{"first":1, "second":"2"}', '{"second":"2", "first":1}'],
'child object fields are unordered' => [true, '{"Mascott": {"name":"Tux", "age":5}}', '{"Mascott": {"age":5, "name":"Tux"}}'],
'null field different from missing field' => [false, '{"present": true, "missing": null}', '{"present": true}'],
'array elements are ordered' => [false, '["first", "second"]', '["second", "first"]'],
'single boolean valid json' => [true, 'true', 'true'],
'single number valid json' => [true, '5.3', '5.3'],
'single null valid json' => [true, 'null', 'null'],
];
}
public static function evaluateThrowsExpectationFailedExceptionWhenJsonIsValidButDoesNotMatchDataprovider()
{
return [
'error UTF-8' => [\json_encode('\xB1\x31'), \json_encode(['Mascott' => 'Tux'])],
'string type not equals number' => ['{"age": "5"}', '{"age": 5}'],
'string type not equals boolean' => ['{"age": "true"}', '{"age": true}'],
'string type not equals null' => ['{"age": "null"}', '{"age": null}'],
'null field different from missing field' => ['{"present": true, "missing": null}', '{"present": true}'],
'array elements are ordered' => ['["first", "second"]', '["second", "first"]']
];
}
}