Skip to content

Commit a750f45

Browse files
committed
fixed scopes except not working as expected
1 parent 4c8d21c commit a750f45

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

src/Routing/Route.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ protected function optionsApplyToControllerMethod(array $options)
203203
return true;
204204
} elseif (isset($options['only']) && in_array($this->method, $this->explodeOnPipes($options['only']))) {
205205
return true;
206-
} elseif (isset($options['except']) && in_array($this->method, $this->explodeOnPipes($options['except']))) {
207-
return false;
206+
} elseif (isset($options['except'])) {
207+
return ! in_array($this->method, $this->explodeOnPipes($options['except']));
208208
} elseif (in_array($this->method, $this->explodeOnPipes($options))) {
209209
return true;
210210
}

tests/Routing/RouteTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,27 @@ public function testControllerOptionsMergeAndOverrideRouteOptions()
7474
$this->assertEquals(20, $route->getRateExpiration(), 'Route did not setup rate limit expiration correctly.');
7575
$this->assertTrue($route->hasThrottle(), 'Route did not setup throttle correctly.');
7676
$this->assertInstanceOf('Dingo\Api\Tests\Stubs\BasicThrottleStub', $route->getThrottle(), 'Route did not setup throttle correctly.');
77+
78+
$route = new Route($this->adapter, $this->container, $request, [
79+
'uri' => 'foo/bar',
80+
'methods' => ['GET', 'HEAD'],
81+
'action' => [
82+
'scopes' => ['foo', 'bar'],
83+
'providers' => ['foo'],
84+
'limit' => 5,
85+
'expires' => 10,
86+
'throttle' => 'Foo',
87+
'version' => ['v1'],
88+
'conditionalRequest' => false,
89+
'uses' => 'Dingo\Api\Tests\Stubs\RoutingControllerStub@show',
90+
],
91+
]);
92+
93+
$this->assertEquals(['foo', 'bar', 'baz', 'bing', 'bob'], $route->scopes(), 'Route did not setup scopes correctly.');
94+
$this->assertEquals(['foo'], $route->getAuthProviders(), 'Route did not setup authentication providers correctly.');
95+
$this->assertEquals(10, $route->getRateLimit(), 'Route did not setup rate limit correctly.');
96+
$this->assertEquals(20, $route->getRateExpiration(), 'Route did not setup rate limit expiration correctly.');
97+
$this->assertTrue($route->hasThrottle(), 'Route did not setup throttle correctly.');
98+
$this->assertInstanceOf('Dingo\Api\Tests\Stubs\BasicThrottleStub', $route->getThrottle(), 'Route did not setup throttle correctly.');
7799
}
78100
}

tests/Stubs/RoutingControllerStub.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ public function index()
2525
return 'foo';
2626
}
2727

28+
public function show()
29+
{
30+
return 'bar';
31+
}
32+
2833
public function getIndex()
2934
{
3035
return 'foo';

0 commit comments

Comments
 (0)