DingoGeneratorTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace Knuckles\Scribe\Tests\Unit;
  3. use Dingo\Api\Routing\Router;
  4. use Knuckles\Scribe\ScribeServiceProvider;
  5. use Knuckles\Scribe\Tests\Fixtures\TestController;
  6. /**
  7. * @group dingo
  8. */
  9. class DingoGeneratorTest extends GeneratorTestCase
  10. {
  11. protected function getPackageProviders($app)
  12. {
  13. return [
  14. ScribeServiceProvider::class,
  15. \Dingo\Api\Provider\LaravelServiceProvider::class,
  16. ];
  17. }
  18. public function setUp(): void
  19. {
  20. parent::setUp();
  21. config(['scribe.router' => 'dingo']);
  22. }
  23. public function createRoute(string $httpMethod, string $path, string $controllerMethod, $register = false, $class = TestController::class)
  24. {
  25. $route = null;
  26. /** @var Router $api */
  27. $api = app(Router::class);
  28. $api->version('v1', function (Router $api) use ($class, $controllerMethod, $path, $httpMethod, &$route) {
  29. $route = $api->$httpMethod($path, $class . "@$controllerMethod");
  30. });
  31. return $route;
  32. }
  33. public function createRouteUsesArray(string $httpMethod, string $path, string $controllerMethod, $register = false, $class = TestController::class)
  34. {
  35. $route = null;
  36. /** @var Router $api */
  37. $api = app(Router::class);
  38. $api->version('v1', function (Router $api) use ($class, $controllerMethod, $path, $httpMethod, &$route) {
  39. $route = $api->$httpMethod($path, [$class, $controllerMethod]);
  40. });
  41. return $route;
  42. }
  43. public function createRouteUsesCallable(string $httpMethod, string $path, callable $handler, $register = false)
  44. {
  45. $route = null;
  46. /** @var Router $api */
  47. $api = app(Router::class);
  48. $api->version('v1', function (Router $api) use ($handler, $path, $httpMethod, &$route) {
  49. $route = $api->$httpMethod($path, $handler);
  50. });
  51. return $route;
  52. }
  53. }