So my test case in laravel is the following: This line: is causing the test to fail and get an output of ‘The email has already been taken’ Why is this the case? I want to check upon sign up, the user is directed to the home page which it does but my test fails. The user is being created
Tag: testing
Feature test for HTTP RESTful API on Laravel 8
I’m trying to write a feature test in RESTful API that I have been created in laravel 8. I have ChatController that gets user chats by getUserChats method: that called by this route: this is my feature test on this route: the test runs successfully by this green output OK (1 test, 3 assertions) but I don’t know this is
Carbon object in mockery php test
Thank you for your time. I have stripped out the fluff from the code/test. The furthest I have got with this is that setAttribute requires two strings as paramĀ“s, but i am passing in an Carbon object, which Mockery as a test suite does not like? Is this the case, is there a better way to test dates with Mockery/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.
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 …
Testing method which need log in
I want to testing some method like user (method need log in user). $user = User::find(1); $response = $this->actingAs($user)->json(‘POST’, ‘/store/post’, [ ‘title’ => ‘Hello …
Resolving dependencies without a dependency injection container
I have a project in plain PHP and there is a class which is dependent on external library. I don’t feel like passing it to constructor everywhere is a good idea (it’s called mainly in tests, but the …
Laravel Notification Mailable not working in Test
I’am using a notification to send a mail to all users when the notification gets Triggered. This works fine in manual “browsing the website” usage (submit a POST to the ContactController) but in my …
How to make Laravel’s Notification throw an Exception in test
I have a few laravel commands that inherit from my own class to send slack messages if they fail. However if the slack notification fails I still want the original exception thrown so that the error still ends up in the logs if slack is unavailable or misconfigured. I have this and it works, but I can’t figure out how