phpstan-phpunit icon indicating copy to clipboard operation
phpstan-phpunit copied to clipboard

assertInternalType()

Open josephzidell opened this issue 6 years ago • 6 comments

I'm using Codeception's wrapper of PHPUnit's assertInternalType, and thought phpstan would understand the type.

Example code:

$feedHandle = fopen('php://temp', 'rw+');
$this->assertInternalType('resource', $feedHandle);
fwrite($feedHandle, $feed);

Actual result:

Parameter #1 $fp of function fwrite expects resource, resource|false given.

Expected result: -- Nothing --

josephzidell avatar Dec 25 '18 15:12 josephzidell

What’s $this in that case?

On Tue, 25 Dec 2018 at 16:55, Joseph Zidell [email protected] wrote:

I'm using Codeception's wrapper https://github.com/Codeception/Codeception/blob/2.5/src/Codeception/Util/Shared/Asserts.php#L448-L451 of PHPUnit's assertInternalType https://github.com/sebastianbergmann/phpunit/blob/master/src/Framework/Assert.php#L1677, and thought phpstan would understand the type.

Example code:

$feedHandle = fopen('php://temp', 'rw+'); $this->assertInternalType('resource', $feedHandle); fwrite($feedHandle, $feed);

Actual result:

Parameter #1 $fp of function fwrite expects resource, resource|false given.

Expected result: -- Nothing --

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/phpstan/phpstan/issues/1734, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGZuPhkbMaRNLFmTLgg0FuLiX_B_z9rks5u8kpsgaJpZM4ZhI_u .

--

Ondřej Mirtes

ondrejmirtes avatar Dec 25 '18 15:12 ondrejmirtes

One of:

  • instance of \Codeception\Test\Unit that directly extends \PHPUnit\Framework\TestCase (unit tests)
  • instance of AcceptanceTester that uses a trait _generated\AcceptanceTesterActions which wraps the Codeception assert (acceptance tests)

josephzidell avatar Dec 25 '18 16:12 josephzidell

In the second case, there are a few layers of wrapper paper, all using the same method name and signature.

josephzidell avatar Dec 25 '18 16:12 josephzidell

In the first case, the installation of phpstan/phpstan-phpunit extension should be sufficient. Second case is not currently supported, but should be easy to add.

On Tue, 25 Dec 2018 at 17:05, Joseph Zidell [email protected] wrote:

In the second case, there are a few layers of wrapper paper, all using the same method name and signature.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/phpstan/phpstan/issues/1734#issuecomment-449860388, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGZuJFNQd5RtlsqUUIpi7BhcuuZN-AXks5u8kzRgaJpZM4ZhI_u .

--

Ondřej Mirtes

ondrejmirtes avatar Dec 25 '18 16:12 ondrejmirtes

OK, will give it a whirl

josephzidell avatar Dec 26 '18 03:12 josephzidell

You need to make $class a constructor parameter in these two classes:

  • https://github.com/phpstan/phpstan-phpunit/blob/master/src/Type/PHPUnit/Assert/AssertMethodTypeSpecifyingExtension.php
  • https://github.com/phpstan/phpstan-phpunit/blob/master/src/Type/PHPUnit/Assert/AssertStaticMethodTypeSpecifyingExtension.php

Then you need to specify the class in those services here (as part of arguments key... check PHPStan configs for how it's done):

  • https://github.com/phpstan/phpstan-phpunit/blob/master/extension.neon

Once this change is merged, you will be able to register these services in your own phpstan.neon with custom classes.

ondrejmirtes avatar Dec 27 '18 17:12 ondrejmirtes