Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Kreyu committed Nov 24, 2024
1 parent 2e48fb3 commit cb7fae3
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 139 deletions.
87 changes: 72 additions & 15 deletions src/Test/Column/Type/ColumnTypeTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
namespace Kreyu\Bundle\DataTableBundle\Test\Column\Type;

use Kreyu\Bundle\DataTableBundle\Column\ColumnFactoryInterface;
use Kreyu\Bundle\DataTableBundle\Column\ColumnInterface;
use Kreyu\Bundle\DataTableBundle\Column\ColumnRegistry;
use Kreyu\Bundle\DataTableBundle\Column\ColumnRegistryInterface;
use Kreyu\Bundle\DataTableBundle\Column\Type\ColumnTypeInterface;
use Kreyu\Bundle\DataTableBundle\Column\Type\ResolvedColumnTypeFactory;
use Kreyu\Bundle\DataTableBundle\Column\Type\ResolvedColumnTypeFactoryInterface;
use Kreyu\Bundle\DataTableBundle\DataTableFactory;
use Kreyu\Bundle\DataTableBundle\DataTableFactoryInterface;
use Kreyu\Bundle\DataTableBundle\DataTableInterface;
Expand All @@ -17,56 +20,110 @@
use Kreyu\Bundle\DataTableBundle\Tests\Fixtures\Column\TestColumnFactory;
use Kreyu\Bundle\DataTableBundle\Type\DataTableType;
use Kreyu\Bundle\DataTableBundle\Type\ResolvedDataTableTypeFactory;
use Kreyu\Bundle\DataTableBundle\Type\ResolvedDataTableTypeFactoryInterface;
use PHPUnit\Framework\TestCase;

abstract class ColumnTypeTestCase extends TestCase
{
protected ColumnFactoryInterface $factory;
protected ColumnFactoryInterface $columnFactory;
protected ColumnRegistryInterface $columnRegistry;
protected ResolvedColumnTypeFactoryInterface $resolvedColumnTypeFactory;
protected DataTableFactoryInterface $dataTableFactory;
protected DataTableRegistryInterface $dataTableRegistry;
protected ResolvedDataTableTypeFactoryInterface $resolvedDataTableTypeFactory;
protected DataTableInterface $dataTable;

protected function setUp(): void
abstract protected function getTestedColumnType(): ColumnTypeInterface;

protected function createColumn(array $options = []): ColumnInterface
{
return $this->getColumnFactory()->create($this->getTestedColumnType()::class, $options);
}

protected function createNamedColumn(string $name, array $options = []): ColumnInterface
{
parent::setUp();
return $this->getColumnFactory()->createNamed($name, $this->getTestedColumnType()::class, $options);
}

$this->recreateFactoryWithType($this->instantiateType());
protected function getColumnFactory(): ColumnFactoryInterface
{
return $this->columnFactory ??= $this->createColumnFactory();
}

protected function recreateFactoryWithType(ColumnTypeInterface $type): void
protected function createColumnFactory(): ColumnFactoryInterface
{
$registry = new ColumnRegistry(
types: [$type],
$factory = new TestColumnFactory($this->getColumnRegistry());
$factory->setDataTable($this->getDataTable());

return $factory;
}

protected function getColumnRegistry(): ColumnRegistryInterface
{
return $this->columnRegistry ??= $this->createColumnRegistry();
}

protected function createColumnRegistry(): ColumnRegistryInterface
{
return new ColumnRegistry(
types: [$this->getTestedColumnType()],
typeExtensions: [],
resolvedTypeFactory: new ResolvedColumnTypeFactory(),
resolvedTypeFactory: $this->getResolvedColumnTypeFactory(),
);
}

$this->factory = new TestColumnFactory($registry);
$this->factory->setDataTable($this->getDataTable());
protected function getResolvedColumnTypeFactory(): ResolvedColumnTypeFactoryInterface
{
return $this->resolvedColumnTypeFactory ??= $this->createResolvedColumnTypeFactory();
}

protected function instantiateType(): ColumnTypeInterface
protected function createResolvedColumnTypeFactory(): ResolvedColumnTypeFactoryInterface
{
return new ($this->getTestedType());
return new ResolvedColumnTypeFactory();
}

abstract protected function getTestedType(): string;
protected function getDataTableRegistry(): DataTableRegistryInterface
{
return $this->dataTableRegistry ??= $this->createDataTableRegistry();
}

protected function createDataTableRegistry(): DataTableRegistryInterface
{
return new DataTableRegistry(
types: [new DataTableType()],
typeExtensions: [],
proxyQueryFactories: [],
resolvedTypeFactory: new ResolvedDataTableTypeFactory(),
resolvedTypeFactory: $this->getResolvedDataTableTypeFactory(),
);
}

protected function getDataTableFactory(): DataTableFactoryInterface
{
return $this->dataTableFactory ??= $this->createDataTableFactory();
}

protected function createDataTableFactory(): DataTableFactoryInterface
{
return new DataTableFactory($this->createDataTableRegistry());
}

protected function getResolvedDataTableTypeFactory(): ResolvedDataTableTypeFactoryInterface
{
return $this->resolvedDataTableTypeFactory ??= $this->createResolvedDataTableTypeFactory();
}

protected function createResolvedDataTableTypeFactory(): ResolvedDataTableTypeFactoryInterface
{
return new ResolvedDataTableTypeFactory();
}

protected function getDataTable(): DataTableInterface
{
return $this->dataTable ??= $this->createDataTableFactory()->create(DataTableType::class, new ArrayProxyQuery([]));
return $this->dataTable ??= $this->createDataTable();
}

protected function createDataTable(): DataTableInterface
{
return $this->getDataTableFactory()->create(DataTableType::class, new ArrayProxyQuery([]));
}
}
7 changes: 6 additions & 1 deletion tests/Fixtures/Column/TestColumnFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use Kreyu\Bundle\DataTableBundle\Column\Type\ColumnType;
use Kreyu\Bundle\DataTableBundle\DataTableInterface;

/**
* Column factory that automatically sets the data table on created column.
*/
class TestColumnFactory extends ColumnFactory
{
private DataTableInterface $dataTable;
Expand All @@ -29,8 +32,10 @@ public function createNamed(string $name, string $type = ColumnType::class, arra
return $column;
}

public function setDataTable(DataTableInterface $dataTable): void
public function setDataTable(DataTableInterface $dataTable): self
{
$this->dataTable = $dataTable;

return $this;
}
}
Loading

0 comments on commit cb7fae3

Please sign in to comment.