GetFromHeaderAttributeTest.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace Knuckles\Scribe\Tests\Strategies\Headers;
  3. use Knuckles\Camel\Extraction\ExtractedEndpointData;
  4. use Knuckles\Scribe\Attributes\Header;
  5. use Knuckles\Scribe\Extracting\Strategies\Headers\GetFromHeaderAttribute;
  6. use Knuckles\Scribe\Tools\DocumentationConfig;
  7. use PHPUnit\Framework\TestCase;
  8. use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
  9. use ReflectionClass;
  10. class GetFromHeaderAttributeTest extends TestCase
  11. {
  12. use ArraySubsetAsserts;
  13. /** @test */
  14. public function can_fetch_from_header_attribute()
  15. {
  16. $endpoint = new class extends ExtractedEndpointData {
  17. public function __construct(array $parameters = []) {}
  18. };
  19. $endpoint->controller = new ReflectionClass(\Knuckles\Scribe\Tests\Strategies\Headers\HeaderAttributeTestController::class);
  20. $endpoint->method = $endpoint->controller->getMethod('methodWithAttributes');
  21. $strategy = new GetFromHeaderAttribute(new DocumentationConfig([]));
  22. $results = $strategy($endpoint);
  23. $this->assertArraySubset([
  24. 'Api-Version' => 'v1',
  25. ], $results);
  26. $this->assertArrayHasKey('Some-Custom', $results);
  27. $this->assertNotEmpty($results['Some-Custom']);
  28. }
  29. }
  30. #[Header("Api-Version", "v1")]
  31. class HeaderAttributeTestController
  32. {
  33. #[Header("Some-Custom")]
  34. public function methodWithAttributes()
  35. {
  36. }
  37. }