Skip to content

Commit

Permalink
Fix db tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xepozz committed Aug 31, 2023
1 parent 7963600 commit 5c6f67b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^5.13",
"yiisoft/active-record": "^3.0@dev",
"yiisoft/cache": "^3.0",
"yiisoft/db-sqlite": "^1.0",
"yiisoft/di": "^1.1",
"yiisoft/dummy-provider": "^1.0",
"yiisoft/event-dispatcher": "^1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/ParametersProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function __construct(
* @var array<string, array<string, string>> a list of available code templates. The array keys are the template names,
* and the array values are the corresponding template paths or path aliases.
*/
private array $templates = [],
private readonly array $templates = [],
) {
}

Expand Down
14 changes: 14 additions & 0 deletions tests/Generators/ActiveRecordGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ public function testValidGenerator(): void
$this->assertNotEmpty($files);
}

public function testInvalidTableName(): void
{
$generator = $this->createGenerator();
$command = new Command(
namespace: 'App\\Model',
tableName: 'user2',
baseClass: ActiveRecord::class,
template: 'default',
);

$this->expectException(InvalidGeneratorCommandException::class);
$generator->generate($command);
}

public function testInvalidGenerator(): void
{
$generator = $this->createGenerator(
Expand Down
Binary file added tests/Support/test.db
Binary file not shown.
12 changes: 12 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
use Psr\EventDispatcher\ListenerProviderInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Psr\SimpleCache\CacheInterface;
use Yiisoft\Aliases\Aliases;
use Yiisoft\Cache\NullCache;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Sqlite\Connection as SqliteConnection;
use Yiisoft\Db\Sqlite\Driver;
use Yiisoft\Definitions\Reference;
use Yiisoft\Di\Container;
use Yiisoft\Di\ContainerConfig;
Expand Down Expand Up @@ -80,6 +85,13 @@ protected function getContainer(array $definitions = []): ContainerInterface
],
RuleHandlerResolverInterface::class => RuleHandlerContainer::class,
ValidatorInterface::class => Validator::class,
CacheInterface::class => NullCache::class,
ConnectionInterface::class => [
'class' => SqliteConnection::class,
'__construct()' => [
new Driver('sqlite:' . __DIR__ . '/Support/test.db'),
],
],
...$definitions,
]);
$this->container = new Container($config);
Expand Down

0 comments on commit 5c6f67b

Please sign in to comment.