Skip to content
Advertisement

Tag: phpunit

Why my dataProvider function in my unit test file is not working properly?

I want to test this function: Inside my unit test file, I have these functions: And finally, I have these errors: Expectation failed for method name is “get” when invoked zero or more times Parameter 0 for invocation IlluminateHttpRequest::get(‘address1′, null): mixed does not match expected value. Failed asserting that two strings are equal. Expected :’address2′ Actual :’address1’ Expectation failed for

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 documentation: https://laravel.com/docs/8.x/mocking#mocking-objects Answer In

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: https://github.com/laravel/framework/releases/tag/v8.44.0 So just update Laravel to the latest 8.x release and you should be good to go.

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 sendAlert function? If

Advertisement