-
Notifications
You must be signed in to change notification settings - Fork 0
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
10 changed files
with
183 additions
and
36 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
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,32 @@ | ||
<?php | ||
|
||
namespace PChapl\Tests\DependencyInjection; | ||
|
||
use PChapl\DoctrineIdBundle\DependencyInjection\Configuration; | ||
use PChapl\DoctrineIdBundle\DoctrineIdBundle; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ConfigurationTest extends TestCase | ||
{ | ||
private const TYPES = [ | ||
DoctrineIdBundle::CONFIG_TYPES_KEY => [ | ||
'account_id' => 'App\Data\AccountId', | ||
'user_id' => 'App\Data\UserId', | ||
], | ||
]; | ||
|
||
private Configuration $configuration; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->configuration = new Configuration(); | ||
} | ||
|
||
public function testTree(): void | ||
{ | ||
$tree = $this->configuration->getConfigTreeBuilder()->buildTree(); | ||
|
||
self::assertSame(DoctrineIdBundle::BUNDLE_ID, $tree->getName()); | ||
self::assertSame(self::TYPES, $tree->normalize(self::TYPES)); | ||
} | ||
} |
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,92 @@ | ||
<?php | ||
|
||
namespace PChapl\Tests\DependencyInjection; | ||
|
||
use PChapl\DoctrineIdBundle\DependencyInjection\DoctrineIdExtension; | ||
use PChapl\DoctrineIdBundle\DoctrineIdBundle; | ||
use PChapl\DoctrineIdBundle\Exception\InvalidConfigurationException; | ||
use PChapl\Tests\TestId; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
class DoctrineIdExtensionTest extends TestCase | ||
{ | ||
private const TEST_ID_TYPE_NAME = 'test_id_type_name'; | ||
private const CONFIGS = [ | ||
[ | ||
DoctrineIdBundle::CONFIG_TYPES_KEY => [ | ||
self::TEST_ID_TYPE_NAME => TestId::class, | ||
], | ||
], | ||
]; | ||
|
||
/** @var MockObject&ContainerBuilder */ | ||
private MockObject|ContainerBuilder $container; | ||
private DoctrineIdExtension $extension; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->extension = new DoctrineIdExtension(); | ||
|
||
/** @var ContainerBuilder&MockObject $container */ | ||
$container = $this->createMock(ContainerBuilder::class); | ||
$this->container = $container; | ||
} | ||
|
||
public function testLoad(): void | ||
{ | ||
$this->container | ||
->expects($this->once()) | ||
->method('setParameter') | ||
->willReturnCallback( | ||
static function (string $name, mixed $value) { | ||
self::assertSame(DoctrineIdBundle::TYPES_PARAMETER_NAME, $name); | ||
self::assertIsArray($value); | ||
self::assertCount(1, $value); | ||
|
||
foreach ($value as $k => $v) { | ||
self::assertSame(self::TEST_ID_TYPE_NAME, $k); | ||
self::assertSame(TestId::class, $v); | ||
} | ||
} | ||
); | ||
|
||
$this->extension->load(self::CONFIGS, $this->container); | ||
} | ||
|
||
public function testLoadFailsOnClass(): void | ||
{ | ||
$this->expectException(InvalidConfigurationException::class); | ||
$this->expectExceptionMessage("Can not load class 'fake-class'"); | ||
|
||
$this->extension->load( | ||
[[DoctrineIdBundle::CONFIG_TYPES_KEY => [self::TEST_ID_TYPE_NAME => 'fake-class']]], | ||
$this->container, | ||
); | ||
} | ||
|
||
public function testLoadFailsOnDuplicate(): void | ||
{ | ||
$duplicatedId = 'test_duplicated_id'; | ||
|
||
$this->container->method('hasParameter')->willReturnCallback( | ||
static fn (string $name): bool => $name === 'doctrine.dbal.connection_factory.types', | ||
); | ||
$this->container->method('getParameter')->willReturnCallback( | ||
static fn (string $name) => $name === 'doctrine.dbal.connection_factory.types' | ||
? [$duplicatedId => TestId::class] | ||
: null, | ||
); | ||
|
||
$this->expectException(InvalidConfigurationException::class); | ||
$this->expectExceptionMessage( | ||
"Duplicate key \"$duplicatedId\": type should be described either for doctrine_id.types or doctrine.dbal.types" | ||
); | ||
|
||
$this->extension->load( | ||
[[DoctrineIdBundle::CONFIG_TYPES_KEY => [$duplicatedId => TestId::class]]], | ||
$this->container, | ||
); | ||
} | ||
} |
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,39 @@ | ||
<?php | ||
|
||
namespace PChapl\Tests; | ||
|
||
use PChapl\DoctrineIdBundle\DoctrineIdBundle; | ||
use PChapl\DoctrineIdBundle\Id\Type; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
class DoctrineIdBundleTest extends TestCase | ||
{ | ||
private const TEST_ID_TYPE_NAME = 'test_id_type_name'; | ||
|
||
private DoctrineIdBundle $bundle; | ||
|
||
private array $parameters = [ | ||
DoctrineIdBundle::TYPES_PARAMETER_NAME => [ | ||
self::TEST_ID_TYPE_NAME => TestId::class, | ||
], | ||
]; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->bundle = new DoctrineIdBundle(); | ||
/** @var ContainerInterface&MockObject $container */ | ||
$container = $this->createMock(ContainerInterface::class); | ||
$this->bundle->setContainer($container); | ||
$container->method('getParameter')->willReturnCallback(fn (string $name) => $this->parameters[$name] ?? null); | ||
} | ||
|
||
public function testBoot(): void | ||
{ | ||
self::assertFalse(Type::hasType(self::TEST_ID_TYPE_NAME)); | ||
$this->bundle->boot(); | ||
self::assertTrue(Type::hasType(self::TEST_ID_TYPE_NAME)); | ||
self::assertInstanceOf(Type::class, Type::getType(self::TEST_ID_TYPE_NAME)); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
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