Skip to content

Conversation

@mhujer
Copy link
Contributor

@mhujer mhujer commented Dec 11, 2017

I wanted to have a look on how to write PHPStan rules tests and I found none in this repository. So I created one.

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

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

Awesome, thanks! I found a few minor issues 😊

$this->assertSame('1', 1);
$this->assertSame('1', new \stdClass());
$this->assertSame(1, $this->returnsString());
$this->assertSame('1', self::returnsInt());
Copy link
Member

Choose a reason for hiding this comment

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

There should also be a few examples of positive cases - comparing int/int and probably also comparing some unions against simple type and unions against unions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added bellow

@@ -0,0 +1,39 @@
<?php

declare(strict_types = 1);
Copy link
Member

Choose a reason for hiding this comment

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

Please put declare on the same line as <?php :)


declare(strict_types = 1);

namespace PHPUnit;
Copy link
Member

Choose a reason for hiding this comment

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

Please use a different namespace, something like namespace ExampleTestCase is fine 😊

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, but PHPUnit is a well known and used namespace :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok :-)

$this->assertSame(1, self::returnsInt());

// this breaks PHPStan
$this->assertSame(['a'], ['a', 1]);
Copy link
Contributor Author

@mhujer mhujer Dec 11, 2017

Choose a reason for hiding this comment

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

@ondrejmirtes this line breaks PHPStan

PHPStan\ShouldNotHappenException : Internal error.
 C:\devweb\htdocs\phpstan-phpunit\vendor\phpstan\phpstan\src\Type\TypeCombinator.php:23
 C:\devweb\htdocs\phpstan-phpunit\vendor\phpstan\phpstan\src\Type\ArrayType.php:28
 C:\devweb\htdocs\phpstan-phpunit\vendor\phpstan\phpstan\src\Analyser\Scope.php:575
 C:\devweb\htdocs\phpstan-phpunit\vendor\phpstan\phpstan\src\Analyser\Scope.php:323
 C:\devweb\htdocs\phpstan-phpunit\src\Rules\PHPUnit\AssertSameDifferentTypesRule.php:62
 C:\devweb\htdocs\phpstan-phpunit\vendor\phpstan\phpstan\src\Analyser\Analyser.php:162
 C:\devweb\htdocs\phpstan-phpunit\vendor\phpstan\phpstan\src\Analyser\NodeScopeResolver.php:316
 C:\devweb\htdocs\phpstan-phpunit\vendor\phpstan\phpstan\src\Analyser\NodeScopeResolver.php:176
 C:\devweb\htdocs\phpstan-phpunit\vendor\phpstan\phpstan\src\Analyser\NodeScopeResolver.php:686
 C:\devweb\htdocs\phpstan-phpunit\vendor\phpstan\phpstan\src\Analyser\NodeScopeResolver.php:176
 C:\devweb\htdocs\phpstan-phpunit\vendor\phpstan\phpstan\src\Analyser\NodeScopeResolver.php:686
 C:\devweb\htdocs\phpstan-phpunit\vendor\phpstan\phpstan\src\Analyser\NodeScopeResolver.php:176
 C:\devweb\htdocs\phpstan-phpunit\vendor\phpstan\phpstan\src\Analyser\NodeScopeResolver.php:686
 C:\devweb\htdocs\phpstan-phpunit\vendor\phpstan\phpstan\src\Analyser\NodeScopeResolver.php:176
 C:\devweb\htdocs\phpstan-phpunit\vendor\phpstan\phpstan\src\Analyser\Analyser.php:166
 C:\devweb\htdocs\phpstan-phpunit\vendor\phpstan\phpstan\src\Testing\RuleTestCase.php:64
 C:\devweb\htdocs\phpstan-phpunit\tests\Rules\PHPUnit\AssertSameDifferentTypesRuleTest.php:19

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed by enabling union types in tests bootstrap

@mhujer
Copy link
Contributor Author

mhujer commented Dec 12, 2017

R4R @ondrejmirtes

@ondrejmirtes
Copy link
Member

Awesome! :)

@ondrejmirtes ondrejmirtes merged commit 6501e8e into phpstan:master Dec 14, 2017
@mhujer mhujer deleted the mh-add-test branch December 14, 2017 14:11
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

Successfully merging this pull request may close these issues.

2 participants