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

PHPStan producing different results on CI #2269

Closed
angelsk opened this issue Jul 4, 2019 · 13 comments
Closed

PHPStan producing different results on CI #2269

angelsk opened this issue Jul 4, 2019 · 13 comments

Comments

@angelsk
Copy link

angelsk commented Jul 4, 2019

Support question

I have two projects set up using PHPStan. They are both using a Docker container as an image to run stan and unit tests etc again, both locally and on a CI service (GoCD). I have Stan set to max level, the config set up and the phpunit extension installed (and the extensions installer)

I'm running Stan against my tests locally using the Docker image and there are no problems on both projects - which each have a similar test and set up.

On GoCD - one project is failing, one is passing. Locally, both are passing. They are all using the same Docker container, cache cleared and freshly built.

The errors on GoCD are:

  Line   tests/DoctrineExtensions/DBAL/Types/EnumTransactionSourceTypeTest.php    
 ------ ------------------------------------------------------------------------- 
  35     Call to an undefined method                                              
         App\DoctrineExtensions\DBAL\Types\EnumTransactionSourceType|PHPUnit\Fra  
         mework\MockObject\MockObject::getSQLDeclaration().                       
  43     Call to an undefined method                                              
         App\DoctrineExtensions\DBAL\Types\EnumTransactionSourceType|PHPUnit\Fra  
         mework\MockObject\MockObject::getSQLDeclaration().                       
  49     Call to an undefined method                                              
         App\DoctrineExtensions\DBAL\Types\EnumTransactionSourceType|PHPUnit\Fra  
         mework\MockObject\MockObject::getName().                                 
  57     Call to an undefined method                                              
         App\DoctrineExtensions\DBAL\Types\EnumTransactionSourceType|PHPUnit\Fra  
         mework\MockObject\MockObject::convertToDatabaseValue().                  
  77     Call to an undefined method                                              
         App\DoctrineExtensions\DBAL\Types\EnumTransactionSourceType|PHPUnit\Fra  
         mework\MockObject\MockObject::convertToDatabaseValue().                  
 ------ ------------------------------------------------------------------------- 

 [ERROR] Found 5 errors  

Namespaces are included properly. PHPUnit extension included. I've compared against the other project. And as I said it's running fine locally. Also - those methods do exist (and the test runs fine.

Can you think of anything that would cause two different sets of results so I can try and reproduce this locally - as it's really annoying having to commit every potential fix and have it fail again.

An easy fix would be to remove the docblock @var declarations for the test. But as the same test is passing on the other project; I feel like it's something different causing it to fail.

@ondrejmirtes
Copy link
Member

Hi, this looks like the extension isn't properly loaded. I guess that you have MockObject|EnumTransactionSourceType in your phpDoc which should be turned into an intersection type (instead of union type) by the phpstan-phpunit extension.

Please verify that you're running the same versions of PHPStan and extensions locally and in the CI, or for example try to clean PHPStan cache. There's definitely something different about the CI environment.

@angelsk
Copy link
Author

angelsk commented Jul 4, 2019

Hi @ondrejmirtes - the CI runs a clean install with a Docker image each time; I've replicated the same set up both locally and in the other project. Composer update has been run.

How could it not install the extension properly?
Where is the stan cache?
How could it be different if it's running in Docker?

And yes, I'm using

    /**
     * @var EnumTransactionSourceType|MockObject
     */
    private $enumTransactionSourceType;

@ondrejmirtes
Copy link
Member

I have no idea. Do you install PHPStan with extensions in project's composer.json or globally in the project?

Can I help you specifically with this codebase? Can we arrange remote desktop session or something like that?

@angelsk
Copy link
Author

angelsk commented Jul 4, 2019

@ondrejmirtes Unfortunately not, it's with a company I'm contracting with, so proprietary code.
And it's specifically hard because it's just on the GoCD instance and not locally. So it feels like a caching something....

The project's composer json contains in dev

    "phpstan/extension-installer": "^1.0",
    "phpstan/phpstan": "^0.11.8",
    "phpstan/phpstan-doctrine": "^0.11.5",
    "phpstan/phpstan-phpunit": "^0.11.2",
    "phpstan/phpstan-symfony": "^0.11.6",

Where is the phpstan cache? Maybe if I clear that locally I can reproduce....
But I had thought the whole point of using Docker was that it was the same env! Doh :)

It's also not the first time I've had different results on GoCD and locally with the same Docker instance.

@ondrejmirtes
Copy link
Member

First thing I'd try is to remove "phpstan/extension-installer": "^1.0", and install the extensions the old way, by including them in phpstan.neon. It might be some kind of Composer issue - composer install gets executed without Composer plugins or something like that.

@angelsk
Copy link
Author

angelsk commented Jul 4, 2019

@ondrejmirtes Will try that.
It's odd, because the symfony and doctrine ones are being included fine ;)

@angelsk
Copy link
Author

angelsk commented Jul 4, 2019

Ok - now the other project is failing.... only on the CI server. Huh? :( (I'd done a composer update to get the latest stan, but it failed before that on a minor push that had nothing to do with stan).

However; removing the extension installer and adding the rules manually to the config on the first failing project - that's fixed it.

So something weird is going on with the extension installer.....

Is it run in a composer script? How do I force it to run?

@ondrejmirtes
Copy link
Member

Yes, I guess it depends on how many times and when you call composer... Possibly related: phpstan/extension-installer#5

@angelsk
Copy link
Author

angelsk commented Jul 4, 2019

Ah. Now that makes sense. It's annoying - but it makes some sense.

Any way to force it to run?

@ondrejmirtes
Copy link
Member

Add composer install to the right place in your build process / Docker build. Hard to tell what's exactly going wrong...

@ondrejmirtes
Copy link
Member

Closing since it's solved. The extension-installer has narrow usefulness, once you step outside the "happy path", you probably can't use it...

@angelsk
Copy link
Author

angelsk commented Jul 4, 2019

@ondrejmirtes Really seriously appreciate the help though!! thanks 👍

@lock lock bot locked as resolved and limited conversation to collaborators Dec 23, 2019
@ondrejmirtes
Copy link
Member

phpstan/extension-installer now uses relative paths as of 1.1.0 + phpstan/phpstan 0.12.62. So you can give it a shot again :) See: phpstan/extension-installer#17 (comment)

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

No branches or pull requests

2 participants