Skip to content

Commit e99d727

Browse files
committed
Adjustment to method priority calculation on throwing a standard exception so as not to adjust priority score
1 parent c046b2f commit e99d727

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

features/bootstrap/FeatureContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ public function anIssue($issue)
492492
*/
493493
public function theMethodPriorityForShouldBe($methodName, $value)
494494
{
495-
preg_match('/\[([0-9-]+)\] '.$methodName.'/', (string)$this->resource, $matches);
495+
preg_match('/[\[ ]([0-9-]+)\] '.$methodName.' /', (string)$this->resource, $matches);
496496
if (!$matches)
497497
throw new Exception('"'.$methodName.'" not found');
498498
if ($matches[1] != $value)

features/resource.feature

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,45 @@ Feature: HTTP resource object
192192
And the method priority for "test2" should be "2"
193193
And the method priority for "test3" should be "1"
194194
And the method priority for "test4" should be "11"
195+
196+
Scenario: Conditions that throw exceptions should still generate the expected priority
197+
Given a class definition:
198+
"""
199+
/**
200+
* @uri /resource9
201+
*/
202+
class Resource9 extends Tonic\Resource {
203+
/**
204+
* @method get
205+
* @foo
206+
*/
207+
function test() {}
208+
function foo() {
209+
throw new Tonic\NotFoundException;
210+
}
211+
/**
212+
* @method get
213+
* @bar
214+
*/
215+
function test2() {}
216+
function bar() {
217+
throw new Tonic\UnauthorizedException;
218+
}
219+
/**
220+
* @method get
221+
* @baz
222+
*/
223+
function test3() {}
224+
function baz() {
225+
throw new Tonic\ConditionException;
226+
}
227+
}
228+
"""
229+
And the request URI of "/resource9"
230+
And the request method of "GET"
231+
When I create an application object
232+
And I create a request object
233+
And load the resource
234+
Then the method priority for "test" should be "1"
235+
And the method priority for "test2" should be "1"
236+
And the method priority for "test3" should be "-"

spec/DescribeTonicResource.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ function afterCondition()
5757
function hasQuerystring($name)
5858
{
5959
if (!isset($_GET[$name])) throw new Tonic\ConditionException;
60+
return true;
6061
}
6162

6263
function parameterCondition($param1, $param2)

src/Tonic/Resource.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ private function calculateMethodPriorities($resourceMetadata)
8181
}
8282
}
8383
if (!$success) {
84-
$methodPriorities[$key]['value']--;
8584
$methodPriorities[$key]['exception'] = $error;
8685
break;
8786
}

0 commit comments

Comments
 (0)