Skip to content

Commit

Permalink
Soothe sa
Browse files Browse the repository at this point in the history
  • Loading branch information
koriym committed Nov 14, 2021
1 parent 801a975 commit a2a09fc
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 42 deletions.
4 changes: 4 additions & 0 deletions src/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ public function __construct(
$this->linker = $linker;
}

/**
* @psalm-suppress UnevaluatedCode
*/
public function __toString(): string
{
try {
Expand All @@ -133,6 +136,7 @@ public function __toString(): string
} catch (Throwable $e) {
trigger_error($e->getMessage() . PHP_EOL . $e->getTraceAsString(), E_USER_ERROR);

/** @noinspection PhpUnreachableStatementInspection */
return '';
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/JsonSchema/Interceptor/JsonSchemaInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private function validateResponse(ResourceObject $ro, JsonSchema $jsonSchema): v
private function validateRo(ResourceObject $ro, string $schemaFile, JsonSchema $jsonSchema): void
{
/** @var array<stdClass>|false|stdClass $json */
$json = json_decode(json_encode($ro));
$json = json_decode((string) json_encode($ro));
/** @var array<stdClass>|stdClass $target */
$target = is_object($json) ? $this->getTarget($json, $jsonSchema) : $json;
$this->validate($target, $schemaFile);
Expand Down
6 changes: 6 additions & 0 deletions tests/Module/JsonSchemaFakeModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public function linkHeaderTest(): void
$this->assertSame('<http://example.com/schema/user.json>; rel="describedby"', $ro->headers['Link']);
}

/**
* @param class-string $class
*/
private function getRo(string $class): ResourceObject
{
$module = $this->getJsonSchemaModule();
Expand All @@ -91,6 +94,9 @@ private function getRo(string $class): ResourceObject
return $ro;
}

/**
* @param class-string $class
*/
private function getLinkHeaderRo(string $class): FakeUser
{
$jsonSchemaHost = 'http://example.com/schema/';
Expand Down
9 changes: 9 additions & 0 deletions tests/Module/JsonSchemaModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ public function linkHeaderTest(): void
$this->assertSame('<http://example.com/schema/user.json>; rel="describedby"', $ro->headers['Link']);
}

/**
* @param class-string $class
*/
private function createJsonSchemaException(string $class): JsonSchemaException
{
$ro = $this->getRo($class);
Expand All @@ -119,6 +122,9 @@ private function createJsonSchemaException(string $class): JsonSchemaException
throw new LogicException();
}

/**
* @param class-string $class
*/
private function getRo(string $class): ResourceObject
{
$module = $this->getJsonSchemaModule();
Expand All @@ -129,6 +135,9 @@ private function getRo(string $class): ResourceObject
return $ro;
}

/**
* @param class-string $class
*/
private function getLinkHeaderRo(string $class): ResourceObject
{
$jsonSchemaHost = 'http://example.com/schema/';
Expand Down
7 changes: 7 additions & 0 deletions tests/ResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use Ray\ServiceLocator\ServiceLocator;

use function assert;
use function serialize;
use function unserialize;

class ResourceTest extends TestCase
{
Expand Down Expand Up @@ -325,4 +327,9 @@ public function testOptions(): void
$this->assertInstanceOf(ResourceObject::class, $ro);
$this->assertSame('GET, POST, PUT, PATCH, DELETE', $ro->headers['Allow']);
}

public function testSerialize(): void
{
$this->assertInstanceOf(ResourceInterface::class, unserialize(serialize($this->resource)));
}
}
82 changes: 41 additions & 41 deletions vendor-bin/tools/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a2a09fc

Please # to comment.