Skip to content
Merged
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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
30 changes: 30 additions & 0 deletions src/Factory/ClickHouseMigrationFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/*
* This file is part of the FiveLab Migrator package
*
* (c) FiveLab
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code
*/

declare(strict_types = 1);

namespace FiveLab\Component\Migrator\Factory;

use ClickHouseDB\Client;
use FiveLab\Component\Migrator\Migration\MigrationInterface;
use FiveLab\Component\Migrator\MigrationMetadata;

readonly class ClickHouseMigrationFactory implements MigrationFactoryInterface
{
public function __construct(private Client $client)
{
}

public function create(MigrationMetadata $metadata): MigrationInterface
{
return $metadata->class->newInstance($this->client);
}
}
43 changes: 43 additions & 0 deletions tests/Migrations/DataSet04/Version01.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/*
* This file is part of the FiveLab Migrator package
*
* (c) FiveLab
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code
*/

declare(strict_types = 1);

namespace FiveLab\Component\Migrator\Tests\Migrations\DataSet04;

use ClickHouseDB\Client;
use FiveLab\Component\Migrator\Migration\AbstractMigration;

readonly class Version01 extends AbstractMigration
{
public function __construct(private Client $client)
{
}

public function getDescription(): string
{
return 'pdo version 01';
}

public function up(): void
{
$this->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');
}
}
46 changes: 46 additions & 0 deletions tests/Unit/Factory/ClickHouseMigrationFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/*
* This file is part of the FiveLab Migrator package
*
* (c) FiveLab
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code
*/

declare(strict_types = 1);

namespace FiveLab\Component\Migrator\Tests\Unit\Factory;

use ClickHouseDB\Client;
use FiveLab\Component\Migrator\Factory\ClickHouseMigrationFactory;
use FiveLab\Component\Migrator\MigrationMetadata;
use FiveLab\Component\Migrator\Tests\Migrations\DataSet04\Version01;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

class ClickHouseMigrationFactoryTest extends TestCase
{
private Client $client;

protected function setUp(): void
{
$this->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);
}
}
Loading