ScannerTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace EasySwoole\HttpAnnotation\Tests;
  3. use EasySwoole\HttpAnnotation\Tests\TestController\Normal;
  4. use EasySwoole\HttpAnnotation\Utility\Scanner;
  5. use FastRoute\DataGenerator\GroupCountBased;
  6. use FastRoute\RouteCollector;
  7. use FastRoute\RouteParser\Std;
  8. use PHPUnit\Framework\TestCase;
  9. class ScannerTest extends TestCase
  10. {
  11. function testGetFileDeclaredClass()
  12. {
  13. $class = Scanner::getFileDeclaredClass(__DIR__ . '/TestController/Normal.php');
  14. $this->assertEquals(Normal::class, $class);
  15. }
  16. function testScanAnnotations()
  17. {
  18. $scan = new Scanner();
  19. $array = $scan->scanAnnotations(__DIR__ . '/TestController');
  20. $this->assertEquals(7, count($array));
  21. }
  22. function testRouter()
  23. {
  24. $scan = new Scanner();
  25. $col = new RouteCollector(new Std(), new GroupCountBased());
  26. $scan->mappingRouter($col, __DIR__ . '/TestController', 'EasySwoole\HttpAnnotation\Tests\TestController');
  27. $this->assertEquals('/NoneAnnotation/exception', $col->getData()[0]['GET']['/testR']);
  28. }
  29. function testDeprecated()
  30. {
  31. $scan = new Scanner();
  32. $col = new RouteCollector(new Std(), new GroupCountBased());
  33. $scan->mappingRouter($col, __DIR__ . '/TestController', 'EasySwoole\HttpAnnotation\Tests\TestController');
  34. $this->assertArrayNotHasKey('/deprecated', $col->getData()[0]['GET']);
  35. }
  36. }