-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
1,197 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kreyu\Bundle\DataTableBundle\Test\Column\Type; | ||
|
||
use Kreyu\Bundle\DataTableBundle\Column\ColumnFactoryInterface; | ||
use Kreyu\Bundle\DataTableBundle\Column\ColumnRegistry; | ||
use Kreyu\Bundle\DataTableBundle\Column\Type\ColumnTypeInterface; | ||
use Kreyu\Bundle\DataTableBundle\Column\Type\ResolvedColumnTypeFactory; | ||
use Kreyu\Bundle\DataTableBundle\DataTableFactory; | ||
use Kreyu\Bundle\DataTableBundle\DataTableFactoryInterface; | ||
use Kreyu\Bundle\DataTableBundle\DataTableInterface; | ||
use Kreyu\Bundle\DataTableBundle\DataTableRegistry; | ||
use Kreyu\Bundle\DataTableBundle\DataTableRegistryInterface; | ||
use Kreyu\Bundle\DataTableBundle\Query\ArrayProxyQuery; | ||
use Kreyu\Bundle\DataTableBundle\Tests\Fixtures\Column\TestColumnFactory; | ||
use Kreyu\Bundle\DataTableBundle\Type\DataTableType; | ||
use Kreyu\Bundle\DataTableBundle\Type\ResolvedDataTableTypeFactory; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
abstract class ColumnTypeTestCase extends TestCase | ||
{ | ||
protected ColumnFactoryInterface $factory; | ||
protected DataTableInterface $dataTable; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->recreateFactoryWithType($this->instantiateType()); | ||
} | ||
|
||
protected function recreateFactoryWithType(ColumnTypeInterface $type): void | ||
{ | ||
$registry = new ColumnRegistry( | ||
types: [$type], | ||
typeExtensions: [], | ||
resolvedTypeFactory: new ResolvedColumnTypeFactory(), | ||
); | ||
|
||
$this->factory = new TestColumnFactory($registry); | ||
$this->factory->setDataTable($this->getDataTable()); | ||
} | ||
|
||
protected function instantiateType(): ColumnTypeInterface | ||
{ | ||
return new ($this->getTestedType()); | ||
} | ||
|
||
abstract protected function getTestedType(): string; | ||
|
||
protected function createDataTableRegistry(): DataTableRegistryInterface | ||
{ | ||
return new DataTableRegistry( | ||
types: [new DataTableType()], | ||
typeExtensions: [], | ||
proxyQueryFactories: [], | ||
resolvedTypeFactory: new ResolvedDataTableTypeFactory(), | ||
); | ||
} | ||
|
||
protected function createDataTableFactory(): DataTableFactoryInterface | ||
{ | ||
return new DataTableFactory($this->createDataTableRegistry()); | ||
} | ||
|
||
protected function getDataTable(): DataTableInterface | ||
{ | ||
return $this->dataTable ??= $this->createDataTableFactory()->create(DataTableType::class, new ArrayProxyQuery([])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kreyu\Bundle\DataTableBundle\Tests\Fixtures\Column; | ||
|
||
use Kreyu\Bundle\DataTableBundle\Column\ColumnFactory; | ||
use Kreyu\Bundle\DataTableBundle\Column\ColumnInterface; | ||
use Kreyu\Bundle\DataTableBundle\Column\Type\ColumnType; | ||
use Kreyu\Bundle\DataTableBundle\DataTableInterface; | ||
|
||
class TestColumnFactory extends ColumnFactory | ||
{ | ||
private DataTableInterface $dataTable; | ||
|
||
public function create(string $type = ColumnType::class, array $options = []): ColumnInterface | ||
{ | ||
$column = parent::create($type, $options); | ||
$column->setDataTable($this->dataTable); | ||
|
||
return $column; | ||
} | ||
|
||
public function createNamed(string $name, string $type = ColumnType::class, array $options = []): ColumnInterface | ||
{ | ||
$column = parent::createNamed($name, $type, $options); | ||
$column->setDataTable($this->dataTable); | ||
|
||
return $column; | ||
} | ||
|
||
public function setDataTable(DataTableInterface $dataTable): void | ||
{ | ||
$this->dataTable = $dataTable; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kreyu\Bundle\DataTableBundle\Tests\Fixtures\Model; | ||
|
||
use Symfony\Contracts\Translation\TranslatableInterface; | ||
|
||
class User | ||
{ | ||
public function __construct( | ||
public null|string|TranslatableInterface $firstName = null, | ||
) { | ||
} | ||
|
||
public function getFirstNameUppercased(): string | ||
{ | ||
return strtoupper($this->firstName); | ||
} | ||
} |
Oops, something went wrong.