diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e33910..edaeb2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,3 +33,10 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip ### Removed - Moved Factory classes into another package : VGirol/JsonApi-Faker + +## 1.2.1 - 2019-09-30 + +### Added + +- Added some failure messages +- Added new methods for testing (VGirol\JsonApiAssert\SetExceptionsTrait::setFailure and VGirol\JsonApiAssert\SetExceptionsTrait::formatAsRegex) diff --git a/scripts/build.sh b/scripts/build.sh deleted file mode 100644 index b4c7ba2..0000000 --- a/scripts/build.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -BASE_PATH="./scripts" -LINT_PATH="$BASE_PATH/lint.sh" -METRICS_PATH="$BASE_PATH/metrics.sh" -PHPDOX_PATH="$BASE_PATH/phpdox.sh" - -. "$LINT_PATH" "$@" -. "$METRICS_PATH" -. "$PHPDOX_PATH" diff --git a/scripts/doc.sh b/scripts/doc.sh deleted file mode 100644 index f43fcee..0000000 --- a/scripts/doc.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -BASE_PATH="./scripts" -PHPCS_PATH="$BASE_PATH/phpcs.sh" -PHPMD_PATH="$BASE_PATH/phpmd.sh" -PHPUNIT_PATH="$BASE_PATH/phpunit.sh" -PHPLOC_PATH="$BASE_PATH/phploc.sh" -PHPDOX_PATH="$BASE_PATH/phpdox.sh" - -. "$PHPCS_PATH" -. "$PHPMD_PATH" -. "$PHPLOC_PATH" -. "$PHPUNIT_PATH" -. "$PHPDOX_PATH" diff --git a/scripts/infection.sh b/scripts/infection.sh deleted file mode 100644 index 7e3d529..0000000 --- a/scripts/infection.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -echo "Running infection ..." -infection --coverage=./build/coverage --threads=$(nproc) --configuration=./infection.json diff --git a/scripts/lint.sh b/scripts/lint.sh deleted file mode 100644 index 7b91ef2..0000000 --- a/scripts/lint.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -BASE_PATH="./scripts" -PHPCS_PATH="$BASE_PATH/phpcs.sh" -PHPMD_PATH="$BASE_PATH/phpmd.sh" -PHPCPD_PATH="$BASE_PATH/phpcpd.sh" -PHPMND_PATH="$BASE_PATH/phpmnd.sh" -PHPSTAN_PATH="$BASE_PATH/phpstan.sh" -PHAN_PATH="$BASE_PATH/phan.sh" - -with_phan=1 - -while [ "$1" != "" ]; do - case $1 in - -no-phan ) with_phan=0 - ;; - -h | --help ) usage - exit - ;; - * ) usage - exit 1 - esac - shift -done - -. "$PHPCS_PATH" -. "$PHPMD_PATH" -. "$PHPCPD_PATH" -. "$PHPMND_PATH" -. "$PHPSTAN_PATH" -if [ "$with_phan" = "1" ]; then - . "$PHAN_PATH" -fi diff --git a/scripts/metrics.sh b/scripts/metrics.sh deleted file mode 100644 index 6f05336..0000000 --- a/scripts/metrics.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -BASE_PATH="./scripts" -PHPUNIT_PATH="$BASE_PATH/phpunit.sh" -INFECTION_PATH="$BASE_PATH/infection.sh" -PHPMETRICS_PATH="$BASE_PATH/phpmetrics.sh" -PHPLOC_PATH="$BASE_PATH/phploc.sh" - -. "$PHPUNIT_PATH" -. "$INFECTION_PATH" -. "$PHPMETRICS_PATH" -. "$PHPLOC_PATH" diff --git a/scripts/phan.sh b/scripts/phan.sh deleted file mode 100644 index 833e7ed..0000000 --- a/scripts/phan.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -echo "Running phan..." -# ./build/scripts/php-no-xdebug.sh phan -m text -o ./build/phan/phan.txt -phan -m text -o ./build/phan/phan.txt diff --git a/scripts/php-no-xdebug.sh b/scripts/php-no-xdebug.sh deleted file mode 100644 index 0ccf28d..0000000 --- a/scripts/php-no-xdebug.sh +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/bash - -php=$(which php) - -# get the xdebug config -xdebugConfig=$(php -i | grep xdebug | while read line; do echo $line; exit; done) - -# no xdebug? Nothing to do! -if [ "$xdebugConfig" == "" ]; then - $php "$@" - exit -fi - -# get the configfile (which should be the first value) -# so strip off everything after the first space of the xdebug-config -xdebugConfigFile=$(php -i | grep xdebug | while read line; do echo $line; exit; done) - -# test whether we got it right -if [ ! -f "$xdebugConfigFile" ]; then - echo "No XDebug configfile found!" - exit 1 -fi - -# disable xdebug by renaming the relevant .ini file -mv ${xdebugConfigFile}{,.temporarily-disabled} - -# dissect the argument to extract the first one (which should be a script or an application in $PATH) from the rest -index=0 -for arg in $(echo $@ | tr ' ' "\n") -do - if [ "$index" == "0" ]; then - firstArg=$arg - else - restArg="$restArg $arg" - fi - - ((index++)) -done - -# check whether the command to be executed is a local PHP file or something in the $PATH like composer or php-cs-fixer -fullPath="$(which $firstArg)" -if [ "$fullPath" == "" ]; then - # check whether it's a local file - if [ ! -f $firstArg ]; then - echo "Could not find $firstArg. No such file or directory" - exit 1 - else - # just run the commands - $php $@ - fi -else - # run the command with the fullpath followed by the rest of the arguments provided - $php $fullPath $restArg -fi - -# execute the command -$php "$@" - -# re-enable xdebug -mv ${xdebugConfigFile}{.temporarily-disabled,} - -# test whether the conf file is restored correctly -if [ ! -f "$xdebugConfigFile" ]; then - echo "Something went wrong with restoring the configfile for xdebug!" - exit 1 -fi diff --git a/scripts/phpcpd.sh b/scripts/phpcpd.sh deleted file mode 100644 index 0b540fb..0000000 --- a/scripts/phpcpd.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -echo "Running phpcpd..." -phpcpd ./src diff --git a/scripts/phpcs.sh b/scripts/phpcs.sh deleted file mode 100644 index a24c9cc..0000000 --- a/scripts/phpcs.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -echo "Running phpcs..." -phpcs --encoding=utf-8 --report-full=./build/phpcs/phpcs.txt --report-xml=./build/phpcs/phpcs.xml diff --git a/scripts/phpdox.sh b/scripts/phpdox.sh deleted file mode 100644 index a7cb70e..0000000 --- a/scripts/phpdox.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -echo "Running phpDox..." -phpdox diff --git a/scripts/phploc.sh b/scripts/phploc.sh deleted file mode 100644 index ca29a64..0000000 --- a/scripts/phploc.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -echo "Running phploc..." -phploc --log-xml="./build/phploc/phploc.xml" -vvv ./src diff --git a/scripts/phpmd.sh b/scripts/phpmd.sh deleted file mode 100644 index 5b33757..0000000 --- a/scripts/phpmd.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -echo "Running phpmd..." -phpmd ./src text ./phpmd-src.xml --reportfile ./build/phpmd/phpmd_src.txt --ignore-violations-on-exit -phpmd ./src xml ./phpmd-src.xml --reportfile ./build/phpmd/phpmd_src.xml --ignore-violations-on-exit -phpmd ./tests text ./phpmd-tests.xml --reportfile ./build/phpmd/phpmd_tests.txt --ignore-violations-on-exit diff --git a/scripts/phpmetrics.sh b/scripts/phpmetrics.sh deleted file mode 100644 index 2637f51..0000000 --- a/scripts/phpmetrics.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -echo "Running phpmetrics..." -phpmetrics --report-html=./build/phpmetrics --junit=./build/coverage/phpunit.junit.xml ./src,./tests diff --git a/scripts/phpmnd.sh b/scripts/phpmnd.sh deleted file mode 100644 index 43e1151..0000000 --- a/scripts/phpmnd.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -echo "Running phpmnd..." -phpmnd ./src/ --extensions=all --strings --include-numeric-string --allow-array-mapping --xml-output=./build/phpmnd/phpmnd.xml --progress | tee ./build/phpmnd/phpmnd.txt diff --git a/scripts/phpstan.sh b/scripts/phpstan.sh deleted file mode 100644 index d4fe352..0000000 --- a/scripts/phpstan.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -echo "Running phpstan..." -phpstan analyse ./src --level=7 | tee ./build/phpstan/phpstan.txt diff --git a/scripts/phpunit.sh b/scripts/phpunit.sh deleted file mode 100644 index ee58f7a..0000000 --- a/scripts/phpunit.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -echo "Running phpunit..." -# phpunit ./tests --coverage-html=./build/coverage/html --coverage-xml=build/coverage/xml --log-junit=build/coverage/phpunit.junit.xml -phpunit ./tests diff --git a/src/Asserts/Content/AssertErrors.php b/src/Asserts/Content/AssertErrors.php index a9dd4d3..c2ef9b6 100644 --- a/src/Asserts/Content/AssertErrors.php +++ b/src/Asserts/Content/AssertErrors.php @@ -2,7 +2,6 @@ namespace VGirol\JsonApiAssert\Asserts\Content; -use DMS\PHPUnitExtensions\ArraySubset\Assert as AssertArray; use DMS\PHPUnitExtensions\ArraySubset\Constraint\ArraySubset; use PHPUnit\Framework\Assert as PHPUnit; use PHPUnit\Framework\ExpectationFailedException; diff --git a/src/Asserts/Content/AssertLinks.php b/src/Asserts/Content/AssertLinks.php index 342721c..2cbc754 100644 --- a/src/Asserts/Content/AssertLinks.php +++ b/src/Asserts/Content/AssertLinks.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\Assert as PHPUnit; use VGirol\JsonApiAssert\Constraint\LinkEqualsConstraint; +use VGirol\JsonApiAssert\Messages; /** * This trait adds the ability to test links objects. @@ -29,7 +30,14 @@ trait AssertLinks */ public static function assertLinksObjectEquals($expected, $links): void { - PHPUnit::assertEquals(count($expected), count($links)); + $countExpected = count($expected); + $count = count($links); + PHPUnit::assertEquals( + $countExpected, + $count, + sprintf(Messages::LINKS_OBJECT_HAVE_NOT_SAME_LENGTH, $count, $countExpected) + ); + foreach ($expected as $name => $value) { static::assertLinksObjectContains($name, $value, $links); } @@ -64,14 +72,13 @@ public static function assertLinksObjectContains($name, $expected, $links): void * * @param array|string|null $expected The expected link value * @param array|string|null $link The link to test - * @param string $message An optional message to explain why the test failed * * @return void * @throws \PHPUnit\Framework\ExpectationFailedException */ - public static function assertLinkObjectEquals($expected, $link, string $message = ''): void + public static function assertLinkObjectEquals($expected, $link): void { - PHPUnit::assertThat($link, self::linkEqualsConstraint($expected), $message); + PHPUnit::assertThat($link, self::linkEqualsConstraint($expected)); } /** diff --git a/src/Asserts/Content/AssertPagination.php b/src/Asserts/Content/AssertPagination.php index 738b5fd..9090258 100644 --- a/src/Asserts/Content/AssertPagination.php +++ b/src/Asserts/Content/AssertPagination.php @@ -7,6 +7,7 @@ use PHPUnit\Framework\Assert as PHPUnit; use VGirol\JsonApiAssert\Constraint\PaginationLinksEqualConstraint; use VGirol\JsonApiAssert\Members; +use VGirol\JsonApiAssert\Messages; /** * This trait adds the ability to test pagination (links and meta). @@ -76,7 +77,11 @@ public static function assertHasNoPaginationLinks($links): void */ public static function assertPaginationLinksEquals($expected, $json): void { - PHPUnit::assertThat($json, self::paginationLinksEqualConstraint($expected)); + PHPUnit::assertThat( + $json, + self::paginationLinksEqualConstraint($expected), + Messages::PAGINATION_LINKS_NOT_EQUAL + ); } /** diff --git a/src/Asserts/Content/AssertResource.php b/src/Asserts/Content/AssertResource.php index 5558e4f..76ff45c 100644 --- a/src/Asserts/Content/AssertResource.php +++ b/src/Asserts/Content/AssertResource.php @@ -61,10 +61,8 @@ public static function assertResourceCollectionEquals($expected, $json) sprintf(Messages::RESOURCE_COLLECTION_HAVE_NOT_SAME_LENGTH, $count, $expectedCount) ); - $index = 0; - foreach ($expected as $resource) { + foreach ($expected as $index => $resource) { static::assertResourceObjectEquals($resource, $json[$index]); - $index++; } } diff --git a/src/Asserts/Content/AssertResourceLinkage.php b/src/Asserts/Content/AssertResourceLinkage.php index 2606563..11e07a8 100644 --- a/src/Asserts/Content/AssertResourceLinkage.php +++ b/src/Asserts/Content/AssertResourceLinkage.php @@ -5,6 +5,7 @@ namespace VGirol\JsonApiAssert\Asserts\Content; use PHPUnit\Framework\Assert as PHPUnit; +use VGirol\JsonApiAssert\Messages; /** * This trait adds the ability to test resource linkage (single or collection). @@ -25,7 +26,11 @@ trait AssertResourceLinkage */ public static function assertResourceIdentifierEquals($expected, $json) { - PHPUnit::assertSame($expected, $json); + PHPUnit::assertSame( + $expected, + $json, + sprintf(Messages::RESOURCE_IDENTIFIER_IS_NOT_EQUAL, var_export($json, true), var_export($expected, true)) + ); } /** @@ -49,7 +54,14 @@ public static function assertResourceIdentifierEquals($expected, $json) public static function assertResourceIdentifierCollectionEquals($expected, $json) { static::assertIsArrayOfObjects($json); - PHPUnit::assertEquals(count($expected), count($json)); + + $expectedCount = count($expected); + $count = count($json); + PHPUnit::assertEquals( + $expectedCount, + $count, + sprintf(Messages::RESOURCE_LINKAGE_COLLECTION_HAVE_NOT_SAME_LENGTH, $count, $expectedCount) + ); $index = 0; foreach ($expected as $resource) { @@ -89,12 +101,16 @@ public static function assertResourceLinkageEquals($expected, $json, $strict) static::assertIsValidResourceLinkage($json, $strict); if ($expected === null) { - PHPUnit::assertNull($json); + PHPUnit::assertNull( + $json, + sprintf(Messages::RESOURCE_LINKAGE_MUST_BE_NULL, var_export($json, true)) + ); return; } - PHPUnit::assertNotNull($json); + PHPUnit::assertNotNull($json, Messages::RESOURCE_LINKAGE_MUST_NOT_BE_NULL); + /** @var array $json */ if (!static::isArrayOfObjects($expected)) { @@ -105,7 +121,7 @@ public static function assertResourceLinkageEquals($expected, $json, $strict) } if (count($expected) == 0) { - PHPUnit::assertEmpty($json); + PHPUnit::assertEmpty($json, Messages::RESOURCE_LINKAGE_COLLECTION_MUST_BE_EMPTY); return; } diff --git a/src/Constraint/PaginationLinksEqualConstraint.php b/src/Constraint/PaginationLinksEqualConstraint.php index 706ef95..5170415 100644 --- a/src/Constraint/PaginationLinksEqualConstraint.php +++ b/src/Constraint/PaginationLinksEqualConstraint.php @@ -6,7 +6,6 @@ use PHPUnit\Framework\Constraint\Constraint; use VGirol\JsonApiAssert\Constraint\LinkEqualsConstraint; -use VGirol\JsonApiAssert\Members; /** * A constraint class to assert that a link object equals an expected value. diff --git a/src/Messages.php b/src/Messages.php index 0ae5a10..83096e3 100644 --- a/src/Messages.php +++ b/src/Messages.php @@ -119,4 +119,18 @@ abstract class Messages 'Failed asserting that the resource collection length (%u) is equal to %u.'; const RESOURCE_IS_NOT_EQUAL = 'Failed asserting that the resource %s is equal to %s.'; + const PAGINATION_LINKS_NOT_EQUAL = + 'Failed asserting that pagination links equal expected values.'; + const RESOURCE_LINKAGE_COLLECTION_MUST_BE_EMPTY = + 'Failed asserting that the resource linkage collection is empty.'; + const RESOURCE_LINKAGE_COLLECTION_HAVE_NOT_SAME_LENGTH = + 'Failed asserting that the resource linkage collection length (%u) is equal to %u.'; + const RESOURCE_IDENTIFIER_IS_NOT_EQUAL = + 'Failed asserting that the resource identifier %s is equal to %s.'; + const RESOURCE_LINKAGE_MUST_BE_NULL = + 'Failed asserting that the resource linkage %s is null.'; + const RESOURCE_LINKAGE_MUST_NOT_BE_NULL = + 'Failed asserting that the resource linkage is not null.'; + const LINKS_OBJECT_HAVE_NOT_SAME_LENGTH = + 'Failed asserting that the links collection length (%u) is equal to %u.'; } diff --git a/src/SetExceptionsTrait.php b/src/SetExceptionsTrait.php index 6affd87..11360c1 100644 --- a/src/SetExceptionsTrait.php +++ b/src/SetExceptionsTrait.php @@ -46,6 +46,23 @@ abstract public function expectExceptionMessage(string $message): void; */ abstract public function expectExceptionMessageRegExp(string $messageRegExp): void; + + /** + * Set the expected exception and message when defining a test that will fail. + * + * @param string|null $message The failure message could be either a string or a regular expression. + * + * @return void + */ + protected function setFailure(?string $message = null) + { + if (($message !== null) && (strpos($message, '/') === 0)) { + $this->setFailureExceptionRegex($message); + } else { + $this->setFailureException($message); + } + } + /** * Set the expected exception and message when defining a test that will fail. * @@ -53,7 +70,7 @@ abstract public function expectExceptionMessageRegExp(string $messageRegExp): vo * * @return void */ - protected function setFailureException($message = null) + protected function setFailureException(?string $message = null) { $this->expectException(ExpectationFailedException::class); if ($message !== null) { @@ -68,7 +85,7 @@ protected function setFailureException($message = null) * * @return void */ - protected function setFailureExceptionRegex($message = null) + protected function setFailureExceptionRegex(?string $message = null) { $this->expectException(ExpectationFailedException::class); if ($message !== null) { @@ -100,4 +117,20 @@ protected function setInvalidArgumentException(int $arg, string $type, $value = ) ); } + + /** + * Format the failure message as a regular expression. + * + * @param string $message + * + * @return string + */ + protected function formatAsRegex(string $message): string + { + return '/' . preg_replace( + "!\%(\+?)('.|[0 ]|)(-?)([1-9][0-9]*|)(\.[1-9][0-9]*|)([%a-zA-Z])!u", + '.*', + preg_quote($message) + ) . '/s'; + } } diff --git a/tests/Asserts/Content/ErrorsTest.php b/tests/Asserts/Content/ErrorsTest.php index e9edb8b..9123334 100644 --- a/tests/Asserts/Content/ErrorsTest.php +++ b/tests/Asserts/Content/ErrorsTest.php @@ -56,7 +56,7 @@ public function errorsContains() */ public function errorsContainsFailed($expectedErrors, $errors, $strict, $failureMsg) { - $this->setFailureException($failureMsg); + $this->setFailure($failureMsg); Assert::assertErrorsContains($expectedErrors, $errors, $strict); } @@ -103,7 +103,7 @@ public function errorsContainsFailedProvider() ] ], false, - null + Messages::ERRORS_OBJECT_CONTAINS_NOT_ENOUGH_ERRORS ], 'expected error not present' => [ [ @@ -176,7 +176,7 @@ public function errorsContainsFailedProvider() ] ], false, - null + $this->formatAsRegex(Messages::ERRORS_OBJECT_DOES_NOT_CONTAIN_EXPECTED_ERROR) ] ]; } diff --git a/tests/Asserts/Content/IncludeTest.php b/tests/Asserts/Content/IncludeTest.php index 000adc7..defef72 100644 --- a/tests/Asserts/Content/IncludeTest.php +++ b/tests/Asserts/Content/IncludeTest.php @@ -68,7 +68,7 @@ public function includeObjectContainsFailed() ] ]; - $this->setFailureException(); + $this->setFailure(); Assert::assertIncludeObjectContains($expected, $json); } diff --git a/tests/Asserts/Content/JsonapiTest.php b/tests/Asserts/Content/JsonapiTest.php index 39f2729..29bda98 100644 --- a/tests/Asserts/Content/JsonapiTest.php +++ b/tests/Asserts/Content/JsonapiTest.php @@ -36,7 +36,7 @@ public function jsonapiObjectEqualsFailed() ] ]; - $this->setFailureException(); + $this->setFailure(); Assert::assertJsonapiObjectEquals($expected, $json); } diff --git a/tests/Asserts/Content/LinksTest.php b/tests/Asserts/Content/LinksTest.php index c314dbf..5ac386f 100644 --- a/tests/Asserts/Content/LinksTest.php +++ b/tests/Asserts/Content/LinksTest.php @@ -39,9 +39,9 @@ public function linkObjectEqualsProvider() * @test * @dataProvider linkObjectEqualsFailedProvider */ - public function linkObjectEqualsFailed($expected, $link, $failureMsg) + public function linkObjectEqualsFailed($expected, $link) { - $this->setFailureException($failureMsg); + $this->setFailure($this->formatAsRegex('Failed asserting that %s equals %s.')); Assert::assertLinkObjectEquals($expected, $link); } @@ -51,38 +51,31 @@ public function linkObjectEqualsFailedProvider() return [ 'must be null' => [ null, - 'not null', - null + 'not null' ], 'must not be null' => [ 'url', - null, null ], 'must have query string' => [ 'url?query=test', - 'url', - null + 'url' ], 'must not have query string' => [ 'url', - 'url?query=test', - null + 'url?query=test' ], 'not same url' => [ 'url1', - 'url2', - null + 'url2' ], 'not same count of query strings' => [ 'url?query1=test', - 'url?query1=test&query2=anything', - null + 'url?query1=test&query2=anything' ], 'not same query strings' => [ 'url?query1=test', - 'url?query1=anything', - null + 'url?query1=anything' ] ]; } @@ -107,7 +100,7 @@ public function linksObjectContains() */ public function linksObjectContainsFailed($name, $expected, $links, $failureMsg) { - $this->setFailureException($failureMsg); + $this->setFailure($failureMsg); Assert::assertLinksObjectContains($name, $expected, $links); } @@ -129,7 +122,7 @@ public function linksObjectContainsFailedProvider() [ 'self' => 'url1' ], - null + $this->formatAsRegex('Failed asserting that %s equals %s.') ] ]; } @@ -154,7 +147,7 @@ public function linksObjectEquals() */ public function linksObjectEqualsFailed($expected, $links, $failureMsg) { - $this->setFailureException($failureMsg); + $this->setFailure($failureMsg); Assert::assertLinksObjectEquals($expected, $links); } @@ -170,7 +163,7 @@ public function linksObjectEqualsFailedProvider() 'self' => 'url', 'anything' => 'url' ], - null + $this->formatAsRegex(Messages::LINKS_OBJECT_HAVE_NOT_SAME_LENGTH) ], 'link is not as expected' => [ [ @@ -179,7 +172,7 @@ public function linksObjectEqualsFailedProvider() [ 'self' => 'url2' ], - null + $this->formatAsRegex('Failed asserting that %s equals %s.') ] ]; } diff --git a/tests/Asserts/Content/PaginationTest.php b/tests/Asserts/Content/PaginationTest.php index 03a8d87..c4802ab 100644 --- a/tests/Asserts/Content/PaginationTest.php +++ b/tests/Asserts/Content/PaginationTest.php @@ -32,7 +32,7 @@ public function hasPaginationLinksFailed() 'self' => 'url' ]; - $this->setFailureException( + $this->setFailure( sprintf( Messages::CONTAINS_AT_LEAST_ONE, implode( @@ -72,7 +72,7 @@ public function hasNoPaginationLinksFailed() 'first' => 'urlFirst' ]; - $this->setFailureException( + $this->setFailure( sprintf(Messages::NOT_HAS_MEMBER, 'first') ); @@ -111,7 +111,7 @@ public function paginationLinksEqualsFailed($expected, $failureMsg) 'last' => 'urlLast' ]; - $this->setFailureException($failureMsg); + $this->setFailure($failureMsg); Assert::assertPaginationLinksEquals($expected, $json); } @@ -119,23 +119,23 @@ public function paginationLinksEqualsFailed($expected, $failureMsg) public function paginationLinksEqualsFailedProvider() { return [ - 'has not expected member' => [ + 'has too many members' => [ [ 'first' => 'urlFirst', 'next' => false, 'prev' => false, 'last' => 'urlLast' ], - null + Messages::PAGINATION_LINKS_NOT_EQUAL ], - 'not has expected member' => [ + 'has not all expected member' => [ [ 'first' => 'urlFirst', 'next' => 'urlNext', 'prev' => 'urlPrev', 'last' => 'urlLast' ], - null + Messages::PAGINATION_LINKS_NOT_EQUAL ], 'not same value' => [ [ @@ -144,7 +144,7 @@ public function paginationLinksEqualsFailedProvider() 'prev' => false, 'last' => 'urlLast' ], - null + Messages::PAGINATION_LINKS_NOT_EQUAL ] ]; } diff --git a/tests/Asserts/Content/ResourceLinkageTest.php b/tests/Asserts/Content/ResourceLinkageTest.php index c7bf976..b7d1eff 100644 --- a/tests/Asserts/Content/ResourceLinkageTest.php +++ b/tests/Asserts/Content/ResourceLinkageTest.php @@ -39,7 +39,7 @@ public function resourceIdentifierEqualsFailed() 'type' => 'test' ]; - $this->setFailureException(); + $this->setFailure(); Assert::assertResourceIdentifierEquals($expected, $json); } @@ -79,7 +79,7 @@ public function resourceIdentifierCollectionEquals() */ public function resourceIdentifierCollectionEqualsFailed($expected, $json, $failureMsg) { - $this->setFailureException($failureMsg); + $this->setFailure($failureMsg); Assert::assertResourceIdentifierCollectionEquals($expected, $json); } @@ -121,7 +121,7 @@ public function resourceIdentifierCollectionEqualsFailedProvider() 'type' => 'test' ] ], - null + $this->formatAsRegex(Messages::RESOURCE_LINKAGE_COLLECTION_HAVE_NOT_SAME_LENGTH) ], 'not same value' => [ [ @@ -144,7 +144,7 @@ public function resourceIdentifierCollectionEqualsFailedProvider() 'type' => 'test' ] ], - null + $this->formatAsRegex(Messages::RESOURCE_IDENTIFIER_IS_NOT_EQUAL) ] ]; } @@ -229,7 +229,7 @@ public function resourceLinkageEqualsProvider() */ public function resourceLinkageEqualsFailed($expected, $json, $strict, $failureMsg) { - $this->setFailureException($failureMsg); + $this->setFailure($failureMsg); Assert::assertResourceLinkageEquals($expected, $json, $strict); } @@ -250,7 +250,7 @@ public function resourceLinkageEqualsFailedProvider() 'type' => 'test' ], true, - null + $this->formatAsRegex(Messages::RESOURCE_LINKAGE_MUST_BE_NULL) ], 'is null but resource identifier expected' => [ [ @@ -259,7 +259,7 @@ public function resourceLinkageEqualsFailedProvider() ], null, true, - null + Messages::RESOURCE_LINKAGE_MUST_NOT_BE_NULL ], 'is not a single resource identifier' => [ [ @@ -289,7 +289,7 @@ public function resourceLinkageEqualsFailedProvider() 'type' => 'test' ], true, - null + $this->formatAsRegex(Messages::RESOURCE_IDENTIFIER_IS_NOT_EQUAL) ], 'is not empty collection as expected' => [ [], @@ -298,7 +298,7 @@ public function resourceLinkageEqualsFailedProvider() 'type' => 'test' ], true, - null + Messages::RESOURCE_LINKAGE_COLLECTION_MUST_BE_EMPTY ], 'is not same collection' => [ [ @@ -322,7 +322,7 @@ public function resourceLinkageEqualsFailedProvider() ] ], true, - null + $this->formatAsRegex(Messages::RESOURCE_IDENTIFIER_IS_NOT_EQUAL) ] ]; } diff --git a/tests/Asserts/Content/ResourceTest.php b/tests/Asserts/Content/ResourceTest.php index de7914b..b6c8865 100644 --- a/tests/Asserts/Content/ResourceTest.php +++ b/tests/Asserts/Content/ResourceTest.php @@ -51,7 +51,7 @@ public function resourceObjectEqualsFailed() ] ]; - $this->setFailureException( + $this->setFailure( sprintf(Messages::RESOURCE_IS_NOT_EQUAL, var_export($json, true), var_export($expected, true)) ); @@ -146,7 +146,7 @@ public function resourceCollectionContainsFailed() ] ]; - $this->setFailureException(); + $this->setFailure(); Assert::assertResourceCollectionContains($expected, $json); } @@ -201,7 +201,7 @@ public function resourceCollectionEqualsFailed($expected, $failureMsg) ] ]; - $this->setFailureException($failureMsg); + $this->setFailure($failureMsg); Assert::assertResourceCollectionEquals($expected, $json); } @@ -248,7 +248,7 @@ public function resourceCollectionEqualsFailedProvider() ] ] ], - null + $this->formatAsRegex(Messages::RESOURCE_IS_NOT_EQUAL) ] ]; } diff --git a/tests/Asserts/Structure/ArrayTest.php b/tests/Asserts/Structure/ArrayTest.php index 0c657e9..68582df 100644 --- a/tests/Asserts/Structure/ArrayTest.php +++ b/tests/Asserts/Structure/ArrayTest.php @@ -41,7 +41,7 @@ public function arrayOfObjectsProvider() */ public function assertIsArrayOfObjectsFailed($data, $message, $failureMessage) { - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertIsArrayOfObjects($data, $message); } @@ -105,9 +105,9 @@ public function assertIsNotArrayOfObjectsFailed() 'first' => 'jsonapi' ] ]; - $failureMessage = null; + $failureMessage = Messages::MUST_NOT_BE_ARRAY_OF_OBJECTS; - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertIsNotArrayOfObjects($data); } diff --git a/tests/Asserts/Structure/AttributesObjectTest.php b/tests/Asserts/Structure/AttributesObjectTest.php index 1ed4071..e3cf138 100644 --- a/tests/Asserts/Structure/AttributesObjectTest.php +++ b/tests/Asserts/Structure/AttributesObjectTest.php @@ -22,8 +22,8 @@ public function memberNameIsNotForbidden() */ public function memberNameIsForbidden($data, $failureMessage) { - $this->setFailureException($failureMessage); - JsonApiAssert::assertIsNotForbiddenMemberName($data); + $this->setFailure($failureMessage); + JsonApiAssert::assertIsNotForbiddenMemberName($data); } public function forbiddenMemberNameProvider() @@ -70,7 +70,7 @@ public function fieldHasNoForbiddenMemberName() */ public function fieldHasForbiddenMemberName($data, $failureMessage) { - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertFieldHasNoForbiddenMemberName($data); } @@ -129,7 +129,7 @@ public function validAttributesObjectProvider() */ public function attributesObjectIsNotValid($json, $strict, $failureMessage) { - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertIsValidAttributesObject($json, $strict); } diff --git a/tests/Asserts/Structure/ErrorsObjectTest.php b/tests/Asserts/Structure/ErrorsObjectTest.php index f44f19e..bbc98c5 100644 --- a/tests/Asserts/Structure/ErrorsObjectTest.php +++ b/tests/Asserts/Structure/ErrorsObjectTest.php @@ -26,7 +26,7 @@ public function errorLinksObjectIsValid() */ public function errorLinksObjectIsNotValid($json, $strict, $failureMessage) { - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertIsValidErrorLinksObject($json, $strict); } @@ -76,7 +76,7 @@ public function validErrorSourceObjectProvider() */ public function errorSourceObjectIsNotValid($data, $failureMessage) { - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertIsValidErrorSourceObject($data); } @@ -144,7 +144,7 @@ public function errorObjectIsValid() */ public function errorObjectIsNotValid($data, $strict, $failureMessage) { - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertIsValidErrorObject($data, $strict); } @@ -288,7 +288,7 @@ public function errorsObjectIsValid() */ public function errorsObjectIsNotValid($data, $strict, $failureMessage) { - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertIsValidErrorsObject($data, $strict); } @@ -305,22 +305,24 @@ public function notValidErrorsObjectProvider() 'error object not valid' => [ [ [ - 'code' => 'E13', - '+not' => 'not valid', + 'status' => 666, + 'code' => 'E13' ] ], false, - null + Messages::ERROR_STATUS_IS_NOT_STRING ], 'error object not safe' => [ [ [ 'code' => 'E13', - 'not valid' => 'not valid', + 'meta' => [ + 'not valid' => 'not valid' + ] ] ], true, - null + Messages::MEMBER_NAME_HAVE_RESERVED_CHARACTERS ] ]; } diff --git a/tests/Asserts/Structure/IncludedTest.php b/tests/Asserts/Structure/IncludedTest.php index a214551..883c18d 100644 --- a/tests/Asserts/Structure/IncludedTest.php +++ b/tests/Asserts/Structure/IncludedTest.php @@ -78,7 +78,7 @@ public function compoundDocumentIsValid() */ public function compoundDocumentIsNotValid($json, $strict, $failureMessage) { - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertIsValidIncludedCollection($json['included'], $json['data'], $strict); } diff --git a/tests/Asserts/Structure/JsonapiObjectTest.php b/tests/Asserts/Structure/JsonapiObjectTest.php index 3b374c7..f976351 100644 --- a/tests/Asserts/Structure/JsonapiObjectTest.php +++ b/tests/Asserts/Structure/JsonapiObjectTest.php @@ -29,7 +29,7 @@ public function jsonapiObjectIsValid() */ public function jsonapiObjectIsNotValid($data, $strict, $failureMessage) { - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertIsValidJsonapiObject($data, $strict); } diff --git a/tests/Asserts/Structure/LinksObjectTest.php b/tests/Asserts/Structure/LinksObjectTest.php index b0bd3dc..9224c78 100644 --- a/tests/Asserts/Structure/LinksObjectTest.php +++ b/tests/Asserts/Structure/LinksObjectTest.php @@ -45,7 +45,7 @@ public function validLinkObjectProvider() */ public function linkObjectIsNotValid($data, $strict, $failureMessage) { - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertIsValidLinkObject($data, $strict); } @@ -117,7 +117,7 @@ public function linksObjectIsValid() */ public function linksObjectIsNotValid($data, $allowed, $strict, $failureMessage) { - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertIsValidLinksObject($data, $allowed, $strict); } diff --git a/tests/Asserts/Structure/MemberNameTest.php b/tests/Asserts/Structure/MemberNameTest.php index d326198..2e62913 100644 --- a/tests/Asserts/Structure/MemberNameTest.php +++ b/tests/Asserts/Structure/MemberNameTest.php @@ -40,7 +40,7 @@ public function validMemberNameProvider() */ public function memberNameIsNotValid($data, $strict, $failureMessage) { - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertIsValidMemberName($data, $strict); } diff --git a/tests/Asserts/Structure/MembersTest.php b/tests/Asserts/Structure/MembersTest.php index abd228f..79137a5 100644 --- a/tests/Asserts/Structure/MembersTest.php +++ b/tests/Asserts/Structure/MembersTest.php @@ -32,7 +32,7 @@ public function assertHasMemberFailed() ]; $failureMessage = sprintf(Messages::HAS_MEMBER, 'member'); - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertHasMember($expected, $json); } @@ -94,7 +94,7 @@ public function assertHasMembersFailed() $keys = ['meta', 'nothing']; $failureMessage = sprintf(Messages::HAS_MEMBER, 'nothing'); - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertHasMembers($keys, $data); } @@ -158,7 +158,7 @@ public function assertHasOnlyMembersFailed() $keys = ['meta', 'data']; $failureMessage = sprintf(Messages::HAS_ONLY_MEMBERS, implode(', ', $keys)); - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertHasOnlyMembers($keys, $data); } @@ -220,7 +220,7 @@ public function assertNotHasMemberFailed() $expected = 'anything'; $failureMessage = sprintf(Messages::NOT_HAS_MEMBER, $expected); - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertNotHasMember($expected, $data); } @@ -287,7 +287,7 @@ public function assertNotHasMembersFailed() ]; $failureMessage = sprintf(Messages::NOT_HAS_MEMBER, 'anything'); - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertNotHasMembers($expected, $data); } @@ -435,7 +435,7 @@ public function assertContainsAtLeastOneMemberFailed() ]; $failureMessage = sprintf(Messages::CONTAINS_AT_LEAST_ONE, implode(', ', $expected)); - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertContainsAtLeastOneMember($expected, $data); } @@ -465,7 +465,7 @@ public function assertContainsOnlyAllowedMembersFailed() ]; $failureMessage = Messages::ONLY_ALLOWED_MEMBERS; - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertContainsOnlyAllowedMembers($expected, $data); } } diff --git a/tests/Asserts/Structure/MetaObjectTest.php b/tests/Asserts/Structure/MetaObjectTest.php index a86644e..b2820bb 100644 --- a/tests/Asserts/Structure/MetaObjectTest.php +++ b/tests/Asserts/Structure/MetaObjectTest.php @@ -27,7 +27,7 @@ public function metaObjectIsValid() */ public function metaObjectIsNotValid($json, $strict, $failureMessage) { - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertIsValidMetaObject($json, $strict); } diff --git a/tests/Asserts/Structure/PrimaryDataTest.php b/tests/Asserts/Structure/PrimaryDataTest.php index 60d46c9..9f9ba9d 100644 --- a/tests/Asserts/Structure/PrimaryDataTest.php +++ b/tests/Asserts/Structure/PrimaryDataTest.php @@ -85,7 +85,7 @@ public function validPrimaryDataProvider() */ public function primaryDataIsNotValid($data, $strict, $failureMessage) { - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertIsValidPrimaryData($data, $strict); } diff --git a/tests/Asserts/Structure/RelationshipsObjectTest.php b/tests/Asserts/Structure/RelationshipsObjectTest.php index 6fbd509..7c847da 100644 --- a/tests/Asserts/Structure/RelationshipsObjectTest.php +++ b/tests/Asserts/Structure/RelationshipsObjectTest.php @@ -47,7 +47,7 @@ public function validRelationshipLinksObjectProvider() */ public function relationshipLinksObjectIsNotValid($json, $withPagination, $strict, $failureMessage) { - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertIsValidRelationshipLinksObject($json, $withPagination, $strict); } @@ -150,7 +150,7 @@ public function validRelationshipObjectProvider() */ public function relationshipObjectIsNotValid($data, $strict, $failureMessage) { - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertIsValidRelationshipObject($data, $strict); } @@ -263,7 +263,7 @@ public function relationshipsObjectIsValid() */ public function relationshipsObjectIsNotValid($data, $strict, $failureMessage) { - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertIsValidRelationshipsObject($data, $strict); } diff --git a/tests/Asserts/Structure/ResourceLinkageTest.php b/tests/Asserts/Structure/ResourceLinkageTest.php index a97ae5e..19b49c6 100644 --- a/tests/Asserts/Structure/ResourceLinkageTest.php +++ b/tests/Asserts/Structure/ResourceLinkageTest.php @@ -56,7 +56,7 @@ public function validResourceLinkageProvider() */ public function resourceLinkageIsNotValid($data, $strict, $failureMessage) { - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertIsValidResourceLinkage($data, $strict); } @@ -129,7 +129,7 @@ public function resourceIdentifierObjectIsValid() */ public function resourceIdentifierObjectIsNotValid($json, $strict, $failureMessage) { - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertIsValidResourceIdentifierObject($json, $strict); } diff --git a/tests/Asserts/Structure/ResourceObjectTest.php b/tests/Asserts/Structure/ResourceObjectTest.php index 39fd608..fbaae9c 100644 --- a/tests/Asserts/Structure/ResourceObjectTest.php +++ b/tests/Asserts/Structure/ResourceObjectTest.php @@ -24,7 +24,7 @@ public function resourceFieldNameIsNotForbidden() */ public function resourceFieldNameIsForbidden($name, $failureMessage) { - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertIsNotForbiddenResourceFieldName($name); } @@ -61,7 +61,7 @@ public function resourceLinksObjectIsValid() */ public function resourceLinksObjectIsNotValid($json, $strict, $failureMessage) { - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertIsValidResourceLinksObject($json, $strict); } @@ -118,7 +118,7 @@ public function resourceHasValidTopLevelStructure() */ public function resourceHasNotValidTopLevelStructure($json, $failureMessage) { - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertResourceObjectHasValidTopLevelStructure($json); } @@ -190,7 +190,7 @@ public function resourceIdMemberIsValid() */ public function resourceIdMemberIsNotValid($json, $failureMessage) { - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertResourceIdMember($json); } @@ -234,7 +234,7 @@ public function resourceTypeMemberIsValid() */ public function resourceTypeMemberIsNotValid($json, $strict, $failureMessage) { - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertResourceTypeMember($json, $strict); } @@ -306,7 +306,7 @@ public function resourceFieldIsValid() */ public function resourceFieldIsNotValid($json, $failureMessage) { - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertHasValidFields($json); } @@ -404,7 +404,7 @@ public function resourceObjectIsValid() */ public function resourceObjectIsNotValid($json, $strict, $failureMessage) { - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertIsValidResourceObject($json, $strict); } @@ -592,7 +592,7 @@ public function resourceObjectCollectionIsValid() */ public function resourceObjectCollectionIsNotValid($json, $strict, $failureMessage) { - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertIsValidResourceObjectCollection($json, $strict); } diff --git a/tests/Asserts/Structure/StructureTest.php b/tests/Asserts/Structure/StructureTest.php index 23ae6a5..1fb8361 100644 --- a/tests/Asserts/Structure/StructureTest.php +++ b/tests/Asserts/Structure/StructureTest.php @@ -90,7 +90,7 @@ public function validStructureProvider() */ public function documentHasNotValidStructure($data, $strict, $failureMessage) { - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertHasValidStructure($data, $strict); } @@ -226,7 +226,7 @@ public function topLevelLinksObjectIsValid() */ public function topLevelLinksObjectIsNotValid($json, $strict, $failureMessage) { - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertIsValidTopLevelLinksMember($json, $strict); } diff --git a/tests/Asserts/Structure/TopLevelMembersTest.php b/tests/Asserts/Structure/TopLevelMembersTest.php index fcef33f..a56f00e 100644 --- a/tests/Asserts/Structure/TopLevelMembersTest.php +++ b/tests/Asserts/Structure/TopLevelMembersTest.php @@ -44,7 +44,7 @@ public function documentHasValidTopLevelMembers() */ public function documentHasNotValidTopLevelMembers($data, $failureMessage) { - $this->setFailureException($failureMessage); + $this->setFailure($failureMessage); JsonApiAssert::assertHasValidTopLevelMembers($data); } diff --git a/tests/Constraints/ContainsAtLeastOneTest.php b/tests/Constraints/ContainsAtLeastOneTest.php index efcf3ac..ccf84cf 100644 --- a/tests/Constraints/ContainsAtLeastOneTest.php +++ b/tests/Constraints/ContainsAtLeastOneTest.php @@ -62,7 +62,7 @@ public function assertContainsAtLeastOneFailedAndThrowException() $constraint = new ContainsAtLeastOneConstraint($allowed); - $this->setFailureExceptionRegex(sprintf( + $this->setFailure(sprintf( '/Failed asserting that [\S\s]* %s\./', $constraint->toString() )); diff --git a/tests/Constraints/ContainsOnlyAllowedMembersTest.php b/tests/Constraints/ContainsOnlyAllowedMembersTest.php index 120bfbd..292ea9a 100644 --- a/tests/Constraints/ContainsOnlyAllowedMembersTest.php +++ b/tests/Constraints/ContainsOnlyAllowedMembersTest.php @@ -63,7 +63,7 @@ public function assertContainsOnlyAllowedMembersThrowsException() $constraint = new ContainsOnlyAllowedMembersConstraint($allowed); - $this->setFailureExceptionRegex( + $this->setFailure( sprintf( '/Failed asserting that [\S\s]* %s\./', $constraint->toString()