aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/AppFramework/Utility/ControllerMethodReflectorTest.php
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2023-11-17 14:04:09 +0100
committerArthur Schiwon <blizzz@arthur-schiwon.de>2023-11-24 12:46:38 +0100
commit3fa43a529bbef075364666c5122e7ad18d34de62 (patch)
treea74e60d3da87fb32222dcb1176747a35eff9f368 /tests/lib/AppFramework/Utility/ControllerMethodReflectorTest.php
parent7646f68cd7e4dcba44a1c54258a3fe2a0cf18a36 (diff)
downloadnextcloud-server-3fa43a529bbef075364666c5122e7ad18d34de62.tar.gz
nextcloud-server-3fa43a529bbef075364666c5122e7ad18d34de62.zip
enh(dispatcher): enforce psalm ranges in the http dispatcher
- allows devs to provide int ranges for API arguments Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'tests/lib/AppFramework/Utility/ControllerMethodReflectorTest.php')
-rw-r--r--tests/lib/AppFramework/Utility/ControllerMethodReflectorTest.php21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/lib/AppFramework/Utility/ControllerMethodReflectorTest.php b/tests/lib/AppFramework/Utility/ControllerMethodReflectorTest.php
index 5452fb853b9..2ba2f34425b 100644
--- a/tests/lib/AppFramework/Utility/ControllerMethodReflectorTest.php
+++ b/tests/lib/AppFramework/Utility/ControllerMethodReflectorTest.php
@@ -54,6 +54,14 @@ class MiddleController extends BaseController {
public function test3() {
}
+
+ /**
+ * @psalm-param int<-4, 42> $rangedOne
+ * @psalm-param int<min, max> $rangedTwo
+ * @return void
+ */
+ public function test4(int $rangedOne, int $rangedTwo) {
+ }
}
class EndController extends MiddleController {
@@ -234,4 +242,17 @@ class ControllerMethodReflectorTest extends \Test\TestCase {
$this->assertFalse($reader->hasAnnotation('Annotation'));
}
+
+ public function testRangeDetection() {
+ $reader = new ControllerMethodReflector();
+ $reader->reflect('Test\AppFramework\Utility\EndController', 'test4');
+
+ $rangeInfo1 = $reader->getRange('rangedOne');
+ $this->assertSame(-4, $rangeInfo1['min']);
+ $this->assertSame(42, $rangeInfo1['max']);
+
+ $rangeInfo2 = $reader->getRange('rangedTwo');
+ $this->assertSame(PHP_INT_MIN, $rangeInfo2['min']);
+ $this->assertSame(PHP_INT_MAX, $rangeInfo2['max']);
+ }
}