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

FQCN as a key for argumentsSet does not work as expected #195

Open
mialex opened this issue Dec 7, 2021 · 2 comments
Open

FQCN as a key for argumentsSet does not work as expected #195

mialex opened this issue Dec 7, 2021 · 2 comments
Labels

Comments

@mialex
Copy link

mialex commented Dec 7, 2021

Hi.

I faced an issue when I need to use the FQCN of my classes as a key for argumentsSet. When it is defined with FQCN in the way \Worker\Fixtures\UserFixture::class it does not work as expected, as in this case it takes all possible arguments, regardless of the key. Once it's set up as a string '\Worker\Fixtures\UserFixture' it works ex expected. It would be great if it's possible to use class constant instead fo the string. Here are examples of the source code

.phpstorm.meta.php

<?php

namespace PHPSTORM_META {

    use Worker\Fixtures;

    function fixture_data_set(array $attributes = []) {
        return [
            'attributes' => $attributes,
        ];
    }

    function fixture_set() {
        return [
            Fixtures\UserFixture::class => \PHPSTORM_META\fixture_data_set([
                'firstName' => '',
                'lastName' => '',
            ]),
            Fixtures\DeviceFixture::class => \PHPSTORM_META\fixture_data_set([
                'deviceStatusId' => '',
                'externalId' => '',
            ]),
        ];
    }

    registerArgumentsSet('fixturesSet', ...\PHPSTORM_META\fixture_set());

    expectedArguments(\Worker\Provider::add(), 0, argumentsSet('fixturesSet'));
}

worker.php

<?php

namespace Worker\Fixtures {
    class UserFixture {
        // accept some data
    }

    class DeviceFixture {
        // accept some data
    }
}

namespace Worker {
    class Provider
    {
        public function add(array $data) {
            return $this;
        }
    }
}

namespace {
    use Worker\Fixtures;

    $provider = new \Worker\Provider();
    $provider
        ->add([
            Fixtures\UserFixture::class => [
                'attributes' => [
                    '', // get 4 unexpected fields (`firstName`, `lastName`, `deviceStatusId`, `externalId`)
                ]
            ]
        ])
    ;
}

In my example, if you try to add a new attribute, you will get the list of all 4 available attributes in the suggestion list (firstName, lastName, deviceStatusId, externalId) and it's not expected, as I need to see only 2 (firstName, lastName) by the key, which is Worker\Fixtures\UserFixture::class. If I change it to be simple string, it works as expected and I get the list of 2 expected elements (firstName, lastName). See the shortened samples of code with the string keys below:

<?php

namespace PHPSTORM_META {

    // same as above

    function fixture_set() {
        return [
            'Fixtures\UserFixture' => \PHPSTORM_META\fixture_data_set([
                'firstName' => '',
                'lastName' => '',
            ]),
            'Fixtures\DeviceFixture' => \PHPSTORM_META\fixture_data_set([
                'deviceStatusId' => '',
                'externalId' => '',
            ]),
        ];
    }

    // same as above
}

worker.php

// same as above

namespace {

    $provider = new \Worker\Provider();
    $provider
        ->add([
            'Fixtures\UserFixture'' => [
                'attributes' => [
                    '', // get 2 expected fields (`firstName`, `lastName`)
                ]
            ]
        ])
    ;
}
@klesun klesun added the status: help wanted Backlog label Dec 7, 2021
@mialex
Copy link
Author

mialex commented Mar 15, 2022

Are there any updates?

@klesun
Copy link
Owner

klesun commented Mar 15, 2022

Hi. Sadly no, need a PR.

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