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

Disable PHP Attribute mutations globally via config. #1894

Closed
nuryagdym opened this issue Nov 6, 2023 · 2 comments
Closed

Disable PHP Attribute mutations globally via config. #1894

nuryagdym opened this issue Nov 6, 2023 · 2 comments
Labels

Comments

@nuryagdym
Copy link

Hi,

I am working with Doctrine Entities and Mongo DB documents.

Doctrine allows us to configure ORM mapping with PHP attributes.
Example:

class UserDevice
{
    public function __construct(
        #[MongoDB\Id]
        private ?string $id,

        #[MongoDB\Field(type: Types::DATE_MUTABLE, nullable: true)]
        private ?UTCDateTime $updatedAt = null,
    ) {
    }

In this case infection test is changing nullable: true to nullable: false.

There is no direct way of handling this mutant, especially with unit tests.

Can we add a config, using which we can disable mutation of PHP attributes at all?

@maks-rafalko
Copy link
Member

maks-rafalko commented Nov 6, 2023

Hello,

while disabling mutating Attributes is not supported out of the box, you can achieve it by global-ignoreSourceCodeByRegex setting in infection.json5 config:

{
    "mutators": {
        "@default": true,
        "global-ignoreSourceCodeByRegex": [
            // to not mutate `nullable: false` to `nullable: true` or `unique: true` as unit tests don't cover it
            ".*\\#\\[MongoDB\\\\Field.*",
            ".*\\#\\[ORM\\\\JoinColumn.*",
            ".*\\#\\[ORM\\\\Column.*"
        ]
    }
}

Does it help?

@nuryagdym
Copy link
Author

Thank you very much @maks-rafalko, it worked!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants