Skip to content

Commit

Permalink
Merge pull request #1802 from jifer/typed-field-mapper-option
Browse files Browse the repository at this point in the history
  • Loading branch information
ostrolucky authored May 21, 2024
2 parents 4bb9f20 + 7bbff25 commit 794cb9e
Show file tree
Hide file tree
Showing 31 changed files with 155 additions and 53 deletions.
12 changes: 9 additions & 3 deletions .doctrine-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@
"slug": "doctrine-bundle",
"versions": [
{
"name": "2.12",
"branchName": "2.12.x",
"name": "2.13",
"branchName": "2.13.x",
"slug": "latest",
"upcoming": true
},
{
"name": "2.12",
"branchName": "2.12.x",
"slug": "2.12",
"current": true
},
{
"name": "2.11",
"branchName": "2.11.x",
"slug": "2.11",
"current": true
"maintained": false
},
{
"name": "2.10",
Expand Down
5 changes: 3 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
phpunit.xml.dist export-ignore
phpcs.xml.dist export-ignore
psalm.xml.dist export-ignore
/Resources/doc export-ignore
/Tests export-ignore
/docs export-ignore
/tests export-ignore
.symfony.bundle.yaml export-ignore
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
labels:
- "CI"
2 changes: 1 addition & 1 deletion .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ on:
jobs:
coding-standards:
name: "Coding Standards"
uses: "doctrine/.github/.github/workflows/coding-standards.yml@3.1.0"
uses: "doctrine/.github/.github/workflows/coding-standards.yml@5.0.1"
with:
composer-options: "--prefer-dist --prefer-stable"
2 changes: 1 addition & 1 deletion .github/workflows/composer-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ on:
jobs:
composer-lint:
name: "Composer Lint"
uses: "doctrine/.github/.github/workflows/composer-lint.yml@3.1.0"
uses: "doctrine/.github/.github/workflows/composer-lint.yml@5.0.1"
19 changes: 11 additions & 8 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
- "7.4"
- "8.0"
- "8.1"
- "8.2"
dependencies:
- "highest"
stability:
Expand All @@ -46,22 +47,22 @@ jobs:
# Test last supported minor version
- symfony-require: "6.*"
dependencies: "highest"
php-version: "8.2"
php-version: "8.3"

# DBAL only without ORM
- php-version: "8.2"
- php-version: "8.3"
dependencies: "highest"
stability: "stable"
remove-orm: true

# DBAL 4
- php-version: "8.2"
- php-version: "8.3"
dependencies: "highest"
stability: "dev"
remove-orm: true

# Bleeding edge
- php-version: "8.2"
- php-version: "8.3"
dependencies: "highest"
stability: "dev"

Expand Down Expand Up @@ -93,7 +94,7 @@ jobs:
if: "${{ matrix.remove-orm }}"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v3"
with:
dependency-versions: "${{ matrix.dependencies }}"
composer-options: "--prefer-dist"
Expand All @@ -102,7 +103,7 @@ jobs:
run: "vendor/bin/phpunit --coverage-clover=coverage.xml"

- name: "Upload coverage file"
uses: "actions/upload-artifact@v3"
uses: "actions/upload-artifact@v4"
with:
name: "phpunit-${{ matrix.php-version }}-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}.coverage"
path: "coverage.xml"
Expand All @@ -120,11 +121,13 @@ jobs:
fetch-depth: 2

- name: "Download coverage files"
uses: "actions/download-artifact@v3"
uses: "actions/download-artifact@v4"
with:
path: "reports"

- name: "Upload to Codecov"
uses: "codecov/codecov-action@v3"
uses: "codecov/codecov-action@v4"
with:
directory: reports
env:
CODECOV_TOKEN: "${{ secrets.CODECOV_TOKEN }}"
2 changes: 1 addition & 1 deletion .github/workflows/release-on-milestone-closed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
jobs:
release:
name: "Git tag, release & create merge-up PR"
uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@3.1.0"
uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@5.0.1"
secrets:
GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }}
GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
run: "composer config minimum-stability stable"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v3"

- name: "Run a static analysis with vimeo/psalm"
run: "vendor/bin/psalm --show-info=false --stats --output-format=github --find-unused-psalm-suppress"
2 changes: 1 addition & 1 deletion .github/workflows/test-dev-stability.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
if: "${{ startsWith(matrix.symfony-require, '4.') }}"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v3"
with:
dependency-versions: "${{ matrix.dependencies }}"
composer-options: "--prefer-dist"
Expand Down
9 changes: 5 additions & 4 deletions .symfony.bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ branches:
- "2.10.x"
- "2.11.x"
- "2.12.x"
- "2.13.x"
maintained_branches:
- "2.11.x"
- "2.12.x"
doc_dir: { "2.11.x": "Resources/doc/", "2.12.x": "docs/" }
current_branch: "2.11.x"
dev_branch: "2.12.x"
- "2.13.x"
doc_dir: "docs/"
current_branch: "2.12.x"
dev_branch: "2.13.x"
6 changes: 6 additions & 0 deletions config/orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
<parameter key="doctrine.orm.quote_strategy.default.class">Doctrine\ORM\Mapping\DefaultQuoteStrategy</parameter>
<parameter key="doctrine.orm.quote_strategy.ansi.class">Doctrine\ORM\Mapping\AnsiQuoteStrategy</parameter>

<!-- typed field mapper -->
<parameter key="doctrine.orm.typed_field_mapper.default.class">Doctrine\ORM\Mapping\DefaultTypedFieldMapper</parameter>

<!-- entity listener resolver -->
<parameter key="doctrine.orm.entity_listener_resolver.class">Doctrine\Bundle\DoctrineBundle\Mapping\ContainerEntityListenerResolver</parameter>

Expand Down Expand Up @@ -173,6 +176,9 @@
<service id="doctrine.orm.quote_strategy.default" class="%doctrine.orm.quote_strategy.default.class%" public="false" />
<service id="doctrine.orm.quote_strategy.ansi" class="%doctrine.orm.quote_strategy.ansi.class%" public="false" />

<!-- typed field mapper -->
<service id="doctrine.orm.typed_field_mapper.default" class="%doctrine.orm.typed_field_mapper.default.class%" public="false" />

<!-- custom id generators -->
<service id="doctrine.ulid_generator" class="Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator">
<argument type="service" id="ulid.factory" on-invalid="ignore" />
Expand Down
1 change: 1 addition & 0 deletions config/schema/doctrine-1.0.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
<xsd:attribute name="class-metadata-factory-name" type="xsd:string" />
<xsd:attribute name="naming-strategy" type="xsd:string" />
<xsd:attribute name="quote-strategy" type="xsd:string" />
<xsd:attribute name="typed-field-mapper" type="xsd:string" />
<xsd:attribute name="entity-listener-resolver" type="xsd:string" />
<xsd:attribute name="repository-factory" type="xsd:string" />
<xsd:attribute name="report-fields-where-declared" type="xsd:boolean" />
Expand Down
4 changes: 3 additions & 1 deletion docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ Configuration Reference
validate_xml_mapping: false
naming_strategy: doctrine.orm.naming_strategy.default
quote_strategy: doctrine.orm.quote_strategy.default
typed_field_mapper: doctrine.orm.typed_field_mapper.default
entity_listener_resolver: ~
repository_factory: ~
second_level_cache:
Expand Down Expand Up @@ -514,6 +515,7 @@ Configuration Reference
report-fields-where-declared="false"
naming-strategy="doctrine.orm.naming_strategy.default"
quote-strategy="doctrine.orm.quote_strategy.default"
typed-field-mapper="doctrine.orm.typed_field_mapper.default"
entity-listener-resolver="null"
repository-factory="null"
>
Expand Down Expand Up @@ -883,7 +885,7 @@ can configure. The following block shows all possible configuration keys:
logging: "%kernel.debug%"
platform_service: MyOwnDatabasePlatformService
auto_commit: false
schema_filter: ^sf2_
schema_filter: /^sf2_/
mapping_types:
enum: string
types:
Expand Down
9 changes: 5 additions & 4 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<config name="php_version" value="70400"/>

<file>src</file>
<file>tests</file>

<rule ref="Doctrine">
<exclude name="SlevomatCodingStandard.TypeHints.DeclareStrictTypes"/>
Expand All @@ -22,11 +23,11 @@
</rule>

<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
<exclude-pattern>Tests/*</exclude-pattern>
<exclude-pattern>Repository/RepositoryFactoryCompatibility.php</exclude-pattern>
<exclude-pattern>Repository/ServiceEntityRepository.php</exclude-pattern>
<exclude-pattern>tests/*</exclude-pattern>
<exclude-pattern>src/Repository/RepositoryFactoryCompatibility.php</exclude-pattern>
<exclude-pattern>src/Repository/ServiceEntityRepository.php</exclude-pattern>
</rule>
<rule ref="Squiz.Classes.ClassFileName.NoMatch">
<exclude-pattern>Tests/*</exclude-pattern>
<exclude-pattern>tests/*</exclude-pattern>
</rule>
</ruleset>
19 changes: 13 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit colors="true" bootstrap="tests/bootstrap.php">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
colors="true"
bootstrap="tests/bootstrap.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
>
<testsuites>
<testsuite name="DoctrineBundle for the Symfony Framework">
<directory>./tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="ignoreFile=./tests/baseline-ignore"/>
</php>

<coverage>
<include>
<directory>src</directory>
</whitelist>
</filter>
</include>
</coverage>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
Expand Down
3 changes: 2 additions & 1 deletion src/Command/CreateDatabaseDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
unset($params['dbname'], $params['path'], $params['url']);

if ($connection->getDatabasePlatform() instanceof PostgreSQLPlatform) {
$params['dbname'] = 'postgres';
/** @psalm-suppress InvalidArrayOffset It's still available in DBAL 3.x that we need to support */
$params['dbname'] = $params['default_dbname'] ?? 'postgres';
}

$tmpConnection = DriverManager::getConnection($params, $connection->getConfiguration());
Expand Down
3 changes: 2 additions & 1 deletion src/Command/DropDatabaseDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
unset($params['dbname'], $params['url']);

if ($connection->getDatabasePlatform() instanceof PostgreSQLPlatform) {
$params['dbname'] = 'postgres';
/** @psalm-suppress InvalidArrayOffset It's still available in DBAL 3.x that we need to support */
$params['dbname'] = $params['default_dbname'] ?? 'postgres';
}

if (! $input->getOption('force')) {
Expand Down
5 changes: 4 additions & 1 deletion src/ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ public function createConnection(array $params, ?Configuration $config = null, ?
$driver = $connection->getDriver();
/** @psalm-suppress InvalidScalarArgument Bogus error, StaticServerVersionProvider implements Doctrine\DBAL\ServerVersionProvider */
$platform = $driver->getDatabasePlatform(
...(class_exists(StaticServerVersionProvider::class) ? [new StaticServerVersionProvider($params['serverVersion'] ?? '')] : []),
...(class_exists(StaticServerVersionProvider::class)
? [new StaticServerVersionProvider($params['serverVersion'] ?? $params['primary']['serverVersion'] ?? '')]
: []
),
);

if (! isset($params['charset'])) {
Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ private function getOrmEntityManagersNode(): ArrayNodeDefinition
->scalarNode('auto_mapping')->defaultFalse()->end()
->scalarNode('naming_strategy')->defaultValue('doctrine.orm.naming_strategy.default')->end()
->scalarNode('quote_strategy')->defaultValue('doctrine.orm.quote_strategy.default')->end()
->scalarNode('typed_field_mapper')->defaultValue('doctrine.orm.typed_field_mapper.default')->end()
->scalarNode('entity_listener_resolver')->defaultNull()->end()
->scalarNode('repository_factory')->defaultValue('doctrine.orm.container_repository_factory')->end()
->arrayNode('schema_ignore_classes')
Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ protected function loadOrmEntityManager(array $entityManager, ContainerBuilder $
'setDefaultRepositoryClassName' => $entityManager['default_repository_class'],
'setNamingStrategy' => new Reference($entityManager['naming_strategy']),
'setQuoteStrategy' => new Reference($entityManager['quote_strategy']),
'setTypedFieldMapper' => new Reference($entityManager['typed_field_mapper']),
'setEntityListenerResolver' => new Reference(sprintf('doctrine.orm.%s_entity_listener_resolver', $entityManager['name'])),
'setLazyGhostObjectEnabled' => '%doctrine.orm.enable_lazy_ghost_objects%',
];
Expand Down
4 changes: 2 additions & 2 deletions tests/ConnectionFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testDefaultCharsetNonMySql(): void
public function testDefaultCharsetMySql(): void
{
$factory = new ConnectionFactory([]);
$params = ['driver' => 'pdo_mysql'];
$params = ['driver' => 'pdo_mysql', 'serverVersion' => '8.0.31'];

$connection = $factory->createConnection($params, $this->configuration);

Expand All @@ -53,7 +53,7 @@ public function testDefaultCharsetMySql(): void
public function testDefaultCollationMySql(): void
{
$factory = new ConnectionFactory([]);
$connection = $factory->createConnection(['driver' => 'pdo_mysql'], $this->configuration);
$connection = $factory->createConnection(['driver' => 'pdo_mysql', 'serverVersion' => '8.0.31'], $this->configuration);

$this->assertSame(
'utf8mb4_unicode_ci',
Expand Down
15 changes: 14 additions & 1 deletion tests/DependencyInjection/AbstractDoctrineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public function testDbalLoadSinglePrimaryReplicaConnection(): void

public function testDbalLoadSavepointsForNestedTransactions(): void
{
if (!method_exists(Connection::class, 'getEventManager')) {
if (! method_exists(Connection::class, 'getEventManager')) {
self::markTestSkipped('This test requires DBAL < 4');
}

Expand Down Expand Up @@ -729,6 +729,19 @@ public function testSetQuoteStrategy(): void
$this->assertDICDefinitionMethodCallOnce($def2, 'setQuoteStrategy', [0 => new Reference('doctrine.orm.quote_strategy.ansi')]);
}

public function testSetTypedFieldMapper(): void
{
if (! interface_exists(EntityManagerInterface::class)) {
self::markTestSkipped('This test requires ORM');
}

$container = $this->loadContainer('orm_typedfieldmapper');

$definition = $container->getDefinition('doctrine.orm.default_configuration');

$this->assertDICDefinitionMethodCallOnce($definition, 'setTypedFieldMapper', [0 => new Reference('doctrine.orm.typed_field_mapper.default')]);
}

/**
* @dataProvider cacheConfigProvider
* @group legacy
Expand Down
Loading

0 comments on commit 794cb9e

Please sign in to comment.