Skip to content

Commit

Permalink
catch exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusjatenee committed Jan 2, 2024
1 parent 5b119cd commit a84dba2
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions tests/Integration/Routing/TransactionalTargetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public function testItExecutesAMethodInsideATransaction()
Route::get('user', [TransactionalTestController::class, 'store']);

$this->get('user');

$this->assertDatabaseHas('users', ['name' => 'Mateus']);
}

Expand All @@ -59,17 +58,31 @@ public function testItRollbacksChangesUponFailure()
TransactionalTestController::$shouldFail = true;
Route::get('user', [TransactionalTestController::class, 'store']);

$this->get('user')->assertStatus(500);
$this->assertDatabaseMissing('users', ['name' => 'Mateus']);
try {
$this->withoutExceptionHandling()->get('user')->assertStatus(500);
} catch (\Exception) {
$this->assertDatabaseMissing('users', ['name' => 'Mateus'], 'second_connection');

return;
}

$this->fail('Exception was not thrown.');
}

public function testItRollbacksChangesUponFailureInvokableController()
{
TransactionalTestController::$shouldFail = true;
Route::get('user', TransactionalTestController::class);

$this->get('user')->assertStatus(500);
$this->assertDatabaseMissing('users', ['name' => 'Mateus']);
try {
$this->withoutExceptionHandling()->get('user')->assertStatus(500);
} catch (\Exception) {
$this->assertDatabaseMissing('users', ['name' => 'Mateus'], 'second_connection');

return;
}

$this->fail('Exception was not thrown.');
}

public function testItExecutesAMethodInsideATransactionSecondConnection()
Expand All @@ -86,8 +99,15 @@ public function testItRollbacksChangesUponFailureDifferentConnection()
TransactionalTestControllerSecondConnection::$shouldFail = true;
Route::get('user', [TransactionalTestControllerSecondConnection::class, 'store']);

$this->get('user')->assertStatus(500);
$this->assertDatabaseMissing('users', ['name' => 'Mateus'], 'second_connection');
try {
$this->withoutExceptionHandling()->get('user')->assertStatus(500);
} catch (\Exception) {
$this->assertDatabaseMissing('users', ['name' => 'Mateus'], 'second_connection');

return;
}

$this->fail('Exception was not thrown.');
}
}

Expand Down

0 comments on commit a84dba2

Please sign in to comment.