generated from chevere/package-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
227 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
} |