for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace VGirol\JsonApiAssert;
use PHPUnit\Framework\Assert as PHPUnit;
use VGirol\JsonApiStructure\Exception\ValidationException;
use VGirol\JsonApiStructure\ValidateService;
/**
* This trait add the ability to call ValidateService.
*/
trait HaveValidationService
{
* Undocumented variable
*
* @var ValidateService
private static $service;
* Undocumented function
* @return ValidateService
protected static function getServiceInstance(): ValidateService
if (static::$service === null) {
$service
static
self
static::$service = static::createServiceInstance();
}
return static::$service;
* @param string $method
* @param mixed ...$args
* @return mixed
protected static function proxyService(string $method, ...$args)
$service = static::getServiceInstance();
return \call_user_func([$service, $method], ...$args);
* @return void
protected static function askService(string $method, ...$args): void
try {
static::proxyService($method, ...$args);
static::succeed();
} catch (ValidationException $e) {
PHPUnit::fail($e->getMessage());
* @param string $message
* @throws \PHPUnit\Framework\AssertionFailedError
protected static function succeed(string $message = ''): void
PHPUnit::assertTrue(true, $message);
private static function createServiceInstance(): ValidateService
return new ValidateService();