Skip to content

Fix recipe for phpunit #952

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

Merged
1 commit merged into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions phpunit/phpunit/4.7/phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@
</whitelist>
</filter>

<!-- Run `composer require symfony/phpunit-bridge` before enabling this extension -->
Copy link
Member Author

Choose a reason for hiding this comment

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

This removes any diff between phpunit.xml.dist shipped by simple-phpunit vs phpunit recipes.
Without this change, what ppl get is random, leading to the deprecation report being unavailable.

<!--
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>
-->

<!-- Run `composer require symfony/panther` before enabling this extension -->
<!--
Expand Down
6 changes: 6 additions & 0 deletions phpunit/phpunit/9.3/.env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# define your env variables for the test env here
KERNEL_CLASS='App\Kernel'
APP_SECRET='$ecretf0rt3st'
SYMFONY_DEPRECATIONS_HELPER=999999
PANTHER_APP_ENV=panther
PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots
11 changes: 11 additions & 0 deletions phpunit/phpunit/9.3/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"copy-from-recipe": {
".env.test": ".env.test",
"phpunit.xml.dist": "phpunit.xml.dist",
"tests/": "tests/"
},
"gitignore": [
"/phpunit.xml",
".phpunit.result.cache"
]
}
40 changes: 40 additions & 0 deletions phpunit/phpunit/9.3/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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="error_reporting" value="-1" />
<server name="APP_ENV" value="test" force="true" />
<server name="SHELL_VERBOSITY" value="-1" />
<server name="SYMFONY_PHPUNIT_REMOVE" value="" />
<server name="SYMFONY_PHPUNIT_VERSION" value="9.5" />
</php>

<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
Copy link
Member

Choose a reason for hiding this comment

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

Note to others: changes made to the schema for PHPUnit 9.


<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>

<!-- Run `composer require symfony/panther` before enabling this extension -->
<!--
<extensions>
<extension class="Symfony\Component\Panther\ServerExtension" />
</extensions>
-->
</phpunit>
1 change: 1 addition & 0 deletions phpunit/phpunit/9.3/tests
17 changes: 10 additions & 7 deletions symfony/phpunit-bridge/5.3/bin/phpunit
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#!/usr/bin/env php
<?php
if (file_exists(dirname(__DIR__).'/vendor/phpunit/phpunit/phpunit')) {
require dirname(__DIR__).'/vendor/phpunit/phpunit/phpunit';

if (!ini_get('date.timezone')) {
ini_set('date.timezone', 'UTC');
}

if (is_file(dirname(__DIR__).'/vendor/phpunit/phpunit/phpunit')) {
define('PHPUNIT_COMPOSER_INSTALL', dirname(__DIR__).'/vendor/autoload.php');
require PHPUNIT_COMPOSER_INSTALL;
PHPUnit\TextUI\Command::main();
Copy link
Member

Choose a reason for hiding this comment

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

Is this the real significant portion of this PR? Could you explain a bit further?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the only possible fix for #936

Copy link
Member

Choose a reason for hiding this comment

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

I see how there is no PHP file in phpunit to directly require. And so, you've mimicked their phpunit executable.

} else {
if (!file_exists(dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php')) {
if (!is_file(dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php')) {
echo "Unable to find the `simple-phpunit.php` script in `vendor/symfony/phpunit-bridge/bin/`.\n";
exit(1);
}

if (false === getenv('SYMFONY_PHPUNIT_DIR')) {
putenv('SYMFONY_PHPUNIT_DIR='.__DIR__.'/.phpunit');
}

require dirname(__DIR__).'/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php';
}
1 change: 0 additions & 1 deletion symfony/phpunit-bridge/5.3/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"tests/": "tests/"
},
"gitignore": [
".phpunit",
Copy link

@fmonts fmonts Aug 31, 2021

Choose a reason for hiding this comment

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

Why .phpunit has been removed from .gitignore? I don't think that directory should be committed to the application source code, in my case it contains 2600+ files...

Copy link
Member

Choose a reason for hiding this comment

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

Because now we prefer using the binary from PHPUnit (which does not create .phpunit folder) instead the binary from Symfony PHPUnit bridge (simple-phpunit).

So adding .phpunit in .gitignore is not useful anymore.

".phpunit.result.cache",
"/phpunit.xml"
],
Expand Down
15 changes: 5 additions & 10 deletions symfony/phpunit-bridge/5.3/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
<!-- If you use phpunit-bridge directly, set -->
<!-- xsi:noNamespaceSchemaLocation="bin/.phpunit/phpunit.xsd" -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
Expand All @@ -13,11 +11,8 @@
<ini name="error_reporting" value="-1" />
<server name="APP_ENV" value="test" force="true" />
<server name="SHELL_VERBOSITY" value="-1" />
<!-- If you use phpunit-bridge directly, you can control extra behavior -->
<!--
<server name="SYMFONY_PHPUNIT_REMOVE" value="" />
<server name="SYMFONY_PHPUNIT_VERSION" value="8.5" />
-->
<server name="SYMFONY_PHPUNIT_VERSION" value="9.5" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Symfony 5.3 requires php 7.2. But phpunit 9.5 requires php 7.3. So PHP 7.2 users won't be able to run phpunit by default or am I misunderstanding this?

Copy link

Choose a reason for hiding this comment

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

PHP 7.2 is EOL so it shouldn't be maintained anymore IMHO

</php>

<testsuites>
Expand All @@ -26,11 +21,11 @@
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</include>
</coverage>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
Expand Down