phpstan-phpunit
phpstan-phpunit copied to clipboard
assertStringStartsWith after assertNotEmpty fails
assertStringStartsWith after assertNotEmpty fails with error "Parameter #1 $prefix of method PHPUnit\Framework\Assert::assertStringStartsWith() expects non-empty-string', while the string cannot be empty due to the assertNotEmpty call.
<?php
use PHPUnit\Framework\TestCase;
class FooTest extends TestCase {
public function testFoo(): void
{
$string = ([
'',
'bar',
])[rand(0, 1)];
$this->assertNotEmpty($string);
$this->assertStringStartsWith($string, 'baz');
}
}
Can't reproduce the problem: https://phpstan.org/r/91888ed1-d67f-4749-9d9c-a617da10722b
Please show the output of vendor/bin/phpstan diagnose.
I get the problem now, phpstan-phpunit has a special type-specifying extension that doesn't work for strings: https://github.com/phpstan/phpstan-phpunit/blob/d35895e0388e9aa822af00e1dfd4f8086fd8938d/src/Type/PHPUnit/Assert/AssertTypeSpecifyingExtensionHelper.php#L168-L177
I was not able to reproduce the issue, but I think https://github.com/phpstan/phpstan-src/pull/4473 will have fixed it in case its still relevant
@gisostallenberg please double check whether this issue still reproduces on the latest release