[Laravel] Database transactions in controller not working properly in Pest test #493
Unanswered
Jamesking56
asked this question in
Q&A
Replies: 3 comments
-
There seems to be a problem with DB transaction, even when using phpUnit. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Any help on this? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Having the same issue as well when using use App\Models\Customers\Customer;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use function Pest\Laravel\postJson;
uses(DatabaseTransactions::class);
it('should test if customer is deactivated successfully', function () {
$customer = Customer::factory()->create();
postJson(route('api.v2.contacts.deactivate'), ['contact_id' => $customer->id])
->assertSuccessful()
->assertJsonPath('message', 'Contact deactivated successfully');
expect($customer->fresh()->deleted_at)->not()->toBeNull();
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When using Laravel's
DB::transaction()
method, Pest incorrectly perceives that no records are created.For instance, using this
Pest.php
file:And creating a Controller method that does multiple queries inside of
DB::transaction()
:Then hitting the controller in a Pest test and checking that the database has those records created:
Seems to fail, stating that no records exist in the table. Really not sure why, the code works fine and there is no exception logged 🤷♂️
Beta Was this translation helpful? Give feedback.
All reactions