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

Test failures with PHPStan dev-master #50

Closed
ondrejmirtes opened this issue Nov 21, 2021 · 4 comments
Closed

Test failures with PHPStan dev-master #50

ondrejmirtes opened this issue Nov 21, 2021 · 4 comments

Comments

@ondrejmirtes
Copy link
Member

Hi @eiriksm, after your latest changes in phpstan-src, there are now failures in this repo:

1) PHPStan\Rules\Deprecations\CallToDeprecatedMethodRuleTest::testDeprecatedMethodCall
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
 '07: Call to deprecated method deprecatedFoo() of class CheckDeprecatedMethodCall\Foo.
+10: Call to deprecated method deprecatedFoo() of class CheckDeprecatedMethodCall\Bar.
 11: Call to deprecated method deprecatedFoo2() of class CheckDeprecatedMethodCall\Foo.
 14: Call to deprecated method deprecatedFooFromTrait() of class CheckDeprecatedMethodCall\Foo.
 15: Call to deprecated method deprecatedWithDescription() of class CheckDeprecatedMethodCall\Foo:
 Call a different method instead.
 '

phar:///home/runner/work/phpstan/phpstan/extension/vendor/phpstan/phpstan/phpstan.phar/src/Testing/RuleTestCase.php:84
/home/runner/work/phpstan/phpstan/extension/tests/Rules/Deprecations/CallToDeprecatedMethodRuleTest.php:23

2) PHPStan\Rules\Deprecations\CallToDeprecatedStaticMethodRuleTest::testDeprecatedStaticMethodCall
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
 '06: Call to deprecated method deprecatedFoo() of class CheckDeprecatedStaticMethodCall\Foo.
+08: Call to deprecated method deprecatedFoo() of class CheckDeprecatedStaticMethodCall\Bar.
 09: Call to deprecated method deprecatedFoo2() of class CheckDeprecatedStaticMethodCall\Foo.
 11: Call to method foo() of deprecated class CheckDeprecatedStaticMethodCall\Foo.
 12: Call to method deprecatedFoo() of deprecated class CheckDeprecatedStaticMethodCall\Foo.
@@ @@
 Do not touch this at all.
 16: Call to deprecated method deprecatedWithDescription() of class CheckDeprecatedStaticMethodCall\Foo:
 This is probably a singleton.
-24: Call to deprecated method deprecatedFoo() of class CheckDeprecatedStaticMethodCall\Foo.
 '

Can you please look into it so we know what needs fixing? If the tests asserts here are reasonable then phpstan-src needs fixing, or these asserts need to be edited.

@eiriksm
Copy link
Contributor

eiriksm commented Nov 21, 2021

OK so the reason is

class Bar extends Foo
{

	public function deprecatedFoo()
	{

	}

}


// Shortened for relevance.
class Foo
{

	/**
	 * @deprecated
	 */
	public function deprecatedFoo()
	{

	}

}

Now Bar::deprecatedFoo is marked as deprecated. My editor thinks it's not deprecated. Only when I add

	/**
	 * {@inheritdoc}
	 */

to the method, phpstorm thinks so. Personally I think we should have the current behaviour (that's failing the tests), so just adjust the assertions. What do you think?

The same is the case for the other test failure regarding static methods. Except the missing error, which is now not marked as deprecated because of the first line where

		if (DeprecatedScopeHelper::isScopeDeprecated($scope)) {
			return [];
		}

Scope is apparently deprecated when it's a static function? Not sure about this one.

Will open a PR which fixes the tests at least (with adjusting them).

@franmomu
Copy link

franmomu commented Dec 30, 2021

Hi, I'm having this problem with PHPStan 1.3.0 with this kind of code:

class LifecycleEventArgs
{
    private object $object;

    public function __construct(object $object)
    {
        $this->object = $object;
    }

    /**
     * @deprecated
     */
    public function getEntity(): object
    {
        return $this->object;
    }

    public function getObject(): object
    {
        return $this->object;
    }
}

class ORMLifecycleEventArgs extends BaseLifecycleEventArgs
{
    public function getEntity(): object
    {
        return $this->getObject();
    }
}

I'm getting:

Call to deprecated method getEntity() of class Doctrine\ORM\Event\LifecycleEventArgs.

@ondrejmirtes
Copy link
Member Author

@franmomu This is an expected change after phpstan/phpstan-src#792. Feel free to ignore it: https://phpstan.org/user-guide/ignoring-errors

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants