From 4b98ddf6a695c5b70cfc7443e934088b65d03c0b Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 19 Nov 2023 17:56:33 +0900 Subject: [PATCH] test: use HTTP\Method constants --- tests/system/CodeIgniterTest.php | 5 +- tests/system/Router/RouteCollectionTest.php | 73 +++++++++++---------- tests/system/Router/RouterTest.php | 3 +- 3 files changed, 42 insertions(+), 39 deletions(-) diff --git a/tests/system/CodeIgniterTest.php b/tests/system/CodeIgniterTest.php index 948e9c2dcd5d..5d12863604f6 100644 --- a/tests/system/CodeIgniterTest.php +++ b/tests/system/CodeIgniterTest.php @@ -14,6 +14,7 @@ use CodeIgniter\Config\Services; use CodeIgniter\Exceptions\ConfigException; use CodeIgniter\Exceptions\PageNotFoundException; +use CodeIgniter\HTTP\Method; use CodeIgniter\HTTP\Response; use CodeIgniter\Router\Exceptions\RedirectException; use CodeIgniter\Router\RouteCollection; @@ -721,7 +722,7 @@ public function testSpoofRequestMethodCanUsePUT(): void $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1'; $_SERVER['REQUEST_METHOD'] = 'POST'; - $_POST['_method'] = 'PUT'; + $_POST['_method'] = Method::PUT; $routes = \Config\Services::routes(); $routes->setDefaultNamespace('App\Controllers'); @@ -733,7 +734,7 @@ public function testSpoofRequestMethodCanUsePUT(): void $this->codeigniter->run(); ob_get_clean(); - $this->assertSame('PUT', Services::incomingrequest()->getMethod()); + $this->assertSame(Method::PUT, Services::incomingrequest()->getMethod()); } public function testSpoofRequestMethodCannotUseGET(): void diff --git a/tests/system/Router/RouteCollectionTest.php b/tests/system/Router/RouteCollectionTest.php index 32989e952d57..06ab63f3e151 100644 --- a/tests/system/Router/RouteCollectionTest.php +++ b/tests/system/Router/RouteCollectionTest.php @@ -15,6 +15,7 @@ use CodeIgniter\Config\Services; use CodeIgniter\controller; use CodeIgniter\Exceptions\PageNotFoundException; +use CodeIgniter\HTTP\Method; use CodeIgniter\Test\CIUnitTestCase; use Config\Modules; use Config\Routing; @@ -144,7 +145,7 @@ public function testAddIgnoresDefaultNamespaceWhenExists(): void public function testAddWorksWithCurrentHTTPMethods(): void { - Services::request()->setMethod('GET'); + Services::request()->setMethod(Method::GET); $routes = $this->getCollector(); @@ -176,7 +177,7 @@ public function testAddWithLeadingSlash(): void public function testMatchIgnoresInvalidHTTPMethods(): void { - Services::request()->setMethod('GET'); + Services::request()->setMethod(Method::GET); $routes = $this->getCollector(); @@ -189,7 +190,7 @@ public function testMatchIgnoresInvalidHTTPMethods(): void public function testAddWorksWithArrayOFHTTPMethods(): void { - Services::request()->setMethod('POST'); + Services::request()->setMethod(Method::POST); $routes = $this->getCollector(); @@ -696,7 +697,7 @@ public function testPresenterScaffoldsCorrectly(): void public function testResourcesWithCustomController(): void { - Services::request()->setMethod('GET'); + Services::request()->setMethod(Method::GET); $routes = $this->getCollector(); $routes->resource('photos', ['controller' => '