Writing unit tests for custom generators and types #8647
-
My application makes use of a custom id type which maps to a time-based identity, it also makes use of a custom generator for these values. What's the best way to write tests for this? e.g. Initializing the EntityManager etc (within Symfony Flex.) namespace App\Tests\Support\Database\Identity;
use App\Support\Database\Identity\Type;
use Doctrine\DBAL\Platforms\PostgreSQL100Platform;
use PHPUnit\Framework\TestCase;
final class TypeTests extends TestCase
{
public function testGetSqlDeclaration(): void
{
$type = new Type();
$this->assertEquals('ksuid', $type->getSQLDeclaration([], new PostgreSQL100Platform()));
}
} This works well enough to handle the SQL declaration, but to test serialization and deserialization of DB values, or the ID generator which needs an active EntityManager, how would I approach this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
For an integration test, Use the KernelTestCase from Symfony and fetch the entity manager service from the container. |
Beta Was this translation helpful? Give feedback.
For an integration test, Use the KernelTestCase from Symfony and fetch the entity manager service from the container.