-
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(database): add seperate initializer for FrameworkIntegrationTest…
…Case
- Loading branch information
1 parent
b0381eb
commit 7f1ba39
Showing
3 changed files
with
37 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Database; | ||
|
||
use Tempest\Container\Container; | ||
use Tempest\Container\Initializer; | ||
use Tempest\Container\Singleton; | ||
|
||
/** | ||
* Reuses the same connection instance based on a static variable instead of the container. | ||
* | ||
* Used in testing where each test can have its own container instance. | ||
*/ | ||
final class CachedConnectionInitializer implements Initializer | ||
{ | ||
private static Connection|null $instance = null; | ||
|
||
public function __construct(private readonly ConnectionInitializer $initializer) | ||
{ | ||
} | ||
|
||
#[Singleton] | ||
public function initialize(Container $container): Connection | ||
{ | ||
if (self::$instance !== null) { | ||
return self::$instance; | ||
} | ||
|
||
self::$instance = $this->initializer->initialize($container); | ||
|
||
return self::$instance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters