File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -278,7 +278,13 @@ public function withLogger($logger)
278278 */
279279 public function withUri (string $ uri )
280280 {
281- $ this ->uri = new URI ($ uri );
281+ $ factory = Services::siteurifactory ();
282+ $ this ->uri = $ factory ->createFromString ($ uri );
283+ Services::injectMock ('uri ' , $ this ->uri );
284+
285+ // Update the Request instance, because Request has the SiteURI instance.
286+ $ this ->request = Services::incomingrequest (null , false );
287+ Services::injectMock ('request ' , $ this ->request );
282288
283289 return $ this ;
284290 }
Original file line number Diff line number Diff line change @@ -347,6 +347,10 @@ Bugs Fixed
347347 (e.g., **foo-bar **) and one URI for underscores (e.g., **foo_bar **). This bug
348348 has been fixed. Now the URI for underscores (**foo_bar **) is not accessible.
349349- **Output Buffering: ** Bug fix with output buffering.
350+ - **ControllerTestTrait: ** ``ControllerTestTrait::withUri() `` creates a new Request
351+ instance with the URI. Because the Request instance should have the URI instance.
352+ Also if the hostname in the URI string is invalid with ``Config\App ``, the valid
353+ hostname will be set.
350354
351355See the repo's
352356`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md >`_
Original file line number Diff line number Diff line change @@ -101,6 +101,11 @@ representing a valid URI:
101101
102102It is a good practice to always provide the URI during testing to avoid surprises.
103103
104+ .. note :: Since v4.4.0, this method creates a new Request instance with the URI.
105+ Because the Request instance should have the URI instance. Also if the hostname
106+ in the URI string is invalid with ``Config\App ``, the valid hostname will be
107+ set.
108+
104109withBody($body)
105110---------------
106111
You can’t perform that action at this time.
0 commit comments