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

Added test-case for deprecated phpstorm stub with patch-version #1406

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,83 @@ public function testStubForConstantThatIsDeprecated(): void
self::assertSame('filter', $stubData->getExtensionName());
}

public function testStubForConstantThatIsDeprecatedInPatchRelease(): void
{
// use a faked stub to make this test independent of the actual PHP version
$exampleStub = <<<'EOT'
<?php

/**
* @deprecated 8.1.2
*/
\define('A_CUSTOM_CONSTANT', 513);
EOT;
$stubData = new StubData($exampleStub, null);

self::assertStringMatchesFormat(
"%Adefine('A_CUSTOM_CONSTANT',%w%d);",
$stubData->getStub(),
);

if (PHP_VERSION_ID >= 80100) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh I think we don't catch a bug because we never reach the ELSE case of this condition (because CI is running only 8.2/8.3)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good catch! Indeed!

Perhaps we can change the fixture to introduce deprecations with higher/fictional PHP versions? :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me first make sure phpstan can catch such bugs in the future. Brb

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

phpstan/phpstan-src#2968 should help us in the future.

self::assertStringContainsString(
'@deprecated 8.1.2',
$stubData->getStub(),
);
} else {
self::assertStringNotContainsString(
'@deprecated 8.1.2',
$stubData->getStub(),
);
}

self::assertNull($stubData->getExtensionName());
}

public function testStubForConstantThatIsDeprecatedWithUserMessage(): void
{
// use a faked stub to make this test independent of the actual PHP version
$exampleStub = <<<'EOT'
<?php

/**
* @deprecated you should not use it.
*/
\define('A_CUSTOM_CONSTANT', 513);
EOT;
$stubData = new StubData($exampleStub, null);

self::assertStringMatchesFormat(
"%Adefine('A_CUSTOM_CONSTANT',%w%d);",
$stubData->getStub(),
);

self::assertStringContainsString(
'@deprecated you should not use it.',
$stubData->getStub(),
);

self::assertNull($stubData->getExtensionName());
}

public function testStubForConstantWithoutPhpdoc(): void
{
// use a faked stub to make this test independent of the actual PHP version
$exampleStub = <<<'EOT'
<?php

\define('A_CUSTOM_CONSTANT', 513);
EOT;
$stubData = new StubData($exampleStub, null);

self::assertStringMatchesFormat(
"%Adefine('A_CUSTOM_CONSTANT',%w%d);",
$stubData->getStub(),
);

self::assertNull($stubData->getExtensionName());
}

public function testNoStubForConstantThatDoesNotExist(): void
{
self::assertNull($this->sourceStubber->generateConstantStub('SOME_CONSTANT'));
Expand Down
Loading