CodeIgniter Forums
Testing current URI - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Testing current URI (/showthread.php?tid=77482)



Testing current URI - SteeveDroz - 09-06-2020

Hello,

As stated in this StackOverflow question, to which you can answer and win a few points, I am trying to run a unit test of a library that checks the value of string_uri().

In order to test it right, I have to mock the current URI, something like

PHP Code:
$_SERVER['PHP_SELF'] = 'my/custom/test/uri'


Unfortunately, that doesn't work.

I ended up by writing a function in the test suite that changes it and another one that overrides string_uri(). I don't like that, because I'm writing code that will never be tested.

Is there another way to mock the URI?