diff --git a/.gitignore b/.gitignore index 8bb069994..0e321ab34 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ packages/database.sqlite packages/database/src/database.sqlite src/Tempest/database.sqlite tests/Fixtures/database.sqlite +tests/Fixtures/database*.sqlite tests/Unit/Console/test-console.log src/Tempest/Database/src/database.sqlite .env diff --git a/composer.json b/composer.json index e7188b507..c091cd01a 100644 --- a/composer.json +++ b/composer.json @@ -87,7 +87,8 @@ "tempest/blade": "dev-main", "thenetworg/oauth2-azure": "^2.2", "twig/twig": "^3.16", - "wohali/oauth2-discord-new": "^1.2" + "wohali/oauth2-discord-new": "^1.2", + "brianium/paratest": "^7.14" }, "replace": { "tempest/auth": "self.version", diff --git a/packages/container/src/HasInstance.php b/packages/container/src/HasInstance.php index 3f4b6b60f..7edfdeef3 100644 --- a/packages/container/src/HasInstance.php +++ b/packages/container/src/HasInstance.php @@ -6,14 +6,14 @@ trait HasInstance { - private static self $instance; + private static ?self $instance = null; public static function instance(): ?self { return self::$instance ?? null; } - public static function setInstance(self $instance): void + public static function setInstance(?self $instance): void { self::$instance = $instance; } diff --git a/src/Tempest/Framework/Testing/IntegrationTest.php b/src/Tempest/Framework/Testing/IntegrationTest.php index d664e6d7c..08ea0e93d 100644 --- a/src/Tempest/Framework/Testing/IntegrationTest.php +++ b/src/Tempest/Framework/Testing/IntegrationTest.php @@ -36,6 +36,7 @@ use Tempest\Storage\Testing\StorageTester; use Throwable; +use function Tempest\env; use function Tempest\Support\Path\normalize; use function Tempest\Support\Path\to_absolute_path; @@ -46,6 +47,8 @@ abstract class IntegrationTest extends TestCase { protected string $root; + protected string $internalStorage; + /** @var \Tempest\Discovery\DiscoveryLocation[] */ protected array $discoveryLocations = []; @@ -110,12 +113,14 @@ protected function setupKernel(): self { // We force forward slashes for consistency even on Windows. $this->root ??= normalize(realpath(getcwd())); + $this->internalStorage = $this->root . '/.tempest/test_internal_storage/' . env('TEST_TOKEN', 'default'); $discoveryLocations = [...$this->discoveryLocations, ...$this->discoverTestLocations()]; $this->kernel ??= FrameworkKernel::boot( root: $this->root, discoveryLocations: $discoveryLocations, + internalStorage: $this->internalStorage, ); /** @var GenericContainer $container */ @@ -234,6 +239,8 @@ protected function tearDown(): void unset($this->http); /** @phpstan-ignore-next-line */ unset($this->oauth); + + GenericContainer::setInstance(null); } protected function assertException(string $expectedExceptionClass, Closure $handler, ?Closure $assertException = null, ?string $message = null): void diff --git a/tests/Fixtures/Config/database.sqlite.php b/tests/Fixtures/Config/database.sqlite.php index c72626b54..b46dcbd6f 100644 --- a/tests/Fixtures/Config/database.sqlite.php +++ b/tests/Fixtures/Config/database.sqlite.php @@ -4,6 +4,8 @@ use Tempest\Database\Config\SQLiteConfig; +use function Tempest\env; + return new SQLiteConfig( - path: __DIR__ . '/../database.sqlite', + path: __DIR__ . '/../database' . env('TEST_TOKEN', 'default') . '.sqlite', ); diff --git a/tests/Integration/Console/Commands/MakeCommandCommandTest.php b/tests/Integration/Console/Commands/MakeCommandCommandTest.php index 511480532..2e55cb52e 100644 --- a/tests/Integration/Console/Commands/MakeCommandCommandTest.php +++ b/tests/Integration/Console/Commands/MakeCommandCommandTest.php @@ -19,8 +19,8 @@ protected function setUp(): void parent::setUp(); $this->installer->configure( - __DIR__ . '/install', - new Psr4Namespace('App\\', __DIR__ . '/install/App'), + $this->internalStorage . '/install', + new Psr4Namespace('App\\', $this->internalStorage . '/install/App'), ); } diff --git a/tests/Integration/Console/Commands/MakeConfigCommandTest.php b/tests/Integration/Console/Commands/MakeConfigCommandTest.php index 2fadbfa77..0f0766b34 100644 --- a/tests/Integration/Console/Commands/MakeConfigCommandTest.php +++ b/tests/Integration/Console/Commands/MakeConfigCommandTest.php @@ -30,8 +30,8 @@ protected function setUp(): void parent::setUp(); $this->installer->configure( - __DIR__ . '/install', - new Psr4Namespace('App\\', __DIR__ . '/install/App'), + $this->internalStorage . '/install', + new Psr4Namespace('App\\', $this->internalStorage . '/install/App'), ); } diff --git a/tests/Integration/Console/Commands/MakeGeneratorCommandCommandTest.php b/tests/Integration/Console/Commands/MakeGeneratorCommandCommandTest.php index 55e8bf4f7..427d83dfc 100644 --- a/tests/Integration/Console/Commands/MakeGeneratorCommandCommandTest.php +++ b/tests/Integration/Console/Commands/MakeGeneratorCommandCommandTest.php @@ -19,8 +19,8 @@ protected function setUp(): void parent::setUp(); $this->installer->configure( - __DIR__ . '/install', - new Psr4Namespace('App\\', __DIR__ . '/install/App'), + $this->internalStorage . '/install', + new Psr4Namespace('App\\', $this->internalStorage . '/install/App'), ); } diff --git a/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php b/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php index 26a13130a..2c84475c4 100644 --- a/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php +++ b/tests/Integration/Console/Commands/MakeMiddlewareCommandTest.php @@ -22,8 +22,8 @@ protected function setUp(): void parent::setUp(); $this->installer->configure( - __DIR__ . '/install', - new Psr4Namespace('App\\', __DIR__ . '/install/App'), + $this->internalStorage . '/install', + new Psr4Namespace('App\\', $this->internalStorage . '/install/App'), ); } diff --git a/tests/Integration/Console/Installer/ConsoleInstallerTest.php b/tests/Integration/Console/Installer/ConsoleInstallerTest.php index 6e785922c..36ab895da 100644 --- a/tests/Integration/Console/Installer/ConsoleInstallerTest.php +++ b/tests/Integration/Console/Installer/ConsoleInstallerTest.php @@ -18,10 +18,10 @@ protected function setUp(): void $this->installer ->configure( - __DIR__ . '/install', - new Psr4Namespace('App\\', __DIR__ . '/install/App'), + $this->internalStorage . '/install', + new Psr4Namespace('App\\', $this->internalStorage . '/install/App'), ) - ->setRoot(__DIR__ . '/install'); + ->setRoot($this->internalStorage . '/install'); } protected function tearDown(): void diff --git a/tests/Integration/Container/Commands/MakeInitializerCommandTest.php b/tests/Integration/Container/Commands/MakeInitializerCommandTest.php index 52a4387db..70a0a5066 100644 --- a/tests/Integration/Container/Commands/MakeInitializerCommandTest.php +++ b/tests/Integration/Container/Commands/MakeInitializerCommandTest.php @@ -19,8 +19,8 @@ protected function setUp(): void parent::setUp(); $this->installer->configure( - __DIR__ . '/install', - new Psr4Namespace('App\\', __DIR__ . '/install/App'), + $this->internalStorage . '/install', + new Psr4Namespace('App\\', $this->internalStorage . '/install/App'), ); } diff --git a/tests/Integration/Core/FrameworkInstallerTest.php b/tests/Integration/Core/FrameworkInstallerTest.php index b567744d9..5a15f28d8 100644 --- a/tests/Integration/Core/FrameworkInstallerTest.php +++ b/tests/Integration/Core/FrameworkInstallerTest.php @@ -18,10 +18,10 @@ protected function setUp(): void $this->installer ->configure( - __DIR__ . '/install', - new Psr4Namespace('App\\', __DIR__ . '/install/App'), + $this->internalStorage . '/install', + new Psr4Namespace('App\\', $this->internalStorage . '/install/App'), ) - ->setRoot(__DIR__ . '/install'); + ->setRoot($this->internalStorage . '/install'); } protected function tearDown(): void diff --git a/tests/Integration/Core/InstallCommandTest.php b/tests/Integration/Core/InstallCommandTest.php index 80aab3c7d..f6622a270 100644 --- a/tests/Integration/Core/InstallCommandTest.php +++ b/tests/Integration/Core/InstallCommandTest.php @@ -18,10 +18,10 @@ protected function setUp(): void $this->installer ->configure( - __DIR__ . '/install', - new Psr4Namespace('App\\', __DIR__ . '/install/App'), + $this->internalStorage . '/install', + new Psr4Namespace('App\\', $this->internalStorage . '/install/App'), ) - ->setRoot(__DIR__ . '/install'); + ->setRoot($this->internalStorage . '/install'); } protected function tearDown(): void diff --git a/tests/Integration/Core/PublishesFilesTest.php b/tests/Integration/Core/PublishesFilesTest.php index 7d5cddf09..d1611ed34 100644 --- a/tests/Integration/Core/PublishesFilesTest.php +++ b/tests/Integration/Core/PublishesFilesTest.php @@ -23,8 +23,8 @@ protected function setUp(): void parent::setUp(); $this->installer->configure( - __DIR__ . '/install', - new Psr4Namespace('App\\', __DIR__ . '/install/App'), + $this->internalStorage . '/install', + new Psr4Namespace('App\\', $this->internalStorage . '/install/App'), ); } diff --git a/tests/Integration/Core/ViewComponentsInstallerTest.php b/tests/Integration/Core/ViewComponentsInstallerTest.php index 1ea9f9fb8..4283033a7 100644 --- a/tests/Integration/Core/ViewComponentsInstallerTest.php +++ b/tests/Integration/Core/ViewComponentsInstallerTest.php @@ -19,10 +19,10 @@ protected function setUp(): void $this->installer ->configure( - __DIR__ . '/install', - new Psr4Namespace('App\\', __DIR__ . '/install/App'), + $this->internalStorage . '/install', + new Psr4Namespace('App\\', $this->internalStorage . '/install/App'), ) - ->setRoot(__DIR__ . '/install'); + ->setRoot($this->internalStorage . '/install'); $this->registerViewComponent( name: 'x-vendor-a', diff --git a/tests/Integration/Cryptography/GenerateSigningKeyCommandTest.php b/tests/Integration/Cryptography/GenerateSigningKeyCommandTest.php index 56b83ac06..51dac06a6 100644 --- a/tests/Integration/Cryptography/GenerateSigningKeyCommandTest.php +++ b/tests/Integration/Cryptography/GenerateSigningKeyCommandTest.php @@ -21,9 +21,9 @@ protected function setUp(): void protected function tearDown(): void { - parent::tearDown(); - Filesystem\delete_file(root_path('.env')); + + parent::tearDown(); } public function test_creates_dot_env(): void diff --git a/tests/Integration/Database/Commands/MakeMigrationCommandTest.php b/tests/Integration/Database/Commands/MakeMigrationCommandTest.php index decafef87..846727422 100644 --- a/tests/Integration/Database/Commands/MakeMigrationCommandTest.php +++ b/tests/Integration/Database/Commands/MakeMigrationCommandTest.php @@ -20,7 +20,10 @@ final class MakeMigrationCommandTest extends FrameworkIntegrationTestCase #[PreCondition] protected function configure(): void { - $this->installer->configure(__DIR__ . '/install', new Psr4Namespace('App\\', __DIR__ . '/install/App')); + $this->installer->configure( + $this->internalStorage . '/install', + new Psr4Namespace('App\\', $this->internalStorage . '/install/App'), + ); } #[PostCondition] diff --git a/tests/Integration/Database/Commands/MakeModelCommandTest.php b/tests/Integration/Database/Commands/MakeModelCommandTest.php index bbad4d192..0f1d4b72b 100644 --- a/tests/Integration/Database/Commands/MakeModelCommandTest.php +++ b/tests/Integration/Database/Commands/MakeModelCommandTest.php @@ -19,8 +19,8 @@ protected function setUp(): void parent::setUp(); $this->installer->configure( - __DIR__ . '/install', - new Psr4Namespace('App\\', __DIR__ . '/install/App'), + $this->internalStorage . '/install', + new Psr4Namespace('App\\', $this->internalStorage . '/install/App'), ); } diff --git a/tests/Integration/Database/DatabaseConfigTest.php b/tests/Integration/Database/DatabaseConfigTest.php index 3a1d16a74..c6e985e1d 100644 --- a/tests/Integration/Database/DatabaseConfigTest.php +++ b/tests/Integration/Database/DatabaseConfigTest.php @@ -23,7 +23,7 @@ final class DatabaseConfigTest extends FrameworkIntegrationTestCase public function test_strategy_is_taken_into_account(string $strategy, string $expected): void { $this->container->config(new SQLiteConfig( - path: __DIR__ . '/../database.sqlite', + path: $this->internalStorage . '/../database.sqlite', namingStrategy: new $strategy(), )); diff --git a/tests/Integration/Database/MultiDatabaseTest.php b/tests/Integration/Database/MultiDatabaseTest.php index 4c9d48b91..4ae4a94b3 100644 --- a/tests/Integration/Database/MultiDatabaseTest.php +++ b/tests/Integration/Database/MultiDatabaseTest.php @@ -42,8 +42,8 @@ protected function setUp(): void } $files = [ - __DIR__ . '/db-main.sqlite', - __DIR__ . '/db-backup.sqlite', + $this->internalStorage . '/db-main.sqlite', + $this->internalStorage . '/db-backup.sqlite', ]; foreach ($files as $file) { @@ -58,12 +58,12 @@ protected function setUp(): void $this->container->addInitializer(DatabaseInitializer::class); $this->container->config(new SQLiteConfig( - path: __DIR__ . '/db-main.sqlite', + path: $this->internalStorage . '/db-main.sqlite', tag: 'main', )); $this->container->config(new SQLiteConfig( - path: __DIR__ . '/db-backup.sqlite', + path: $this->internalStorage . '/db-backup.sqlite', tag: 'backup', )); } diff --git a/tests/Integration/Discovery/Commands/MakeDiscoveryCommandTest.php b/tests/Integration/Discovery/Commands/MakeDiscoveryCommandTest.php index 87e1ecd40..225c365de 100644 --- a/tests/Integration/Discovery/Commands/MakeDiscoveryCommandTest.php +++ b/tests/Integration/Discovery/Commands/MakeDiscoveryCommandTest.php @@ -19,8 +19,8 @@ protected function setUp(): void parent::setUp(); $this->installer->configure( - __DIR__ . '/install', - new Psr4Namespace('App\\', __DIR__ . '/install/App'), + $this->internalStorage . '/install', + new Psr4Namespace('App\\', $this->internalStorage . '/install/App'), ); } diff --git a/tests/Integration/Http/DatabaseSessionInstallerTest.php b/tests/Integration/Http/DatabaseSessionInstallerTest.php index f1eba3604..a085634ee 100644 --- a/tests/Integration/Http/DatabaseSessionInstallerTest.php +++ b/tests/Integration/Http/DatabaseSessionInstallerTest.php @@ -19,8 +19,8 @@ final class DatabaseSessionInstallerTest extends FrameworkIntegrationTestCase protected function configure(): void { $this->installer - ->configure(__DIR__ . '/install', new Psr4Namespace('App\\', __DIR__ . '/install/App')) - ->setRoot(__DIR__ . '/install'); + ->configure($this->internalStorage . '/install', new Psr4Namespace('App\\', $this->internalStorage . '/install/App')) + ->setRoot($this->internalStorage . '/install'); } #[PostCondition] diff --git a/tests/Integration/Http/MakeControllerCommandTest.php b/tests/Integration/Http/MakeControllerCommandTest.php index 2264c006d..36229d907 100644 --- a/tests/Integration/Http/MakeControllerCommandTest.php +++ b/tests/Integration/Http/MakeControllerCommandTest.php @@ -19,8 +19,8 @@ protected function setUp(): void parent::setUp(); $this->installer->configure( - __DIR__ . '/install', - new Psr4Namespace('App\\', __DIR__ . '/install/App'), + $this->internalStorage . '/install', + new Psr4Namespace('App\\', $this->internalStorage . '/install/App'), ); } diff --git a/tests/Integration/Http/MakeRequestCommandTest.php b/tests/Integration/Http/MakeRequestCommandTest.php index b53656368..5f5456d38 100644 --- a/tests/Integration/Http/MakeRequestCommandTest.php +++ b/tests/Integration/Http/MakeRequestCommandTest.php @@ -19,8 +19,8 @@ protected function setUp(): void parent::setUp(); $this->installer->configure( - __DIR__ . '/install', - new Psr4Namespace('App\\', __DIR__ . '/install/App'), + $this->internalStorage . '/install', + new Psr4Namespace('App\\', $this->internalStorage . '/install/App'), ); } diff --git a/tests/Integration/Http/MakeResponseCommandTest.php b/tests/Integration/Http/MakeResponseCommandTest.php index bf4f0cb43..c387c59f3 100644 --- a/tests/Integration/Http/MakeResponseCommandTest.php +++ b/tests/Integration/Http/MakeResponseCommandTest.php @@ -19,8 +19,8 @@ protected function setUp(): void parent::setUp(); $this->installer->configure( - __DIR__ . '/install', - new Psr4Namespace('App\\', __DIR__ . '/install/App'), + $this->internalStorage . '/install', + new Psr4Namespace('App\\', $this->internalStorage . '/install/App'), ); } diff --git a/tests/Integration/View/Commands/MakeViewCommandTest.php b/tests/Integration/View/Commands/MakeViewCommandTest.php index 348b3b2ae..e970d3946 100644 --- a/tests/Integration/View/Commands/MakeViewCommandTest.php +++ b/tests/Integration/View/Commands/MakeViewCommandTest.php @@ -18,8 +18,8 @@ protected function setUp(): void parent::setUp(); $this->installer->configure( - __DIR__ . '/install', - new Psr4Namespace('App\\', __DIR__ . '/install/App'), + $this->internalStorage . '/install', + new Psr4Namespace('App\\', $this->internalStorage . '/install/App'), ); } diff --git a/tests/Integration/Vite/ViteInstallerTest.php b/tests/Integration/Vite/ViteInstallerTest.php index 9c38f1c42..543df9672 100644 --- a/tests/Integration/Vite/ViteInstallerTest.php +++ b/tests/Integration/Vite/ViteInstallerTest.php @@ -14,12 +14,15 @@ final class ViteInstallerTest extends FrameworkIntegrationTestCase #[PreCondition] protected function configure(): void { - $this->installer->configure(__DIR__ . '/install', new Psr4Namespace('App\\', __DIR__ . '/install/app')); + $this->installer->configure( + $this->internalStorage . '/install', + new Psr4Namespace('App\\', $this->internalStorage . '/install/app'), + ); - mkdir(__DIR__ . '/install/node_modules'); + mkdir($this->internalStorage . '/install/node_modules'); // force usage of npm because bun will mutate Tempest's root install otherwise - touch(__DIR__ . '/install/package-lock.json'); + touch($this->internalStorage . '/install/package-lock.json'); } #[After] diff --git a/tests/Integration/Vite/ViteTest.php b/tests/Integration/Vite/ViteTest.php index a7c7bbb43..9fcceb0cf 100644 --- a/tests/Integration/Vite/ViteTest.php +++ b/tests/Integration/Vite/ViteTest.php @@ -23,7 +23,7 @@ protected function setUp(): void { parent::setUp(); - $this->vite->setRootDirectory(__DIR__ . '/Fixtures/tmp'); + $this->vite->setRootDirectory($this->internalStorage . '/Fixtures/tmp'); } public function test_set_nonce(): void