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

PHPUnit extensions and rules for PHPStan

Results 40 phpstan-phpunit issues
Sort by recently updated
recently updated
newest added

Hi @ondrejmirtes, I just got an issue with my tests saying that an offset does not exist in an array. I tried to add a `assertArrayHasKey` check, without success. I...

```php final class MyTest extends \PHPUnit\Framework\TestCase { public function testMe(): void { $foo = new class([1]) extends ArrayIterator { public function current(): void { throw new RuntimeException('foo'); } }; $this->expectException(\RuntimeException::class);...

I noticed a strange error "Unable to resolve the template type ExpectedType" when executing the same statement twice. Please see the following example code: ```php class Test extends \PHPUnit\Framework\TestCase {...

Calling `createMock` with multiple Types causes phpstan to report errors: A class like ```

```php self::assertArrayHasKey(1, $ubos); self::assertFalse($ubos[1]->isActive); ``` produces ``` Offset 1 does not exist on array(MangoPay\Ubo). ``` related class: https://github.com/Mangopay/mangopay2-php-sdk/blob/d967b3fb6f45a0f01891134062265144950c9259/MangoPay/UboDeclaration.php

Given ```php class MyClass { public function foo(): string {} } class MyOtherClassTest extends \PHPUnit\Framework\TestCase { public function testFooMock() { $class = $this->createMock(MyClass::class); $class ->expects(static::once()) ->method('foo') ->willReturn(123) ; } }...

Doctrine is using the following legacy format on some places: ```php self::assertInstanceOf(__NAMESPACE__.'\\MyFetchClass', $results[0]); ``` in a test located inside the `Doctrine\Tests\DBAL\Functional\DataAccessTest` test case. The above incorrectly resolves as `Doctrine\MyFetchClass` instead...

Here is a list of a ideas that may be implemented in the future: - [ ] suggest `assertInstanceOf(Foo::class, $a)` instead of `assertTrue($a instanceof Foo)` - [ ] suggest `assertNotInstanceOf(Foo::class,...

Example ```php class Test extends \PHPUnit\Framework\TestCase { public function testAssertVariable() { $foo = null; $value = new \stdClass(); $mock = $this->getMockBuilder('Foo')->setMethods(['update'])->getMock(); $mock->method('update')->willReturnCallback(function () use (&$foo, $value) { $foo = $value;...

bug

`assertSame` uses `===` php operator and `NAN === NAN` is false we should advise to use `assertNan`