Skip to content

Adds metadata field type validation against Entity property type#10662

Closed
DavideBicego wants to merge 4 commits into
doctrine:2.17.xfrom
KanbanBOX:2.14.x
Closed

Adds metadata field type validation against Entity property type#10662
DavideBicego wants to merge 4 commits into
doctrine:2.17.xfrom
KanbanBOX:2.14.x

Conversation

@DavideBicego

Copy link
Copy Markdown
Contributor

This adds some properties type validation to SchemaValidator.

I think some strictness when setting the Entity value during Hydration would be better but ReflectionProperty::setValue skips strictness validation.

Resolve #10661

@Ocramius

Copy link
Copy Markdown
Member

Note: potentially worth going to 2.15.x, but unsure what the maintainers are planning for the 2.x branch, especially in the direction of adding features.

Comment thread lib/Doctrine/ORM/Mapping/DefaultTypedFieldMapper.php Outdated
Comment thread lib/Doctrine/ORM/Mapping/DefaultTypedFieldMapper.php Outdated
Comment thread lib/Doctrine/ORM/Mapping/DefaultTypedFieldMapper.php Outdated
Comment thread tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php Outdated
Comment thread lib/Doctrine/ORM/Tools/SchemaValidator.php Outdated
Comment thread lib/Doctrine/ORM/Tools/SchemaValidator.php Outdated
Comment thread lib/Doctrine/ORM/Tools/SchemaValidator.php Outdated
Comment thread lib/Doctrine/ORM/Mapping/DefaultTypedFieldMapper.php Outdated
Comment thread lib/Doctrine/ORM/Mapping/DefaultTypedFieldMapper.php Outdated
/**
* @Column(type="boolean")
*/
protected int $property;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooooops, the test fails here because Doctrine didn't yet drop PHP 7.3 support (REALLY?!)

I think the best way to handle this would be to:

  1. split this out to a separate file
  2. mark the tests with @requires php>=7.4
  3. exclude the separated file from analysis by tooling like phpcs/phpstan

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you prevent the file from being read with php < 7.4?
The test should not be executed with a @requires php 70400 but the file contains some classes definition too...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember how the test suite works precisely, but can check it tomorrow.

I'd say something like require_once __DIR__ . '/some-php-7.4-only-file.php and then reference the classes in that file that way

@greg0ire greg0ire May 6, 2023

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or use autoload, or team up with @MatTheCat who is having the same issue on https://github.com/doctrine/orm/pull/10666/files#r1186698321

We could have a subdirectories with tests that require a specific version of PHP, and then future contributors would not need to bother with @requires or with splitting test files and companion classes.

@greg0ire

greg0ire commented Apr 27, 2023

Copy link
Copy Markdown
Member

Note: potentially worth going to 2.15.x, but unsure what the maintainers are planning for the 2.x branch, especially in the direction of adding features.

Features welcome, and indeed, this should target 2.15.x (2.15.0 should be released quite soon BTW)

@DavideBicego
DavideBicego changed the base branch from 2.14.x to 2.15.x April 28, 2023 09:07
@derrabus
derrabus changed the base branch from 2.15.x to 2.16.x May 7, 2023 18:53
@DavideBicego

DavideBicego commented May 11, 2023

Copy link
Copy Markdown
Contributor Author

For some reason the CI step "PHPUnit with SQLite (7.1)" ignores the PHP version requirement...

@Ocramius

Copy link
Copy Markdown
Member

SmallIntType::class => 'int',
StringType::class => 'string',
TextType::class => 'string',
];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I don't like about this PR is this harcoded map, but for now there is nothing better I'm afraid. Once doctrine/dbal 4 is published and supported, we can start using reflection to get the return type.

@greg0ire greg0ire closed this Sep 15, 2023
@greg0ire greg0ire reopened this Sep 15, 2023
@greg0ire

Copy link
Copy Markdown
Member

Triggered the CI again

@greg0ire
greg0ire changed the base branch from 2.16.x to 2.17.x September 15, 2023 08:41
use Doctrine\ORM\Tools\SchemaValidator;
use Doctrine\Tests\OrmTestCase;

/** @requires PHP >= 7.4 */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other occurrences of this in the project are multiline. Maybe old versions of PHPUnit ignore single line stuff. The next suspect will be >=

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I can't push… push from maintainers is disabled. I'll open another PR I guess.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like that was the reason: #10946 :)

@greg0ire

Copy link
Copy Markdown
Member

Closing in favor of #10946

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Metadata field type validation against Entity property type

3 participants