10,094 questions
2 votes
1 answer
76 views
Why does PHPUnit require an intermediate variable when mocking/stubbing?
I am doing some unit testing with PHP. I got stuck on an error that the fluent interface of PHPUnit requires an intermediate variable. What is the reason for this behavior? See MyTests::works vs. ...
1 vote
2 answers
148 views
PHPUnit tests get awfully slow when all tests are run at once [closed]
I have a problem which I find awfully hard to debug: In my application, I currently have about 1000 tests, so not much. They are split across several directories (tests/someDir, tests/someOtherDir, ...
0 votes
1 answer
92 views
Testing Eloquent model events in Laravel 11
I can't seem to find a definitive answer on how to test the following boot methods using PHPUnit tests in Laravel. I'm referring to the mthods in public static function boot() on a model. Survey model ...
0 votes
0 answers
129 views
Laravel PHPUnit test: Multiple databases issue
In my Laravel application, I have set up two databases in a single server. All specific migrations and model classes have $connection property set up to use blog instance. The app works fine, no ...
1 vote
0 answers
45 views
Show only failing and expected values from PHPUnit output
I have PHPUnit tests that use data providers as inputs, and by default these are outputted in a diff-like format (when running with php artisan test): 1) Tests\Feature\MyTest::test_feature with data ...
2 votes
1 answer
53 views
PhpUnit overwrite server variables from XML
I have following server variable in phpunit.xml: <php> <server name="APP_DEBUG" value="false"/> </php> Sometimes while developing, I want have APP_DEBUG ...
0 votes
0 answers
98 views
Laravel testing database table is being accessed by other users
I'm currently building a multi-tenant application using stancl/tenancy (every tenant uses their own database) in my Laravel application. Whenever I'm writing tests, tests fail a lot due to the error ...
1 vote
0 answers
192 views
How to run tests of the same phpunit testcase class in parallel with ParaTest?
I have a contrived test case showcasing how multiple test cases can slow the entire execution time down, as even though each is quick on its own, they add up if waited for before executing the next. I ...
1 vote
1 answer
61 views
get_template_directory() returning child theme instead of parent theme when running phpunit
I'm trying to set up testing for a Wordpress child theme. I've use the wp-cliwp scaffold theme-tests command to scaffold some tests. Inside of my child theme's functions.php file, I load some ...
1 vote
0 answers
65 views
How To Test Importing File Excel With Real or Fake File Contained Data For Table Database In Laravel PHPUnit
I have a bit of trouble figuring out of how to test import book route of my controller in PHPUnit Testing. I'm Using MaatWebsite Package for the excel. So, I have real excel file in test/Files/...
0 votes
1 answer
41 views
How To Access Specific Notification Data In Laravel Test
I want to test MarkAsRead function via routing, my route was Route::post('notifications/{id}', [NotificationController::class, 'markAsRead']); and it was in API routing of auth:sanctum api route Route:...
3 votes
1 answer
147 views
Laravel API Testing index and show data fail at assertJsonStructure of Nested Json back-and- fort
I have API for books that I want to test using phpunit, but the structure of nested json somehow make index and show test function making one of them fail. If I wrote this code for both index and show ...
2 votes
2 answers
61 views
Laravel job sync driver refresh database
I have a piece of code that does the following: Create a database row (spatie media library) Create a job that adds something to column A and saves the object (also spatie media library) Adds ...
0 votes
1 answer
54 views
PHPUnit in VS Code don't show tests grouped in Test Explorer, despite correct configuration
PHPUnit test suites not showing in Test Explorer, despite correct configuration in VS-Code it looks like this: TESTING [Filters fiel] 6/6 (6 from 6 succesful) └─ {} SL5 └─ PregContentFinder └─ {} ...
0 votes
2 answers
63 views
How to allow a certain differences in a text assertion for a test case that has some expected changes in data using phpunit?
I am setting up a golden master test case, yet the result may be off at certain points due to side-effects changing some strings at known places. Getting rid of those side-effects would be best, yet ...