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

DIC parameter is interpreted as *never* #286

Open
shyim opened this issue Jul 1, 2022 · 9 comments
Open

DIC parameter is interpreted as *never* #286

shyim opened this issue Jul 1, 2022 · 9 comments

Comments

@shyim
Copy link
Contributor

shyim commented Jul 1, 2022

Since commit 2063d60 I have a error that a dic parameter is never.

I am doing in the test code:

static::assertNotSame($this->container->getParameter('shopware.filesystem.public'), $this->container->getParameter('shopware.filesystem.theme'));

That both parameter keys which are arrays are the same. Since that commit I get

Parameter #1 $expected of static method PHPUnit\Framework\Assert::assertSame() contains unresolvable type.

I took the parameter out and "over-typed" it with an var annotation

/** @var array{type: string, config: array{root: string}} $filesystemPublic */
        $filesystemPublic = $this->builder->getParameter('shopware.filesystem.public');
        static::assertNotSame($filesystemPublic, $this->builder->getParameter('shopware.filesystem.theme'));

This produces that next strange error

 72     Call to static method PHPUnit\Framework\Assert::assertSame() with *NEVER* and array{type: string, config: array{root: string}} will always evaluate to false.  
  72     Parameter #1 $expected of static method PHPUnit\Framework\Assert::assertSame() contains unresolvable type.
@shyim shyim changed the title DIC parameter is interpreted as **never** DIC parameter is interpreted as *never* Jul 1, 2022
@ondrejmirtes
Copy link
Member

/cc @VincentLanglet

@VincentLanglet
Copy link
Contributor

What is your config ? @shyim

I'll need more explanation about the shopware.filesystem.public.

Best would be to reproduce this error with the tests of this repository

@VincentLanglet
Copy link
Contributor

Here you are :)

https://github.com/shopware/platform/blob/dea144715a735c2b6f53098b9c92f9eeebc16c21/src/Core/Framework/Test/DependencyInjection/CompilerPass/FilesystemConfigMigrationCompilerPassTest.php#L60

I ran

git clone ...
composer install
php src/Core/DevOps/StaticAnalyze/PHPStan/phpstan-bootstrap.php
vendor/bin/phpstan analyse src/Core/Framework/Test/DependencyInjection/CompilerPass/FilesystemConfigMigrationCompilerPassTest.php

And got no error

@ondrejmirtes
Copy link
Member

@shyim clearly misunderstood what @VincentLanglet meant with "Best would be to reproduce this error with the tests of this repository".

@VincentLanglet
Copy link
Contributor

@shyim clearly misunderstood what @VincentLanglet meant with "Best would be to reproduce this error with the tests of this repository".

Yes, but if I could have been able to reproduce the error with his repository, I would have write the fix/test by myself.

I'm fine with both solution.
Either, I have an easy way to reproduce the error on his repository
Either, you (@shyim) write a failing test phpstan/phpstan-symfony repository to reproduce the error you have, and I'll debug to fix it.

@ondrejmirtes
Copy link
Member

I think all you need to be able to fix this is to see how shopware.filesystem.public looks like in .yml or .xml container dump.

@VincentLanglet
Copy link
Contributor

I reproduced the error with his repository.

I have

<parameter key="shopware.filesystem.public" type="collection">
      <parameter key="type">local</parameter>
      <parameter key="config" type="collection">
        <parameter key="root">/Users/vincentl/Perso/platform/public</parameter>
      </parameter>
    </parameter>
    <parameter key="shopware.filesystem.theme" type="collection">
      <parameter key="type">local</parameter>
      <parameter key="config" type="collection">
        <parameter key="root">/Users/vincentl/Perso/platform/public</parameter>
      </parameter>
    </parameter>

And with the code

        $this->builder->setParameter('shopware.filesystem.theme', ['foo' => 'foo']);
        $this->builder->setParameter('shopware.filesystem.theme.type', 'amazon-s3');
        $this->builder->setParameter('shopware.filesystem.theme.config', ['test' => 'test']);
        $this->builder->setParameter('shopware.filesystem.theme.url', 'http://cdn.de');

        $this->builder->compile();

        \PHPStan\dumpType($this->builder->getParameter('shopware.filesystem.public'));
        \PHPStan\dumpType($this->builder->getParameter('shopware.filesystem.theme'));

        static::assertNotSame($this->builder->getParameter('shopware.filesystem.public'), $this->builder->getParameter('shopware.filesystem.theme'));

        \PHPStan\dumpType($this->builder->getParameter('shopware.filesystem.public'));
        \PHPStan\dumpType($this->builder->getParameter('shopware.filesystem.theme'));

I have

  58     Dumped type: array{type: string, config: array{root: string}}
  59     Dumped type: array{type: string, config: array{root: string}}
  63     Dumped type: array{type: string, config: array{root: string}}
  64     Dumped type: array{type: string, config: array{root: string}}
  68     Dumped type: *NEVER*
  69     Dumped type: *NEVER*

Phpstan is thinking that the parameter are the same because it doesn't change the value with setParameter.

but Phpstan shouldn't even use the container xml here, since the test is doing new ContainerBuilder.

@VincentLanglet
Copy link
Contributor

To simplify the issue

        $builder = new ContainerBuilder();
        \PHPStan\dumpType($builder->getParameter('shopware.filesystem.public'));

is reported by phpstan

Dumped type: array{type: string, config: array{root: string}}

To me this is wrong, but not related to my changes.

And it will require to consider differently Containerbuilder which are injected as a service, and ContainerBuilder which are freshly created. Doesn't seems like an easy issue to solve, but I may be wrong @ondrejmirtes.

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

No branches or pull requests

3 participants