Skip to content

Commit

Permalink
bump coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
rodber committed Jan 11, 2025
1 parent 13b4ff8 commit 13b8428
Show file tree
Hide file tree
Showing 7 changed files with 227 additions and 9 deletions.
9 changes: 0 additions & 9 deletions src/Headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace Chevere\Http;

use Chevere\DataStructure\Interfaces\VectoredInterface;
use Chevere\DataStructure\Interfaces\VectorInterface;
use Chevere\DataStructure\Traits\VectorTrait;
use Chevere\DataStructure\Vector;

Expand Down Expand Up @@ -55,12 +54,4 @@ public function toArray(): array

return $return;
}

/**
* @return VectorInterface<Headers>
*/
public function vector(): VectorInterface
{
return $this->vector;
}
}
40 changes: 40 additions & 0 deletions tests/Attributes/DescriptionTests.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/*
* This file is part of Chevere.
*
* (c) Rodolfo Berrios <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Chevere\Tests\Attributes;

use Chevere\Http\Attributes\Description;
use PHPUnit\Framework\TestCase;

final class DescriptionTests extends TestCase
{
public function testConstruct(): void
{
$description = 'Test description';
$attribute = new Description($description);
$this->assertSame($description, $attribute->description);
}

public function testConstructDefault(): void
{
$attribute = new Description();
$this->assertSame('', $attribute->description);
}

public function testToString(): void
{
$description = 'Test description';
$attribute = new Description($description);
$this->assertSame($description, (string) $attribute);
}
}
74 changes: 74 additions & 0 deletions tests/Attributes/RequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

/*
* This file is part of Chevere.
*
* (c) Rodolfo Berrios <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Chevere\Tests\Attributes;

use Chevere\Http\Attributes\Request;
use Chevere\Http\Header;
use Chevere\Http\Headers;
use PHPUnit\Framework\TestCase;

final class RequestTest extends TestCase
{
public function testConstructEmpty(): void
{
$request = new Request();
$this->assertCount(0, $request->headers);
}

/**
* @dataProvider provideConstructWithHeaders
*/
public function testConstructWithHeaders(
array $headers,
array $expectLines
): void {
$objects = [];
foreach ($headers as $name => $header) {
$objects[] = new Header($name, $header);
}
$request = new Request(...$objects);
$this->assertCount(count($headers), $request->headers);
$array =
$this->assertSame(
$headers,
$request->headers->toArray()
);
$this->assertSame(
$expectLines,
$request->headers->toLines()
);
}

public static function provideConstructWithHeaders(): array
{
return [
[
[
'Content-Type' => 'application/json',
'X-Key' => 'x-value',
],
[
'Content-Type: application/json',
'X-Key: x-value',
],
],
];
}

public function testHeadersInstance(): void
{
$request = new Request();
$this->assertInstanceOf(Headers::class, $request->headers);
}
}
9 changes: 9 additions & 0 deletions tests/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Chevere\Tests\src\AcceptOptionalController;
use Chevere\Tests\src\NullController;
use InvalidArgumentException;
use Nyholm\Psr7\Response;
use OutOfBoundsException;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -147,4 +148,12 @@ public function testAcceptFileMissingKey(): void
'404' => [],
]);
}

public function testTerminate(): void
{
$controller = new AcceptController();
$response = new Response();
$terminate = $controller->terminate($response);
$this->assertSame($response, $terminate);
}
}
69 changes: 69 additions & 0 deletions tests/UsesAttributesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

/*
* This file is part of Chevere.
*
* (c) Rodolfo Berrios <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Chevere\Tests;

use Chevere\Http\Attributes\Description;
use Chevere\Http\Attributes\Request;
use Chevere\Http\Attributes\Response;
use Chevere\Http\Header;
use Chevere\Http\Status;
use Chevere\Tests\src\UsesAttributes;
use PHPUnit\Framework\TestCase;
use function Chevere\Http\descriptionAttribute;
use function Chevere\Http\requestAttribute;
use function Chevere\Http\responseAttribute;

final class UsesAttributesTest extends TestCase
{
public function testDescription(): void
{
$description = descriptionAttribute(UsesAttributes::class);
$this->assertEquals(
new Description('This is a description'),
$description->__toString()
);
}

public function testRequest(): void
{
$request = requestAttribute(UsesAttributes::class);
$this->assertEquals(
new Request(
new Header('foo', 'bar'),
),
$request
);
}

public function testResponse(): void
{
$response = responseAttribute(UsesAttributes::class);
$status = new Status(200, 400);
$headerDisposition = new Header('Content-Disposition', 'attachment');
$headerType = new Header('Content-Type', 'text/html; charset=UTF-8');
$this->assertEquals(
new Response($status, $headerDisposition, $headerType),
$response
);
$this->assertCount(3, $response);
$this->assertEquals(
[
'status' => $status,
'Content-Disposition' => $headerDisposition,
'Content-Type' => $headerType,
],
$response->toArray()
);
}
}
2 changes: 2 additions & 0 deletions tests/src/AcceptController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Chevere\Tests\src;

use Chevere\Http\Attributes\Description;
use Chevere\Http\Attributes\Request;
use Chevere\Http\Attributes\Response;
use Chevere\Http\Controller;
Expand All @@ -25,6 +26,7 @@
use function Chevere\Parameter\file;
use function Chevere\Parameter\string;

#[Description('This is a description')]
#[Request(
new Header('foo', 'bar'),
)]
Expand Down
33 changes: 33 additions & 0 deletions tests/src/UsesAttributes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/*
* This file is part of Chevere.
*
* (c) Rodolfo Berrios <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Chevere\Tests\src;

use Chevere\Http\Attributes\Description;
use Chevere\Http\Attributes\Request;
use Chevere\Http\Attributes\Response;
use Chevere\Http\Header;
use Chevere\Http\Status;

#[Description('This is a description')]
#[Request(
new Header('foo', 'bar'),
)]
#[Response(
new Status(200, 400),
new Header('Content-Disposition', 'attachment'),
new Header('Content-Type', 'text/html; charset=UTF-8'),
)]
final class UsesAttributes
{
}

0 comments on commit 13b8428

Please sign in to comment.