Skip to content

Commit

Permalink
Merge pull request #5 from Siniliote/feat/update-dbal-orm
Browse files Browse the repository at this point in the history
feat: Updating dependencies doctrine/dbal and doctrine/orm
  • Loading branch information
yann-eugone authored May 23, 2024
2 parents 7072aec + fc94d0d commit eec14b3
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 26 deletions.
13 changes: 7 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
}
],
"require": {
"php": "^8.0",
"doctrine/orm": "^2.7",
"webmozart/assert": "^1.9"
"php": "^8",
"doctrine/orm": "^2.7|^3.1",
"doctrine/dbal": "^3.8|^4.0",
"webmozart/assert": "^1.11"
},
"autoload": {
"psr-4": {
Expand All @@ -21,9 +22,9 @@
},
"require-dev": {
"phpunit/phpunit": "^9.4",
"phpstan/phpstan": "^0.12.76",
"squizlabs/php_codesniffer": "^3.5",
"symfony/cache": "^5.4|^6.0"
"phpstan/phpstan": "^1.11",
"squizlabs/php_codesniffer": "^3.9",
"symfony/cache": "^5.4|^6.0|^7.0"
},
"autoload-dev": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
parameters:
level: max
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
paths:
- src/

ignoreErrors:
- identifier: missingType.iterableValue
- identifier: missingType.generics
# callable with array syntax is not inferred
- '#.*function call_user_func expects callable.*#'
20 changes: 17 additions & 3 deletions src/Doctrine/Types/CollectionValueObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,22 @@

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\JsonType;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use Webmozart\Assert\Assert;
use Yokai\DoctrineValueObject\CollectionValueObject;

final class CollectionValueObjectType extends JsonType
final class CollectionValueObjectType extends Type
{
use ValueObjectType;

public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
/** @var JsonType $typeInherit */
$typeInherit = $this->getType(Types::JSON);
return $typeInherit->getSQLDeclaration($column, $platform);
}

/**
* @inheritdoc
*/
Expand All @@ -33,15 +42,20 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): ?str
Assert::isInstanceOf($value, $this->class);
/** @var CollectionValueObject $value */

return parent::convertToDatabaseValue($value->toValue(), $platform);
/** @var JsonType $typeInherit */
$typeInherit = $this->getType(Types::JSON);
return $typeInherit->convertToDatabaseValue($value->toValue(), $platform);
}

/**
* @inheritdoc
*/
public function convertToPHPValue($value, AbstractPlatform $platform): ?CollectionValueObject
{
$value = parent::convertToPHPValue($value, $platform);
/** @var JsonType $typeInherit */
$typeInherit = $this->getType(Types::JSON);
$value = $typeInherit->convertToPHPValue($value, $platform);

if ($value === null) {
return null;
}
Expand Down
22 changes: 18 additions & 4 deletions src/Doctrine/Types/DateTimeValueObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,22 @@
use DateTimeImmutable;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\DateTimeTzImmutableType;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use Webmozart\Assert\Assert;
use Yokai\DoctrineValueObject\DateTimeValueObject;

final class DateTimeValueObjectType extends DateTimeTzImmutableType
final class DateTimeValueObjectType extends Type
{
use ValueObjectType;

public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
/** @var DateTimeTzImmutableType $typeInherit */
$typeInherit = $this->getType(Types::DATETIMETZ_IMMUTABLE);
return $typeInherit->getSQLDeclaration($column, $platform);
}

/**
* @inheritdoc
*/
Expand All @@ -34,15 +43,20 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): ?str
Assert::isInstanceOf($value, $this->class);
/** @var DateTimeValueObject $value */

return parent::convertToDatabaseValue($value->toValue(), $platform);
/** @var DateTimeTzImmutableType $typeInherit */
$typeInherit = $this->getType(Types::DATETIMETZ_IMMUTABLE);
return $typeInherit->convertToDatabaseValue($value->toValue(), $platform);
}

/**
* @inheritdoc
*/
public function convertToPHPValue($value, AbstractPlatform $platform): ?DateTimeValueObject
public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?DateTimeValueObject
{
$value = parent::convertToPHPValue($value, $platform);
/** @var DateTimeTzImmutableType $typeInherit */
$typeInherit = $this->getType(Types::DATETIMETZ_IMMUTABLE);
$value = $typeInherit->convertToPHPValue($value, $platform);

if ($value === null) {
return null;
}
Expand Down
20 changes: 17 additions & 3 deletions src/Doctrine/Types/IntegerValueObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,22 @@

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\IntegerType;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use Webmozart\Assert\Assert;
use Yokai\DoctrineValueObject\IntegerValueObject;

final class IntegerValueObjectType extends IntegerType
final class IntegerValueObjectType extends Type
{
use ValueObjectType;

public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
/** @var IntegerType $typeInherit */
$typeInherit = $this->getType(Types::INTEGER);
return $typeInherit->getSQLDeclaration($column, $platform);
}

/**
* @inheritdoc
*/
Expand All @@ -33,15 +42,20 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): ?int
Assert::isInstanceOf($value, $this->class);
/** @var IntegerValueObject $value */

return parent::convertToPHPValue($value->toValue(), $platform);
/** @var IntegerType $typeInherit */
$typeInherit = $this->getType(Types::INTEGER);
return $typeInherit->convertToPHPValue($value->toValue(), $platform);
}

/**
* @inheritdoc
*/
public function convertToPHPValue($value, AbstractPlatform $platform): ?IntegerValueObject
{
$value = parent::convertToPHPValue($value, $platform);
/** @var IntegerType $typeInherit */
$typeInherit = $this->getType(Types::INTEGER);
$value = $typeInherit->convertToPHPValue($value, $platform);

if ($value === null) {
return null;
}
Expand Down
20 changes: 17 additions & 3 deletions src/Doctrine/Types/ObjectValueObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,22 @@

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\JsonType;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use Webmozart\Assert\Assert;
use Yokai\DoctrineValueObject\ObjectValueObject;

final class ObjectValueObjectType extends JsonType
final class ObjectValueObjectType extends Type
{
use ValueObjectType;

public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
/** @var JsonType $typeInherit */
$typeInherit = $this->getType(Types::JSON);
return $typeInherit->getSQLDeclaration($column, $platform);
}

/**
* @inheritdoc
*/
Expand All @@ -33,15 +42,20 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): ?str
Assert::isInstanceOf($value, $this->class);
/** @var ObjectValueObject $value */

return parent::convertToDatabaseValue($value->toValue(), $platform);
/** @var JsonType $typeInherit */
$typeInherit = $this->getType(Types::JSON);
return $typeInherit->convertToDatabaseValue($value->toValue(), $platform);
}

/**
* @inheritdoc
*/
public function convertToPHPValue($value, AbstractPlatform $platform): ?ObjectValueObject
{
$value = parent::convertToPHPValue($value, $platform);
/** @var JsonType $typeInherit */
$typeInherit = $this->getType(Types::JSON);
$value = $typeInherit->convertToPHPValue($value, $platform);

if ($value === null) {
return null;
}
Expand Down
22 changes: 18 additions & 4 deletions src/Doctrine/Types/StringValueObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,22 @@

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\StringType;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use Webmozart\Assert\Assert;
use Yokai\DoctrineValueObject\StringValueObject;

final class StringValueObjectType extends StringType
final class StringValueObjectType extends Type
{
use ValueObjectType;

public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
/** @var StringType $typeInherit */
$typeInherit = $this->getType(Types::STRING);
return $typeInherit->getSQLDeclaration($column, $platform);
}

/**
* @inheritdoc
*/
Expand All @@ -24,7 +33,7 @@ public static function getSupportedValueObjectType(): string
/**
* @inheritdoc
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string
public function convertToDatabaseValue($value, AbstractPlatform $platform): mixed
{
if ($value === null) {
return null;
Expand All @@ -33,15 +42,20 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): ?str
Assert::isInstanceOf($value, $this->class);
/** @var StringValueObject $value */

return parent::convertToDatabaseValue($value->toValue(), $platform);
/** @var StringType $typeInherit */
$typeInherit = $this->getType(Types::STRING);
return $typeInherit->convertToDatabaseValue($value->toValue(), $platform);
}

/**
* @inheritdoc
*/
public function convertToPHPValue($value, AbstractPlatform $platform): ?StringValueObject
{
$value = parent::convertToPHPValue($value, $platform);
/** @var StringType $typeInherit */
$typeInherit = $this->getType(Types::STRING);
$value = $typeInherit->convertToPHPValue($value, $platform);

if ($value === null) {
return null;
}
Expand Down
5 changes: 4 additions & 1 deletion tests/EntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ private function manager(): EntityManager

// create entity manager with an sqlite in memory storage
$config = ORMSetup::createAttributeMetadataConfiguration([__DIR__], true);
$connection = DriverManager::getConnection(['url' => 'sqlite:///:memory:']);
$connection = DriverManager::getConnection([
'driver' => 'pdo_sqlite',
'url' => 'sqlite:///:memory:'
]);
$entityManager = new EntityManager($connection, $config);
// create schema
(new SchemaTool($entityManager))
Expand Down

0 comments on commit eec14b3

Please sign in to comment.