From 5af603cb217c233c4fe706239a9310f89c2ceeb5 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 13 Oct 2023 15:46:43 +0900 Subject: [PATCH 1/7] test: add test --- .../Router/DefinedRouteCollectorTest.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/system/Router/DefinedRouteCollectorTest.php b/tests/system/Router/DefinedRouteCollectorTest.php index ba74cec1a86a..976d74268a35 100644 --- a/tests/system/Router/DefinedRouteCollectorTest.php +++ b/tests/system/Router/DefinedRouteCollectorTest.php @@ -87,4 +87,45 @@ public function testCollect() ]; $this->assertSame($expected, $definedRoutes); } + + /** + * @see https://github.com/codeigniter4/CodeIgniter4/issues/8039 + */ + public function testCollectSameFromWithDifferentVerb() + { + $routes = $this->createRouteCollection(); + $routes->get('login', 'AuthController::showLogin', ['as' => 'loginShow']); + $routes->post('login', 'AuthController::login', ['as' => 'login']); + $routes->get('logout', 'AuthController::logout', ['as' => 'logout']); + + $collector = new DefinedRouteCollector($routes); + + $definedRoutes = []; + + foreach ($collector->collect() as $route) { + $definedRoutes[] = $route; + } + + $expected = [ + [ + 'method' => 'get', + 'route' => 'login', + 'name' => 'loginShow', + 'handler' => '\\App\\Controllers\\AuthController::showLogin', + ], + [ + 'method' => 'get', + 'route' => 'logout', + 'name' => 'logout', + 'handler' => '\\App\\Controllers\\AuthController::logout', + ], + [ + 'method' => 'post', + 'route' => 'login', + 'name' => 'login', + 'handler' => '\\App\\Controllers\\AuthController::login', + ], + ]; + $this->assertSame($expected, $definedRoutes); + } } From 68f8218b113f9648a43ff5298c6ce73518c54bc8 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 13 Oct 2023 15:47:00 +0900 Subject: [PATCH 2/7] fix: DefinedRouteCollector returns incorrect route data --- system/Router/DefinedRouteCollector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Router/DefinedRouteCollector.php b/system/Router/DefinedRouteCollector.php index 2b317d4cbc2a..f8e245d19723 100644 --- a/system/Router/DefinedRouteCollector.php +++ b/system/Router/DefinedRouteCollector.php @@ -57,7 +57,7 @@ public function collect(): Generator $handler = $view ? '(View) ' . $view : '(Closure)'; } - $routeName = $this->routeCollection->getRoutesOptions($route)['as'] ?? $route; + $routeName = $this->routeCollection->getRoutesOptions($route, $method)['as'] ?? $route; yield [ 'method' => $method, From 19cdaf2e4e713a917bcbc311df29d3b25c5dc6d5 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 13 Oct 2023 15:51:29 +0900 Subject: [PATCH 3/7] docs: add changelog --- user_guide_src/source/changelogs/v4.4.2.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/user_guide_src/source/changelogs/v4.4.2.rst b/user_guide_src/source/changelogs/v4.4.2.rst index beb5790fc8c1..bacfdf2a2e97 100644 --- a/user_guide_src/source/changelogs/v4.4.2.rst +++ b/user_guide_src/source/changelogs/v4.4.2.rst @@ -46,6 +46,7 @@ Bugs Fixed production mode or to display backtrace in json when an exception occurred. - **Forge:** Fixed a bug where adding a Primary Key to an existing table was ignored if there were no other Keys added too. +- **Routing:** Fixed a bug that ``spark routes`` may show incorrect route names. See the repo's `CHANGELOG.md `_ From ef37e120291f301721f65872202fb9ca8657b2bc Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 13 Oct 2023 16:34:45 +0900 Subject: [PATCH 4/7] docs: add text decoration --- user_guide_src/source/libraries/curlrequest.rst | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/user_guide_src/source/libraries/curlrequest.rst b/user_guide_src/source/libraries/curlrequest.rst index 4da540937cb3..fe21546aa8ed 100644 --- a/user_guide_src/source/libraries/curlrequest.rst +++ b/user_guide_src/source/libraries/curlrequest.rst @@ -214,7 +214,7 @@ cookie ====== This specifies the filename that CURL should use to read cookie values from, and -to save cookie values to. This is done using the CURL_COOKIEJAR and CURL_COOKIEFILE options. +to save cookie values to. This is done using the ``CURL_COOKIEJAR`` and ``CURL_COOKIEFILE`` options. An example: .. literalinclude:: curlrequest/021.php @@ -223,8 +223,10 @@ debug ===== When ``debug`` is passed and set to ``true``, this will enable additional debugging to echo to STDERR during the -script execution. This is done by passing CURLOPT_VERBOSE and echoing the output. So, when you're running a built-in -server via ``spark serve`` you will see the output in the console. Otherwise, the output will be written to +script execution. + +This is done by passing ``CURLOPT_VERBOSE`` and echoing the output. So, when you're running a built-in +server via ``spark serve``, you will see the output in the console. Otherwise, the output will be written to the server's error log. .. literalinclude:: curlrequest/034.php From 8d903a0c8eb39272edbdbff0351fcb64085bc3d6 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 13 Oct 2023 16:37:18 +0900 Subject: [PATCH 5/7] docs: improve explanation --- user_guide_src/source/libraries/curlrequest.rst | 7 +++++-- user_guide_src/source/libraries/curlrequest/026.php | 9 +++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/user_guide_src/source/libraries/curlrequest.rst b/user_guide_src/source/libraries/curlrequest.rst index fe21546aa8ed..f029efc4f883 100644 --- a/user_guide_src/source/libraries/curlrequest.rst +++ b/user_guide_src/source/libraries/curlrequest.rst @@ -272,8 +272,11 @@ further headers arrays or calls to ``setHeader()``. http_errors =========== -By default, CURLRequest will fail if the HTTP code returned is greater than or equal to 400. You can set -``http_errors`` to ``false`` to return the content instead: +By default, CURLRequest will throw ``HTTPException`` if the HTTP code returned is +greater than or equal to 400. + +If you want to see the response body, you can set ``http_errors`` to ``false`` to +return the content instead: .. literalinclude:: curlrequest/026.php diff --git a/user_guide_src/source/libraries/curlrequest/026.php b/user_guide_src/source/libraries/curlrequest/026.php index 36ea74cb9293..6c42894547bd 100644 --- a/user_guide_src/source/libraries/curlrequest/026.php +++ b/user_guide_src/source/libraries/curlrequest/026.php @@ -1,8 +1,9 @@ request('GET', '/status/500'); -// Will fail verbosely +// If the response code is 500, an HTTPException is thrown, +// and a detailed error report is displayed if in development mode. -$res = $client->request('GET', '/status/500', ['http_errors' => false]); -echo $res->getStatusCode(); -// 500 +$response = $client->request('GET', '/status/500', ['http_errors' => false]); +echo $response->getStatusCode(); // 500 +echo $response->getBody(); // You can see the response body. From 60a0fac97fe84152a87a5c814dc8fb486e42ce7a Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 14 Oct 2023 13:25:40 +0900 Subject: [PATCH 6/7] docs: fix anchor text --- user_guide_src/source/installation/upgrade_file_upload.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/installation/upgrade_file_upload.rst b/user_guide_src/source/installation/upgrade_file_upload.rst index d7a38a1f97d8..adb200b9f0f7 100644 --- a/user_guide_src/source/installation/upgrade_file_upload.rst +++ b/user_guide_src/source/installation/upgrade_file_upload.rst @@ -7,7 +7,7 @@ Upgrade Working with Uploaded Files Documentations ============== -- `Output Class Documentation CodeIgniter 3.X `_ +- `File Uploading Class Documentation CodeIgniter 3.X `_ - :doc:`Working with Uploaded Files Documentation CodeIgniter 4.X ` What has been changed From 1f753bcb3a0f5a59e771b14d25d214275e4454ca Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 16 Oct 2023 15:50:57 +0900 Subject: [PATCH 7/7] docs: add note for routes after calling resetServices() --- user_guide_src/source/testing/overview.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/user_guide_src/source/testing/overview.rst b/user_guide_src/source/testing/overview.rst index 7622339f8f0c..d969f73cdc41 100644 --- a/user_guide_src/source/testing/overview.rst +++ b/user_guide_src/source/testing/overview.rst @@ -244,6 +244,10 @@ Removes all mocked classes from the Services class, bringing it back to its orig You can also use the ``$this->resetServices()`` method that ``CIUnitTestCase`` provides. +.. note:: This method resets the all states of Services, and the ``RouteCollection`` + will have no routes. If you want to use your routes to be loaded, you need to + call the ``loadRoutes()`` method like ``Services::routes()->loadRoutes()``. + Services::resetSingle(string $name) -----------------------------------