File tree Expand file tree Collapse file tree
packages/database/src/Connection
tests/Integration/Database/Connection Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,11 +15,15 @@ public function __construct(
1515
1616 public function reset (): void
1717 {
18+ // Manually looping over the connection singletons so that we can check whether they still have an active transaction
1819 if ($ this ->container instanceof GenericContainer) {
19- /** @var Connection[] $connections */
2020 $ connections = $ this ->container ->getSingletons (Connection::class);
2121
2222 foreach ($ connections as $ connection ) {
23+ if (! $ connection instanceof Connection) {
24+ continue ;
25+ }
26+
2327 if ($ connection ->inTransaction ()) {
2428 throw new CouldNotResetConnection ("There's still an active transaction, make sure to close it before ending the request " );
2529 }
Original file line number Diff line number Diff line change 22
33namespace Tests \Tempest \Integration \Database \Connection ;
44
5+ use Exception ;
56use PHPUnit \Framework \Attributes \Test ;
67use Tempest \Database \Connection \Connection ;
78use Tempest \Database \Exceptions \CouldNotResetConnection ;
@@ -38,4 +39,22 @@ public function test_properly_closed_transaction_can_reset_connection(): void
3839 $ newConnection = $ this ->container ->get (Connection::class);
3940 $ this ->assertNotSame ($ connection , $ newConnection );
4041 }
42+
43+ #[Test]
44+ public function test_reset_with_uninstantiated_singletons (): void
45+ {
46+ $ this ->container ->singleton (
47+ Connection::class,
48+ fn () => throw new Exception ('Should not happen ' ),
49+ tag: 'other ' ,
50+ );
51+
52+ /** @var Connection $connection */
53+ $ connection = $ this ->container ->get (Connection::class);
54+
55+ $ this ->container ->reset ();
56+
57+ $ newConnection = $ this ->container ->get (Connection::class);
58+ $ this ->assertNotSame ($ connection , $ newConnection );
59+ }
4160}
You can’t perform that action at this time.
0 commit comments