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(): …
Tag: phpunit
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
Laravel. Tests clear the active DB
The tables in my active DB are empty after tests. I have the test environment variable DB_CONNECTION=mysql_testing. When I run my tests and do dd(env(‘DB_CONNECTION’)) – everything is fine. I see ‘mysql_testing’. But when I write dd( DB::connection()->getDatabaseName()) I see the wrong DB name(for example ‘db_name’, but it should be ‘testing_db_name’) . It is the name of the active DB.
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:…
How to pass arguments to custom composer script
In my Laravel project, I want to run phpunit for a single file, like this one: Here is my composer setup: However, I’m running into this error: www@287dd7480e22:/var/www$ composer run-script test tests/Unit/Services/OrderServiceTest.php php artisan config:cache –env=testing ‘tests/Unit/Services/OrderServiceTest.php’ Too many arguments, expected arguments “command”. Notice: I’ve seen this post: How do you pass an argument to a composer script from the
Reload database before some test in phpunit
I’m currently developing unit tests with phpunit, and symfony 5. On a previous job using behat, we were able to reload the database only for the tests having a specific tag. I’d like to do something similar. I know there is the setUp() method and the @before annotation, but they don’t let me do thing for some tests and not
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 …
PHPUnit Stalling in CI
We’re having an issue with PHPUnit sometimes failing to correctly run our test suite in CI. The behaviour manifests as roughly 1/3 tests failing to start and the CI step timing out. Interestingly enough, we don’t see this behaviour: Locally on our machines Every time we run the tests Occur with the dusk tests Our setup is to run the
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?