-
-
Notifications
You must be signed in to change notification settings - Fork 479
Expand file tree
/
Copy pathRegisterDbalTypePassTest.php
More file actions
82 lines (61 loc) · 2.62 KB
/
RegisterDbalTypePassTest.php
File metadata and controls
82 lines (61 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
declare(strict_types=1);
namespace Doctrine\Bundle\DoctrineBundle\Tests\DependencyInjection\Compiler;
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\RegisterDbalTypePass;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use function sprintf;
class RegisterDbalTypePassTest extends TestCase
{
public function testTaggedTypeAreAdded(): void
{
$container = new ContainerBuilder();
$container->addCompilerPass(new RegisterDbalTypePass());
$container->setParameter('doctrine.dbal.connection_factory.types', []);
$container->register(BarType::class)
->addTag('doctrine.dbal.type', ['name' => 'bar'])
->addTag('container.excluded');
$container->compile();
self::assertSame(['bar' => ['class' => BarType::class]], $container->getParameter('doctrine.dbal.connection_factory.types'));
}
public function testTagMustHaveANameAttribute(): void
{
$container = new ContainerBuilder();
$container->addCompilerPass(new RegisterDbalTypePass());
$container->setParameter('doctrine.dbal.connection_factory.types', []);
$container->register(BarType::class)
->addTag('doctrine.dbal.type')
->addTag('container.excluded');
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage(
sprintf('The "name" attribute is mandatory for the "doctrine.dbal.type" tag on the "%s" type.', BarType::class),
);
$container->compile();
}
public function testTypeMustBeASubclassOfTheDbalBaseType(): void
{
$container = new ContainerBuilder();
$container->addCompilerPass(new RegisterDbalTypePass());
$container->setParameter('doctrine.dbal.connection_factory.types', []);
$container->register(NotASubClassOfDbalBaseType::class)
->addTag('doctrine.dbal.type', ['name' => 'invalid_type'])
->addTag('container.excluded');
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage(sprintf('The "%s" class must extends "%s".', NotASubClassOfDbalBaseType::class, Type::class));
$container->compile();
}
}
class BarType extends Type
{
/** @param array<string, mixed> $column */
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
return 'bar';
}
}
class NotASubClassOfDbalBaseType
{
}