Skip to content

Commit

Permalink
use success instead of primary
Browse files Browse the repository at this point in the history
  • Loading branch information
rodber committed Jan 23, 2025
1 parent e077a4c commit a68f3d0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ class Status implements IteratorAggregate
public readonly array $other;

/**
* @param int $primary The primary status code
* @param int $success The success status code
* @param int ...$other Additional status codes `name: value,...`
*/
public function __construct(
public readonly int $primary = 200,
public readonly int $success = 200,
int ...$other
) {
$other = array_unique($other);
$search = array_search($primary, $other, true);
$search = array_search($success, $other, true);
if ($search !== false) {
unset($other[$search]);
}
Expand All @@ -64,7 +64,7 @@ public function __get(string $name): int
*/
public function getIterator(): Iterator
{
yield $this->primary;
yield $this->success;
foreach ($this->other as $status) {
yield $status;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function testGetResponse(): void
$this->assertEquals($attribute, $response->status);
$this->assertCount(0, $response->headers);
$response = responseAttribute(AcceptController::class);
$this->assertSame(200, $response->status->primary);
$this->assertSame(200, $response->status->success);
$this->assertSame([400], $response->status->other);
$contentDisposition = new Header('Content-Disposition', 'attachment');
$contentType = new Header('Content-Type', 'text/html; charset=UTF-8');
Expand Down
12 changes: 6 additions & 6 deletions tests/StatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class StatusTest extends TestCase
public function testDefault(): void
{
$status = new Status();
$this->assertSame(200, $status->primary);
$this->assertSame(200, $status->success);
$this->assertSame([], $status->other);
$this->assertSame([200], $status->toArray());
$this->expectException(RuntimeException::class);
Expand All @@ -37,39 +37,39 @@ public function testDefault(): void
public function testPrimary(): void
{
$status = new Status(200);
$this->assertSame(200, $status->primary);
$this->assertSame(200, $status->success);
$this->assertSame([], $status->other);
$this->assertSame([200], $status->toArray());
}

public function testPrimaryOverride(): void
{
$status = new Status(200, 200);
$this->assertSame(200, $status->primary);
$this->assertSame(200, $status->success);
$this->assertSame([], $status->other);
$this->assertSame([200], $status->toArray());
}

public function testOther(): void
{
$status = new Status(201, 400);
$this->assertSame(201, $status->primary);
$this->assertSame(201, $status->success);
$this->assertSame([400], $status->other);
$this->assertSame([201, 400], $status->toArray());
}

public function testOtherOverride(): void
{
$status = new Status(200, 400, 400);
$this->assertSame(200, $status->primary);
$this->assertSame(200, $status->success);
$this->assertSame([400], $status->other);
$this->assertSame([200, 400], $status->toArray());
}

public function testOtherNamed(): void
{
$status = new Status(200, bad: 400, notFound: 404);
$this->assertSame(200, $status->primary);
$this->assertSame(200, $status->success);
$this->assertSame(
[
'bad' => 400,
Expand Down

0 comments on commit a68f3d0

Please sign in to comment.