Skip to content

Commit

Permalink
Fixes internal request closures
Browse files Browse the repository at this point in the history
Fixes warning about abstract test class (just for neatness)
  • Loading branch information
specialtactics committed Jul 22, 2024
1 parent 64cc89a commit 35d3182
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ jobs:
fail-fast: false
matrix:
stability: [prefer-stable]
versions: [ { php: 8.1, laravel: 10 }, { php: 8.2, laravel: 10 }, { php: 8.3, laravel: 10 }, { php: 8.2, laravel: 11 }, { php: 8.3, laravel: 11 } ]
#versions: [ { php: 8.1, laravel: 10 }, { php: 8.2, laravel: 10 }, { php: 8.3, laravel: 10 }, { php: 8.2, laravel: 11 }, { php: 8.3, laravel: 11 } ]
versions: [ { php: 8.1, laravel: 10 }, { php: 8.2, laravel: 10 }, { php: 8.3, laravel: 10 } ]

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}

Expand Down
10 changes: 10 additions & 0 deletions src/Provider/DingoServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Dingo\Api\Provider;

use Illuminate\Routing\CallableDispatcher;
use Illuminate\Routing\Contracts\CallableDispatcher as CallableDispatcherContract;
use RuntimeException;
use Dingo\Api\Auth\Auth;
use Dingo\Api\Dispatcher;
Expand Down Expand Up @@ -55,6 +57,7 @@ public function register()
$this->registerExceptionHandler();

$this->registerDispatcher();
$this->registerCallableDispatcher();

$this->registerAuth();

Expand Down Expand Up @@ -145,6 +148,13 @@ public function registerDispatcher()
});
}

public function registerCallableDispatcher()
{
$this->app->singleton(CallableDispatcherContract::class, function ($app) {
return new CallableDispatcher($app);
});
}

/**
* Register the auth.
*
Expand Down
5 changes: 4 additions & 1 deletion tests/DispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\CallableDispatcher;
use Illuminate\Routing\Contracts\CallableDispatcher as CallableDispatcherContract;
use Illuminate\Support\Facades\Request as RequestFacade;
use Mockery as m;
use Symfony\Component\HttpKernel\Exception\GoneHttpException;
Expand Down Expand Up @@ -67,14 +69,15 @@ public function setUp(): void

$this->transformerFactory = new TransformerFactory($this->container, new TransformerStub);

$this->adapter = new RoutingAdapterStub;
$this->adapter = new RoutingAdapterStub($this->container);
$this->exception = m::mock(Handler::class);
$this->router = new Router($this->adapter, $this->exception, $this->container, null, null);

$this->auth = new Auth($this->router, $this->container, []);
$this->dispatcher = new Dispatcher($this->container, new Filesystem, $this->router, $this->auth);

app()->instance(\Illuminate\Routing\Router::class, $this->adapter);
$this->container->singleton(CallableDispatcherContract::class, CallableDispatcher::class);

$this->dispatcher->setSubtype('api');
$this->dispatcher->setStandardsTree('vnd');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Laravel\Lumen\Application;
use Mockery as m;

abstract class BaseAdapterTest extends BaseTestCase
abstract class BaseAdapterTestAbstract extends BaseTestCase
{
/**
* @var Container|Application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Illuminate\Events\Dispatcher;
use Illuminate\Routing\Router;

class LaravelTest extends BaseAdapterTest
class LaravelTestAbstract extends BaseAdapterTestAbstract
{
public function getAdapterInstance()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Illuminate\Http\Request;
use Laravel\Lumen\Application;

class LumenTest extends BaseAdapterTest
class LumenTestAbstract extends BaseAdapterTestAbstract
{
public function getAdapterInstance()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Mockery as m;
use Symfony\Component\HttpKernel\Exception\HttpException;

class RouterTest extends Adapter\BaseAdapterTest
class RouterTestAbstract extends Adapter\BaseAdapterTestAbstract
{
public function getAdapterInstance()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Dingo\Api\Tests\Stubs\RoutingControllerStub;
use Illuminate\Container\Container;

class UrlGeneratorTest extends Adapter\BaseAdapterTest
class UrlGeneratorTestAbstract extends Adapter\BaseAdapterTestAbstract
{
public function getAdapterInstance()
{
Expand Down
11 changes: 11 additions & 0 deletions tests/Stubs/RoutingAdapterStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ class RoutingAdapterStub implements Adapter

protected $patterns = [];

protected $container;

/**
* @param \Illuminate\Container\Container $container
*/
public function __construct(Container $container)
{
$this->container = $container;
}

public function dispatch(Request $request, $version)
{
$routes = $this->routes[$version];
Expand Down Expand Up @@ -75,6 +85,7 @@ public function addRoute(array $methods, array $versions, $uri, $action)

$route = new IlluminateRoute($methods, $uri, $action);
$this->addWhereClausesToRoute($route);
$route->setContainer($this->container);

foreach ($versions as $version) {
$this->routes[$version]->add($route);
Expand Down

0 comments on commit 35d3182

Please sign in to comment.