diff --git a/composer.json b/composer.json index 97ea72a..4bb9131 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,8 @@ "matthiasnoback/symfony-dependency-injection-test": "~6.1.0", "symfony/console": "~6.4 | ~7.0", "symfony/dependency-injection": "~6.4 | ~7.0", - "symfony/config": "~6.4 | ~7.0" + "symfony/config": "~6.4 | ~7.0", + "smi2/phpclickhouse": "~1.6.0" }, "minimum-stability": "RC", diff --git a/src/Factory/ClickHouseMigrationFactory.php b/src/Factory/ClickHouseMigrationFactory.php new file mode 100644 index 0000000..b31aeba --- /dev/null +++ b/src/Factory/ClickHouseMigrationFactory.php @@ -0,0 +1,30 @@ +class->newInstance($this->client); + } +} diff --git a/tests/Migrations/DataSet04/Version01.php b/tests/Migrations/DataSet04/Version01.php new file mode 100644 index 0000000..afa3df2 --- /dev/null +++ b/tests/Migrations/DataSet04/Version01.php @@ -0,0 +1,43 @@ +client->write('CREATE TABLE test_1 ( + id UInt32, + created_at DATETIME, + label String + ) ENGINE=MergeTree ORDER BY (created_at)'); + } + + public function down(): void + { + $this->client->write('DROP TABLE test_1'); + } +} diff --git a/tests/Unit/Factory/ClickHouseMigrationFactoryTest.php b/tests/Unit/Factory/ClickHouseMigrationFactoryTest.php new file mode 100644 index 0000000..ea7da0f --- /dev/null +++ b/tests/Unit/Factory/ClickHouseMigrationFactoryTest.php @@ -0,0 +1,46 @@ +client = $this->createMock(Client::class); + } + + #[Test] + public function shouldSuccessCreate(): void + { + $factory = new ClickHouseMigrationFactory($this->client); + $metadata = MigrationMetadata::fromPhpFile('clickhouse', __DIR__.'/../../Migrations/DataSet04/Version01.php'); + $migration = $factory->create($metadata); + + self::assertInstanceOf(Version01::class, $migration); + + $refClient = new \ReflectionProperty($migration, 'client'); + $client = $refClient->getValue($migration); + + self::assertEquals($this->client, $client); + } +}