diff --git a/composer.json b/composer.json index 94bc96f8..db74eac2 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/ParametersProvider.php b/src/ParametersProvider.php index b3f055c1..8219c5c7 100644 --- a/src/ParametersProvider.php +++ b/src/ParametersProvider.php @@ -11,7 +11,7 @@ public function __construct( * @var array> 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 = [], ) { } diff --git a/tests/Generators/ActiveRecordGeneratorTest.php b/tests/Generators/ActiveRecordGeneratorTest.php index 841a48a6..0d939cfd 100644 --- a/tests/Generators/ActiveRecordGeneratorTest.php +++ b/tests/Generators/ActiveRecordGeneratorTest.php @@ -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( diff --git a/tests/Support/test.db b/tests/Support/test.db new file mode 100644 index 00000000..32e7cfb5 Binary files /dev/null and b/tests/Support/test.db differ diff --git a/tests/TestCase.php b/tests/TestCase.php index 65573ce5..9dfc3aa5 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -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; @@ -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);