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 …

How can I create a MockResponse with statusCode 400 header for MockHttpClient?

I would like to test different responses from an API using symfony/http-client, but how can I create statusCode 400? This is what I tried: public static function mockShipmentResponseFail(): …

Namespace that seems it doesn’t exist is working but why?

I have this exercice folder that gave me instructions on how to install the web application: So this folder contains a .sh file that installs the necessary things: npm install curl -o phpunit -L https:…

Unable to locate factory for [LaravelPassportClient]

I have a laravel app with passport installed to manage api auth. I’m trying to write some tests but I’m unable to create a Client as per the docs on laravel. I’ve googled similar SO answers but they …

How to use expectException in PHPUnit?

I’m trying to test my Exception, or any other exception in PHP Unit. <?php declare(strict_types=1); namespace TestsException; use PHPUnitFrameworkTestCase; class DrinkIsInvalidExceptionTest …

How to “mock” Sentry client in the PHPUnit tests

In case if you need to test PHP application error handlers, you have to “mock” or just disable sending errors on remote servers in the Sentry client. What is the right way to do this?

Problem in testing with withConsecutive()

I have a class FillUserPaymentStatisticService with methods: public function fillStatisticForAllTime(): void { $firstDate = DateTime::createFromFormat(‘Y-m-d H:i:s’, $this->…

PhpUnit How to test double a method using both other class and self class methods?

So I want to test double my function doEverything like so : class MyClass { protected secondClass; public function __construct( SecondClass $secondClass; ) { $this->…

Bypass SIMPLETEST_BASE_URL in PHPUnit.xml

Is there any way to run PHPUnit test case without SIMPLETEST_BASE_URL. I need to perform PHPUnit in an environment where only PHP cli is availabe. So can’t put any url on SIMPLETEST_BASE_URL in …

Laravel eager loading phpunit testing

I am trying to do a GET request to retrieve a specific film via the id /GET ‘film/{id}’ etc film_table — id — description this is what is part of the response, what if I’ve many-to-many …