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
Tag: unit-testing
How to test create model service?
I decided to create CreateClassroomService to separte logic in my controller method. I am trying to test this service as part of learning unit testing, but I don’t know how. I don’t know how to mock the classroom object to control what the method should return. Does this mean that creating this service was not a good idea because I
PHPUnit can’t generate code coverage when running tests in separate processes
I have a problem that I could not find the solution on Google. When I run my unit tests with PHPUnit and Xdebug, I would like to do a code coverage. However, when I do that, I get this error: I realized that this is because in some of my tests there is this at the top: When I remove
“Bad variable name” when trying to run phpunit tests via a Makefile without deprecation warnings
I have a Make target called test. It looks like this: I want to set up a git hook that runs all tests before commits. In order to do this without getting stalled on deprecation warnings, I want to have my hook run a different Make target. It looks like this: However, when I try to run this target, I
Symfony 5.1 to 5.2 unit testing do not authenticate via guard authenticator
I ‘m working with Symfony 5.1 using the firewall and a guard authenticator; All was working fine with 5.1. I’ve recently upgrade to Symfony 5.2 and almost all working fine except Unit tests. When i do a step by step debugging, it’s not stepping into the Authenticator anymore like it was the case previously (in 5.1). Any parameter missing in
Mock class with fluent interface in Phpunit
I am mocking this sample class with fluent methods that doesn’t have return type declaration: Using PhpUnit: By default, this will not work on fluent methods without return type declaration so I need to add the ff.: This works but cumbersome to write if there are a lot fluent methods. My question is, is there a way to set this
What should I test in an application layer service
I wrote the following application service for a project I’m working on, but struggled to write a good unit test for it. As you can see, the service itself doesn’t perform any meaningful logic other than orchestrating the domain layer (as it should if I understand correctly, according to the blue book). What would be your suggestions to unit test
How can I test laravel job’s second try logic which is using attempts function
I have a queued job class which backs off exponentially thanks to the backoff() method. I want to test that backoff() method works right. It should create 2, 4, 8, 16 and so on after each retry. Since attempts() function belongs to the InteractsWithQueue trait and reads the attempt count from the deeper RedisJob class’ decoded payload, I could not
Error when running multiple PHPUnit Tests in Laravel 8
Unit testing in a Laravel 8 project is throwing an error when more than one test is called. The issue is causing my tests to fail when I run more than one at once. When running a batch of tests the …
PHPUnit tests isolation and how to write a test where expected value depends on some value in method that changes often
So I am coding in PHP and am writing tests with PHPUnit. I have this method convertCashAmountToMainCurrency that i want to test: And i have the Constants that are being used here: I am testing the method like this: And the tests passes just fine when the expected value and the currency rate are stated in fixed size. But the