Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Tempest/Framework/Testing/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Tempest\Http\GenericRequest;
use Tempest\Http\Method;
use Tempest\Http\Request;
use Tempest\Database\DatabaseInitializer;
use Tempest\Mail\Testing\MailTester;
use Tempest\Mail\Testing\TestingMailer;
use Tempest\Process\Testing\ProcessTester;
Expand Down Expand Up @@ -208,6 +209,14 @@ protected function setupBaseRequest(): self
return $this;
}

protected function useTestingDatabase(): self
{
$this->container->removeInitializer(DatabaseInitializer::class);
$this->container->addInitializer(TestingDatabaseInitializer::class);

return $this;
}

protected function clock(DateTimeInterface|string $now = 'now'): MockClock
{
$clock = new MockClock($now);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Tests\Tempest\Integration;
namespace Tempest\Framework\Testing;

use Tempest\Container\Container;
use Tempest\Container\DynamicInitializer;
Expand All @@ -13,12 +13,14 @@
use Tempest\Database\Database;
use Tempest\Database\GenericDatabase;
use Tempest\Database\Transactions\GenericTransactionManager;
use Tempest\Discovery\SkipDiscovery;
use Tempest\EventBus\EventBus;
use Tempest\Mapper\SerializerFactory;
use Tempest\Reflection\ClassReflector;
use Tempest\Support\Str;
use UnitEnum;

#[SkipDiscovery]
final class TestingDatabaseInitializer implements DynamicInitializer
{
/** @var Connection[] */
Expand Down
3 changes: 1 addition & 2 deletions tests/Integration/Database/MultiDatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@
use Tempest\Database\QueryStatements\CreateTableStatement;
use Tempest\Database\QueryStatements\DropTableStatement;
use Tempest\Database\ShouldMigrate;
use Tempest\Framework\Testing\TestingDatabaseInitializer;
use Tests\Tempest\Fixtures\Migrations\CreateBookTable;
use Tests\Tempest\Fixtures\Migrations\CreatePublishersTable;
use Tests\Tempest\Fixtures\Modules\Books\Models\Book;
use Tests\Tempest\Fixtures\Modules\Books\Models\Publisher;
use Tests\Tempest\Integration\FrameworkIntegrationTestCase;
use Tests\Tempest\Integration\TestingDatabaseInitializer;

use function Tempest\Database\query;

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/FrameworkIntegrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
use Tempest\Database\DatabaseInitializer;
use Tempest\Discovery\DiscoveryLocation;
use Tempest\Framework\Testing\IntegrationTest;
use Tempest\Framework\Testing\TestingDatabaseInitializer;
use Tempest\Support\Filesystem;
use Tempest\Support\Path;

use function Tempest\Support\str;

abstract class FrameworkIntegrationTestCase extends IntegrationTest
Expand Down
Loading