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

PHPUnit Declaration must be compatible #1012

Closed
shyim opened this issue Feb 4, 2019 · 9 comments
Closed

PHPUnit Declaration must be compatible #1012

shyim opened this issue Feb 4, 2019 · 9 comments

Comments

@shyim
Copy link
Contributor

shyim commented Feb 4, 2019

I am upgrading a test suite from PHPUnit 6 to 8. A run rector over it.
My expectation was that he fixes all return types issue. But it hangs with a Fatal Error

Fatal error: Declaration of Enlight_Components_Test_TestCase::tearDown() must be compatible with PHPUnit\Framework\TestCase::tearDown(): void

@TomasVotruba
Copy link
Member

How does Enlight_Components_Test_TestCase::tearDown() look like?

@shyim
Copy link
Contributor Author

shyim commented Feb 4, 2019

protected function tearDown()
    {
        if ($this->databaseTester !== null) {
            if (method_exists($this, 'getTearDownOperation')) {
                $this->getDatabaseTester()->setTearDownOperation($this->getTearDownOperation());
            }
            if (method_exists($this, 'getDataSet')) {
                $this->getDatabaseTester()->setDataSet($this->getDataSet());
            }
            $this->getDatabaseTester()->onTearDown();
        }

        $this->databaseTester = null;

        set_time_limit(0);
        ini_restore('memory_limit');
    }

It don't have the return type void. I guess that the tool would add it :)

@TomasVotruba
Copy link
Member

TomasVotruba commented Feb 4, 2019

Looks good, it should work.

  • Does it externd the test case?
  • Is it located in your code and not vendor?
  • What exact Rector command do you run? vendor/bin/rector ...

@shyim
Copy link
Contributor Author

shyim commented Feb 4, 2019

Yea its multiple times extended from another test cases.
Code is in tests folder and not vendor

docker run --rm -it  -v (pwd):/project rector/rector:latest bin/rector process --level phpunit80 --config /project/rector.yaml  /project/tests
# rector.yaml
parameters:
  level: phpunit80
  autoload_paths:
    - '/project/autoload.php'
    - '/project/engine/Library/Enlight/Components/Test/TestCase.php'
    - '/project/engine'
    - '/project/tests'
  exclude_rectors:
    - 'Rector\PHPUnit\Rector\MethodCall\SpecificAssertContainsRector'

Abstract TestCase class on Github https://github.com/shopware/shopware/blob/5.5/engine/Library/Enlight/Components/Test/TestCase.php#L69
Example class using it
https://github.com/shopware/shopware/blob/4fb20a661576322704ea0d20332bdbe3c49e2ab6/tests/Functional/Components/StreamProtocolValidatorTest.php#L30

@TomasVotruba
Copy link
Member

I see. I think Enlight_Components_Test_TestCase is not autoloaded.

Since it doesn't have a namespace, it might be missed. I'd try to add it explicitly to autoload_paths.

TomasVotruba added a commit that referenced this issue Feb 4, 2019
@TomasVotruba
Copy link
Member

Oh, I see it's /project/engine/Library/Enlight/Components/Test/TestCase.php', it has different name.

@TomasVotruba
Copy link
Member

TomasVotruba commented Feb 4, 2019

I've added test case here and it passes: https://github.com/rectorphp/rector/pull/1015/files#diff-0046f116fcc7847008b98b058947e8e7

Ano more idea - I use PHPUnit 7.5. If you upgrade to never PHPUnit 8, it will match to your old code to new one and failing in void missmatch.

I'd try Rector run first, then upgrade to PHPUnit 8, when the code is ready.

@shyim
Copy link
Contributor Author

shyim commented Feb 4, 2019

I was before on PHPUnit 6 and upgraded directly to 8 :)

@TomasVotruba
Copy link
Member

TomasVotruba commented Feb 4, 2019

That's the problem :)
Rector uses Reflection of current code and that must be valid.

@shyim shyim closed this as completed Feb 5, 2019
TomasVotruba added a commit that referenced this issue Oct 17, 2021
rectorphp/rector-src@8bb31f2 [automated] Re-Generate Nodes/Rectors Documentation (#1012)
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

2 participants