Failed asserting that 302 is identical to 200 |
Hello,
I am working on this personal project just to learn CI4 and Myth Auth. I am getting the PHPUnit failure message you see in the topic line. "Failed asserting that 302 is identical to 200." when I run a PHPUnit test to test HTTP GET request. This is the code that generates that: Code: $response = $this->get('list'); So, it seems the Myth Auth, which is in the middle authenticating and redirecting, is the reason this is happening. I bypassed Auth and the failure went away. How does one go about testing HTTP requests in these situations? I mean without bypassing Auth every time. Thanks,
You can simulate a logged in user with the AuthTestTrait. It would be something like this, assuming you're using the Trait on the test class.:
PHP Code: $user = $this->createAuthUser(); This will create a new user and log them in so when you attempt the get() call you would pass the checks. (04-18-2022, 08:07 PM)kilishan Wrote: You can simulate a logged in user with the AuthTestTrait. It would be something like this, assuming you're using the Trait on the test class.: Yes, this worked. kenjis' link looks like that could be another way of doing it. Good to know. Thanks
Excellent! Glad it worked for you.
|
Welcome Guest, Not a member yet? Register Sign In |