This repository has been archived by the owner on Feb 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
335 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
declare (strict_types = 1); | ||
|
||
namespace VGirol\JsonApiAssert\Asserts\Content; | ||
|
||
trait AssertInclude | ||
{ | ||
/** | ||
* Asserts that an array of included resource objects contains a given resource object or collection. | ||
* | ||
* @param array $expected | ||
* @param array $json | ||
*/ | ||
public static function assertIncludeObjectContains($expected, $json) | ||
{ | ||
static::assertResourceCollectionContains($expected, $json); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace VGirol\JsonApiAssert\Constraint; | ||
|
||
use PHPUnit\Framework\Constraint\Constraint; | ||
|
||
/** | ||
* A constraint class to assert that a link object equals an expected value. | ||
*/ | ||
class LinkEqualsConstraint extends Constraint | ||
{ | ||
/** | ||
* @var string|null | ||
*/ | ||
private $expected; | ||
|
||
/** | ||
* Class constructor. | ||
* | ||
* @param string|null $expected | ||
*/ | ||
public function __construct($expected) | ||
{ | ||
$this->expected = $expected; | ||
} | ||
|
||
/** | ||
* Returns a string representation of the constraint. | ||
*/ | ||
public function toString(): string | ||
{ | ||
return \sprintf( | ||
'equals "%s"', | ||
$this->expected | ||
); | ||
} | ||
|
||
/** | ||
* Evaluates the constraint for parameter $other. Returns true if the | ||
* constraint is met, false otherwise. | ||
* | ||
* @param mixed $other value or object to evaluate | ||
*/ | ||
protected function matches($other): bool | ||
{ | ||
if (is_null($this->expected)) { | ||
return \is_null($other); | ||
} | ||
|
||
if (is_null($other)) { | ||
return false; | ||
} | ||
|
||
$linkElms = explode('?', $other); | ||
$expectedElms = explode('?', $this->expected); | ||
|
||
if (count($expectedElms) != count($linkElms)) { | ||
return false; | ||
} | ||
|
||
if ($expectedElms[0] != $linkElms[0]) { | ||
return false; | ||
} | ||
|
||
if (count($linkElms) == 1) { | ||
return true; | ||
} | ||
|
||
$expectedQuery = explode('&', $expectedElms[1]); | ||
$linkQuery = explode('&', $linkElms[1]); | ||
|
||
if (count($expectedQuery) != count($linkQuery)) { | ||
return false; | ||
} | ||
|
||
$diff = array_diff($expectedQuery, $linkQuery); | ||
|
||
return count($diff) === 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.