Skip to content

Tag: phpunit

Laravel: Test not Using Mocked Method

I want getNumber to return 200 in the test case, but when I run the test and inspect the result with $response->dump() I can see that the mock is not overriding the method as it is showing array:1 [0 => 100]. What am I missing? Controller: Model: Test: I am using Laravel 8 and referencing this documenta…

Falling testing Laravel assertModelExists

Making a test for database with Laravel (8.44.0) assetion assertModelExists(), fails on an error. The test class looks like this What do you think is missing? Answer The assertModelExists method was added September 2021: https://github.com/laravel/framework/pull/38766 Version 8.44.0 was released May 2021: htt…

PhpUnit: how to fake an outdated file?

I have a method in a class, which checks if a file is older than a day. It achieves this by getting the last change date of the file and comparing it with “now”: I want to write a Unittest faking an outdated file. I tried to change the file date with touch: The output gives me the information that

How to ignore specific private static function with PHPUnit?

I’m new to PHPUnit and wondering is it possible to write a test for which ignore specific method. The code is like examine whether $data is Valid or not, and if it find irregular data, send message to slack with it. My question is, is it possible to run a test without sending alert message, like ignore …