-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Test Double Code Generator does not work when PHPUnit is used from PHAR on PHP 8.4 #6093
Comments
This error currently happens even if property hooks are not used. ![]() I first thought #6044 might remedy this for mocks where no property hooks are involved... but nope. We would need to figure out if property hooks are used without touching |
relates to humbug/php-scoper#1092 |
Thank you for your report. Unfortunately, I am not able to reproduce it:
|
Not really, as the issue you reference is about the The issue you are reporting here seems to be rooted in PHP-Scoper wrongly transforming PHP code when PHPUnit's PHAR is built. |
@theofidry What do you think? |
Because we transform PHPUnit's code using PHP-Scoper on PHP 8.3, PHP-Scoper does not know about the built-in Please disregard what I wrote in #6093 (comment) and sorry for the noise. |
@sebastianbergmann here is my reproduction: <?php
namespace App\Tests;
use PHPUnit\Framework\TestCase;
class Abc {
public int $a;
}
class MinimalTest extends TestCase
{
public function testMinimal() {
$mock = $this->createMock(Abc::class);
$this->assertTrue($mock instanceof Abc);
}
} Using the binary: vendor/bin/phpunit tests/MinimalTest.php
PHPUnit 11.5.1 by Sebastian Bergmann and contributors.
Runtime: PHP 8.4.2
Configuration: /Users/jankal/projects/internal/app/phpunit.xml.dist
. 1 / 1 (100%)
Time: 00:00.004, Memory: 10.00 MB
OK (1 test, 1 assertion) Using the PHAR: ./phpunit-11.5.1.phar tests/MinimalTest.php
PHPUnit 11.5.1 by Sebastian Bergmann and contributors.
Runtime: PHP 8.4.2
Configuration: /Users/jankal/projects/internal/app/phpunit.xml.dist
F 1 / 1 (100%)
Time: 00:00.001, Memory: 27.34 MB
There was 1 failure:
1) App\Tests\MinimalTest::testMinimal
assert(class_exists(PropertyHookType::class))
/Users/jankal/projects/internal/app/tests/MinimalTest.php:14
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
exit status 1
My <?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="tests/bootstrap.php"
>
<php>
<ini name="display_errors" value="1" />
<ini name="error_reporting" value="-1" />
<server name="APP_ENV" value="test" force="true" />
<server name="SHELL_VERBOSITY" value="-1" />
</php>
<source>
<include>
<directory>src</directory>
</include>
</source>
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<extensions>
</extensions>
</phpunit> |
@sebastianbergmann I had mentioned the relationship to We might need to track this in separate issues with |
I do not think so, see #6093 (comment). |
Blocked by humbug/php-scoper#1099. |
@jankal Can you please check whether https://github.com/sebastianbergmann/phpunit/actions/runs/12580496240/artifacts/2378104831 (built in https://github.com/sebastianbergmann/phpunit/actions/runs/12580496240/job/35062614523) solves your problem? Thanks! |
@sebastianbergmann the snapshot version works. > ./phpunit-snapshot.phar tests/MinimalTest.php
PHPUnit 11.5.2 by Sebastian Bergmann and contributors.
Runtime: PHP 8.4.2
Configuration: /Users/jankal/projects/internal/app/phpunit.xml.dist
. 1 / 1 (100%)
Time: 00:00.001, Memory: 27.34 MB
OK (1 test, 1 assertion) |
@sebastianbergmann humbug/php-scoper#1100 was merged thus we can move forwared here. |
Ah, it seems you have already updated the dep in bbd266e - nice work! |
Summary
Tests using the
createMock()
method run flawlessly withphpunit
installed as a composer package.They do not run when using the PHAR.
Current behavior
Each test using
createMock()
outputsassert(class_exists(PropertyHookType::class))
- which looks a lot like anAssertionError
.How to reproduce
Run a test-suite using createMock() with the PHAR version of phpunit.
Expected behavior
Tests should run as expected. No assertion fails.
The text was updated successfully, but these errors were encountered: