Skip to main content
Filter by
Sorted by
Tagged with
2 votes
1 answer
76 views

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. ...
Sven Eppler's user avatar
  • 1,796
1 vote
2 answers
148 views

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, ...
PhilippG's user avatar
0 votes
1 answer
92 views

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 ...
Daniel Harper's user avatar
2 votes
1 answer
53 views

I have following server variable in phpunit.xml: <php> <server name="APP_DEBUG" value="false"/> </php> Sometimes while developing, I want have APP_DEBUG ...
Justinas's user avatar
  • 43.9k
0 votes
0 answers
129 views

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 ...
Gasimoff's user avatar
1 vote
0 answers
45 views

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 ...
Hashim Aziz's user avatar
  • 6,576
1 vote
0 answers
191 views

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 ...
k0pernikus's user avatar
  • 67.6k
508 votes
16 answers
370k views

I am struggling to run a single test method named testSaveAndDrop in the file escalation/EscalationGroupTest.php with phpunit. I tried the following combinations: phpunit EscalationGroupTest ...
Alex's user avatar
  • 45k
0 votes
0 answers
98 views

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 ...
FryingPan's user avatar
  • 123
483 votes
14 answers
375k views

Does anyone know whether there is an assert or something like that which can test whether an exception was thrown in the code being tested?
Felipe's user avatar
  • 11.9k
40 votes
5 answers
26k views

I'm just learning how to use PHPUnit. I'm running it from the command line, and among the results I get OK, but there are issues! Tests: 5, Assertions: 15, Warnings: 2, Deprecations: 5. I can't work ...
Jayy's user avatar
  • 14.9k
1 vote
1 answer
61 views

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 ...
jloosli's user avatar
  • 2,595
44 votes
14 answers
33k views

As method withConsecutive will be deleted in PHPUnit 10 (in 9.6 it's deprecated) I need to replace all of occurrences of this method to new code. Try to find some solutions and didn't find any of ...
yAnTar's user avatar
  • 4,640
113 votes
32 answers
82k views

The Problem To improve my quality of code, I've decided to try to learn how to test my code using Unit Testing instead of my mediocre-at-best testing solutions. I decided to install PHPUnit using ...
user avatar
46 votes
14 answers
102k views

I have run my Laravel application with PHPUnit. Everything is fine until at some point, when I run my test again, it turns out with this error. Illuminate\Database\QueryException: could not find ...
Vic Andam's user avatar
  • 1,193
165 votes
10 answers
180k views

I want to test specific testClass in my project since there are a lot of test class that's failure and I just want to test one Class at a time. I've created the test Class in following folder \test\...
Gujarat Santana's user avatar
221 votes
19 answers
166k views

What is a good way to assert that two arrays of objects are equal, when the order of the elements in the array is unimportant, or even subject to change?
koen's user avatar
  • 13.8k
3 votes
1 answer
147 views

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 ...
TheBetweener's user avatar
1 vote
2 answers
197 views

I'm trying to use PHPUnit 12 dataProviders to provide data to a function to test but I can't get it working. Here's my unit test (that lives at tests/TestTest.php): <?php declare(strict_types=1); ...
neubert's user avatar
  • 17k
236 votes
21 answers
212k views

When running a PHPUnit test, I would like to be able to dump output so I can debug one or two things. I have tried the following (similar to the PHPUnit Manual example); class theTest extends ...
Jess Telford's user avatar
  • 13.3k
361 votes
11 answers
196k views

I found the discussion on Do you test private method informative. I have decided, that in some classes, I want to have protected methods, but test them. Some of these methods are static and short. ...
GrGr's user avatar
  • 4,198
0 votes
1 answer
54 views

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 └─ {} ...
SL5net's user avatar
  • 2,630
1 vote
1 answer
565 views

I have a FormRequest that logs validation error details: protected function failedValidation(Validator $validator) { Log::channel('logistics')->info('Validation failed. Submitted ...
Synchro's user avatar
  • 38k
1 vote
0 answers
154 views

I'm trying to run tests on my Laravel application. here is my phpunit config: <php> <env name="APP_ENV" value="testing"/> <env name="...
Mehrab's user avatar
  • 11
0 votes
2 answers
63 views

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 ...
k0pernikus's user avatar
  • 67.6k
1 vote
0 answers
65 views

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/...
Kholid Syaifullah's user avatar
2 votes
2 answers
61 views

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 ...
Veda's user avatar
  • 2,113
2 votes
1 answer
198 views

this is my first post so don't hesitate to tell me if something is wrongly said. I'm working on a projet in Symfony 7.*. I try to implement unit test in my project but I'm facing some issues. I use ...
Dev Th's user avatar
  • 29
34 votes
4 answers
18k views

I have included PHPUnit in a test vanilla PHP project and when I start the test with vendor/bin/phpunit I get the following error message: Your XML configuration validates against a deprecated schema. ...
Maik Lowrey's user avatar
  • 17.8k
6 votes
3 answers
14k views

I am running php artisan test --parallel on github actions using a docker container, and the performance is worse than if I run it without --parallel. If I specify the cores with php artisan test --...
Bernard Wiesner's user avatar
0 votes
1 answer
69 views

I'm implementing the server API (for geni.com) in PHP. The server requires OAuth authentication, so I need a browser because this requires user input (to permit access to their account). THIS all ...
Shmuel A. Kam's user avatar
1 vote
1 answer
59 views

I have a simple test where I mock a dependency of the code under test: <?php use PHPUnit\Framework\TestCase; class Dependency { public function someFunction(int $first, int $second): int { ...
Robert's user avatar
  • 9,056
34 votes
11 answers
30k views

I created a .env.testing file with my credentials, everything the same as .env besides a different table name for the database. I tried php artisan config:clear which deletes the cached config file ...
zeros-and-ones's user avatar
2 votes
2 answers
210 views

I am running phpUnit tests using Laravel Framework Version 9.52.20. The tests work just fine in my local environment and in my CI/CD pipeline. But when I try to run the same tests in my dev ...
hanmari's user avatar
  • 1,504
170 votes
8 answers
100k views

PHPUnit contains an assertEquals() method, but it also has an assertSame() one. At first glance it looks like they do the same thing. What is the difference between the two? Why are they both ...
Kevin Burke's user avatar
  • 65.7k
174 votes
11 answers
124k views

I've got a PHPUnit mock object that returns 'return value' no matter what its arguments: // From inside a test... $mock = $this->getMock('myObject', 'methodToMock'); $mock->expects($this->...
Ben Dowling's user avatar
  • 17.6k
2 votes
1 answer
493 views

I’m testing my packages for compatibility with PHP 8.4.1. However, some dependencies trigger deprecation warnings. Is there a way to configure PHPUnit to report deprecation warnings only for my ...
8ctopus's user avatar
  • 3,367
162 votes
6 answers
164k views

Is there any way to define different mock-expects for different input arguments? For example, I have database layer class called DB. This class has method called Query(string $query), that method ...
Aleksei Kornushkin's user avatar
2 votes
1 answer
214 views

ClockMock is a very useful tool for creating time sensitive tests e.g. if a date is in past A should happen, if it is in the future B should happen. ClockMock is a part of the phunit-bridge, which ...
Calamity Jane's user avatar
0 votes
1 answer
41 views

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:...
TheBetweener's user avatar
1 vote
4 answers
313 views

I've got a Dockerized Laravel app, here's the docker compose file: version: "3.9" services: app: build: context: ./ dockerfile: Dockerfile image: dmc container_name:...
MrCujo's user avatar
  • 1,393
27 votes
6 answers
25k views

I'm trying to generate coverage html file with PHPUnit. I get a warning: 'No filter is configured, code coverage will not be processed' and coverage file isn't generated. This is phpunit.xml file <?...
Przemek Kro's user avatar
2 votes
1 answer
63 views

The method function at() has been removed from phpunit 10 later. I changed from at() to once() but my tests still don't pass The test fails because you cannot order the condition() calls. php code: ......
bindi_m's user avatar
  • 150
74 votes
3 answers
32k views

When I run tests with PhpUnit on a new package I'm creating for Laravel, it generates the file .phpunit.result.cache. What to do with that? Do I add it to my .gitignore file or not? I'm using ...
Davide Casiraghi's user avatar
1 vote
0 answers
49 views

I'm developing a Wordpress plugin and wanted to use a test-driven approach so I installed PHPUnit and the WP CLI tool. I did wp scaffold plugin-tests my-plugin and it generated the scaffolding files ...
Phl3tch's user avatar
  • 155
1 vote
1 answer
119 views

Stack versions: ApiPlatform 3.2 Symfony 6.4 PhpUnit 9.5 PHP 8.0 Writing a test for the DELETE endpoint of the User resource. When the endpoint is called, the user must be soft deleted and several ...
fombo's user avatar
  • 95
0 votes
1 answer
121 views

Laravel version: 8 php version: 8.1 When I run php artisan test, I get Command "tests" is not defined. I added nunomaduro/collision to my dependencies, and I get the error: NunoMaduro\...
Rowlando13's user avatar
0 votes
1 answer
89 views

I have a Trait called HasDefault its main purpose is to ensure that the class has a static field $default which is callable and returns the default instance of the class using the Trait This is what ...
LordF's user avatar
  • 536
-1 votes
1 answer
168 views

I am trying to test Laravel API by using Laravel PHP unit test, I want to refresh and seeding of my test database once for all tests. what should i need to do in Testcase Laravel class for get this ...
shazim ali's user avatar
80 votes
4 answers
54k views

I am trying to learn how to test with phpunit and laravel. When start the test using phpunit command, I am getting a warning : There was 1 failure: 1) Warning No tests found in class "PostsTest". ...
ytsejam's user avatar
  • 3,449

1
2 3 4 5
202