Skip to content

Commit df06656

Browse files
Merge pull request dingo#1625 from mallardduck/patch-1
Add new methods to satisfy Application contract for Laravel 5.8
2 parents 3d1c751 + 5a89236 commit df06656

File tree

4 files changed

+258
-2
lines changed

4 files changed

+258
-2
lines changed

src/Exception/Handler.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ public function report(Exception $exception)
7878
$this->parentHandler->report($exception);
7979
}
8080

81+
/**
82+
* Determine if the exception should be reported.
83+
*
84+
* @param \Exception $e
85+
*
86+
* @return bool
87+
*/
88+
public function shouldReport(Exception $e)
89+
{
90+
return true;
91+
}
92+
8193
/**
8294
* Render an exception into an HTTP response.
8395
*
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace Dingo\Api\Tests;
4+
5+
use Dingo\Api\Tests\Stubs\ApplicationStub;
6+
use Dingo\Api\Tests\Stubs\Application58Stub;
7+
8+
trait ChecksLaravelVersionTrait
9+
{
10+
public $installed_file_path = __DIR__.'/../vendor/composer/installed.json';
11+
public $current_release = '5.8';
12+
13+
private function getFrameworkVersion()
14+
{
15+
$contents = file_get_contents($this->installed_file_path);
16+
$parsed_data = json_decode($contents, true);
17+
$just_laravel = array_filter($parsed_data, function ($val) {
18+
if ('laravel/framework' === $val['name'] || 'laravel/lumen-framework' === $val['name']) {
19+
return true;
20+
}
21+
});
22+
$laravelVersion = array_map(function ($val) {
23+
return $val['version'];
24+
}, array_values($just_laravel))[0];
25+
26+
return $laravelVersion;
27+
}
28+
29+
private function getApplicationStub()
30+
{
31+
$version = $this->getFrameworkVersion();
32+
if ('dev-master' === $version) {
33+
$version = $this->current_release;
34+
}
35+
$compared_versions = version_compare('5.8', $version);
36+
// If comparison is Less Than, or Equal To, provide the 5.8 stub.
37+
if ($compared_versions === -1 || $compared_versions === 0) {
38+
return new Application58Stub;
39+
}
40+
41+
return new ApplicationStub;
42+
}
43+
}

tests/Http/Middleware/RequestTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Dingo\Api\Http\Validation\Accept;
1313
use Dingo\Api\Http\Validation\Domain;
1414
use Dingo\Api\Http\Validation\Prefix;
15-
use Dingo\Api\Tests\Stubs\ApplicationStub;
15+
use Dingo\Api\Tests\ChecksLaravelVersionTrait;
1616
use Dingo\Api\Http\Parser\Accept as AcceptParser;
1717
use Illuminate\Http\Request as IlluminateRequest;
1818
use Illuminate\Events\Dispatcher as EventDispatcher;
@@ -28,9 +28,11 @@ class RequestTest extends TestCase
2828
protected $events;
2929
protected $middleware;
3030

31+
use ChecksLaravelVersionTrait;
32+
3133
public function setUp()
3234
{
33-
$this->app = new ApplicationStub;
35+
$this->app = $this->getApplicationStub();
3436
$this->router = m::mock(Router::class);
3537
$this->validator = new RequestValidator($this->app);
3638
$this->handler = m::mock(Handler::class);

tests/Stubs/Application58Stub.php

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
<?php
2+
3+
namespace Dingo\Api\Tests\Stubs;
4+
5+
use Illuminate\Container\Container;
6+
use Illuminate\Contracts\Foundation\Application;
7+
8+
class Application58Stub extends Container implements Application
9+
{
10+
public function version()
11+
{
12+
return 'v1';
13+
}
14+
15+
public function basePath()
16+
{
17+
//
18+
}
19+
20+
public function bootstrapPath($path = '')
21+
{
22+
//
23+
}
24+
25+
public function configPath($path = '')
26+
{
27+
//
28+
}
29+
30+
public function databasePath($path = '')
31+
{
32+
//
33+
}
34+
35+
public function environmentPath()
36+
{
37+
//
38+
}
39+
40+
public function resourcePath($path = '')
41+
{
42+
//
43+
}
44+
45+
public function storagePath()
46+
{
47+
//
48+
}
49+
50+
public function environment(...$environments)
51+
{
52+
return 'testing';
53+
}
54+
55+
public function runningInConsole()
56+
{
57+
//
58+
}
59+
60+
public function runningUnitTests()
61+
{
62+
// TODO: Implement runningUnitTests() method.
63+
}
64+
65+
public function isDownForMaintenance()
66+
{
67+
return false;
68+
}
69+
70+
public function registerConfiguredProviders()
71+
{
72+
//
73+
}
74+
75+
public function register($provider, $options = [], $force = false)
76+
{
77+
//
78+
}
79+
80+
public function registerDeferredProvider($provider, $service = null)
81+
{
82+
//
83+
}
84+
85+
public function resolveProvider($provider)
86+
{
87+
//
88+
}
89+
90+
public function boot()
91+
{
92+
//
93+
}
94+
95+
public function booting($callback)
96+
{
97+
//
98+
}
99+
100+
public function booted($callback)
101+
{
102+
//
103+
}
104+
105+
public function bootstrapWith(array $bootstrappers)
106+
{
107+
//
108+
}
109+
110+
public function configurationIsCached()
111+
{
112+
//
113+
}
114+
115+
public function detectEnvironment(\Closure $callback)
116+
{
117+
//
118+
}
119+
120+
public function environmentFile()
121+
{
122+
//
123+
}
124+
125+
public function environmentFilePath()
126+
{
127+
//
128+
}
129+
130+
public function getCachedConfigPath()
131+
{
132+
//
133+
}
134+
135+
public function getCachedServicesPath()
136+
{
137+
//
138+
}
139+
140+
public function getCachedPackagesPath()
141+
{
142+
//
143+
}
144+
145+
public function getCachedRoutesPath()
146+
{
147+
//
148+
}
149+
150+
public function getLocale()
151+
{
152+
//
153+
}
154+
155+
public function getNamespace()
156+
{
157+
//
158+
}
159+
160+
public function getProviders($provider)
161+
{
162+
//
163+
}
164+
165+
public function hasBeenBootstrapped()
166+
{
167+
//
168+
}
169+
170+
public function loadDeferredProviders()
171+
{
172+
//
173+
}
174+
175+
public function loadEnvironmentFrom($file)
176+
{
177+
//
178+
}
179+
180+
public function routesAreCached()
181+
{
182+
//
183+
}
184+
185+
public function setLocale($locale)
186+
{
187+
//
188+
}
189+
190+
public function shouldSkipMiddleware()
191+
{
192+
//
193+
}
194+
195+
public function terminate()
196+
{
197+
//
198+
}
199+
}

0 commit comments

Comments
 (0)