Skip to content

Commit

Permalink
Merge pull request #1625 from mallardduck/patch-1
Browse files Browse the repository at this point in the history
Add new methods to satisfy Application contract for Laravel 5.8
  • Loading branch information
specialtactics authored Mar 2, 2019
2 parents 3d1c751 + 5a89236 commit df06656
Show file tree
Hide file tree
Showing 4 changed files with 258 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/Exception/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ public function report(Exception $exception)
$this->parentHandler->report($exception);
}

/**
* Determine if the exception should be reported.
*
* @param \Exception $e
*
* @return bool
*/
public function shouldReport(Exception $e)
{
return true;
}

/**
* Render an exception into an HTTP response.
*
Expand Down
43 changes: 43 additions & 0 deletions tests/ChecksLaravelVersionTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Dingo\Api\Tests;

use Dingo\Api\Tests\Stubs\ApplicationStub;
use Dingo\Api\Tests\Stubs\Application58Stub;

trait ChecksLaravelVersionTrait
{
public $installed_file_path = __DIR__.'/../vendor/composer/installed.json';
public $current_release = '5.8';

private function getFrameworkVersion()
{
$contents = file_get_contents($this->installed_file_path);
$parsed_data = json_decode($contents, true);
$just_laravel = array_filter($parsed_data, function ($val) {
if ('laravel/framework' === $val['name'] || 'laravel/lumen-framework' === $val['name']) {
return true;
}
});
$laravelVersion = array_map(function ($val) {
return $val['version'];
}, array_values($just_laravel))[0];

return $laravelVersion;
}

private function getApplicationStub()
{
$version = $this->getFrameworkVersion();
if ('dev-master' === $version) {
$version = $this->current_release;
}
$compared_versions = version_compare('5.8', $version);
// If comparison is Less Than, or Equal To, provide the 5.8 stub.
if ($compared_versions === -1 || $compared_versions === 0) {
return new Application58Stub;
}

return new ApplicationStub;
}
}
6 changes: 4 additions & 2 deletions tests/Http/Middleware/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Dingo\Api\Http\Validation\Accept;
use Dingo\Api\Http\Validation\Domain;
use Dingo\Api\Http\Validation\Prefix;
use Dingo\Api\Tests\Stubs\ApplicationStub;
use Dingo\Api\Tests\ChecksLaravelVersionTrait;
use Dingo\Api\Http\Parser\Accept as AcceptParser;
use Illuminate\Http\Request as IlluminateRequest;
use Illuminate\Events\Dispatcher as EventDispatcher;
Expand All @@ -28,9 +28,11 @@ class RequestTest extends TestCase
protected $events;
protected $middleware;

use ChecksLaravelVersionTrait;

public function setUp()
{
$this->app = new ApplicationStub;
$this->app = $this->getApplicationStub();
$this->router = m::mock(Router::class);
$this->validator = new RequestValidator($this->app);
$this->handler = m::mock(Handler::class);
Expand Down
199 changes: 199 additions & 0 deletions tests/Stubs/Application58Stub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
<?php

namespace Dingo\Api\Tests\Stubs;

use Illuminate\Container\Container;
use Illuminate\Contracts\Foundation\Application;

class Application58Stub extends Container implements Application
{
public function version()
{
return 'v1';
}

public function basePath()
{
//
}

public function bootstrapPath($path = '')
{
//
}

public function configPath($path = '')
{
//
}

public function databasePath($path = '')
{
//
}

public function environmentPath()
{
//
}

public function resourcePath($path = '')
{
//
}

public function storagePath()
{
//
}

public function environment(...$environments)
{
return 'testing';
}

public function runningInConsole()
{
//
}

public function runningUnitTests()
{
// TODO: Implement runningUnitTests() method.
}

public function isDownForMaintenance()
{
return false;
}

public function registerConfiguredProviders()
{
//
}

public function register($provider, $options = [], $force = false)
{
//
}

public function registerDeferredProvider($provider, $service = null)
{
//
}

public function resolveProvider($provider)
{
//
}

public function boot()
{
//
}

public function booting($callback)
{
//
}

public function booted($callback)
{
//
}

public function bootstrapWith(array $bootstrappers)
{
//
}

public function configurationIsCached()
{
//
}

public function detectEnvironment(\Closure $callback)
{
//
}

public function environmentFile()
{
//
}

public function environmentFilePath()
{
//
}

public function getCachedConfigPath()
{
//
}

public function getCachedServicesPath()
{
//
}

public function getCachedPackagesPath()
{
//
}

public function getCachedRoutesPath()
{
//
}

public function getLocale()
{
//
}

public function getNamespace()
{
//
}

public function getProviders($provider)
{
//
}

public function hasBeenBootstrapped()
{
//
}

public function loadDeferredProviders()
{
//
}

public function loadEnvironmentFrom($file)
{
//
}

public function routesAreCached()
{
//
}

public function setLocale($locale)
{
//
}

public function shouldSkipMiddleware()
{
//
}

public function terminate()
{
//
}
}

0 comments on commit df06656

Please sign in to comment.