Skip to content

Commit

Permalink
Add a silent response
Browse files Browse the repository at this point in the history
  • Loading branch information
Dropelikeit committed Aug 24, 2023
1 parent 43d683d commit a096d9c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Contracts/ResponseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ public function create(object $jmsResponse): Response;
* @return Response
*/
public function createFromArray(array $jmsResponse): Response;

/**
* @description Create a response without a body
*/
public function createQuietResponse(): Response;
}
5 changes: 5 additions & 0 deletions src/Http/Responses/ResponseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public function createFromArray(array $jmsResponse): Response
return $this->getResponse($content);
}

public function createQuietResponse(): Response
{
return new LaravelResponse(status: Code::HTTP_CODE_NO_CONTENT);
}

/**
* @psalm-param non-empty-string $content
*/
Expand Down
13 changes: 13 additions & 0 deletions tests/Http/Responses/ResponseFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use JMS\Serializer\SerializationContext;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Illuminate\Http\Response as LaravelResponse;

/**
* @author Marcel Strahl <info@marcel-strahl.de>
Expand Down Expand Up @@ -308,4 +309,16 @@ public function canNotCreateWithUnknownSerializeType(): void
/** @phpstan-ignore-next-line */
$responseFactory->withSerializeType('array');
}

/**
* @test
*/
public function canCreateQuietResponse(): void
{
$responseFactory = new ResponseFactory((new Factory())->getSerializer($this->config), $this->config);

$response = $responseFactory->createQuietResponse();

$this->assertEquals(new LaravelResponse(status: 204), $response);
}
}

0 comments on commit a096d9c

Please sign in to comment.