Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds metadata field type validation against Entity property type #10662

Closed
wants to merge 4 commits into from

Conversation

DavideBicego
Copy link
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
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.

lib/Doctrine/ORM/Mapping/DefaultTypedFieldMapper.php Outdated Show resolved Hide resolved
lib/Doctrine/ORM/Mapping/DefaultTypedFieldMapper.php Outdated Show resolved Hide resolved
lib/Doctrine/ORM/Mapping/DefaultTypedFieldMapper.php Outdated Show resolved Hide resolved
tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php Outdated Show resolved Hide resolved
lib/Doctrine/ORM/Tools/SchemaValidator.php Outdated Show resolved Hide resolved
lib/Doctrine/ORM/Tools/SchemaValidator.php Outdated Show resolved Hide resolved
lib/Doctrine/ORM/Tools/SchemaValidator.php Outdated Show resolved Hide resolved
lib/Doctrine/ORM/Mapping/DefaultTypedFieldMapper.php Outdated Show resolved Hide resolved
lib/Doctrine/ORM/Mapping/DefaultTypedFieldMapper.php Outdated Show resolved Hide resolved
/**
* @Column(type="boolean")
*/
protected int $property;
Copy link
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
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
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

Copy link
Member

@greg0ire greg0ire May 6, 2023

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
Copy link
Member

greg0ire commented Apr 27, 2023

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
Copy link
Contributor Author

DavideBicego commented May 11, 2023

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

@Ocramius
Copy link
Member

CI is also stuck due to https://www.githubstatus.com/

SmallIntType::class => 'int',
StringType::class => 'string',
TextType::class => 'string',
];
Copy link
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
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
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
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
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
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