Skip to content

Starting recommending to run PHPUnit directly #906

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
3 commits merged into from
Mar 24, 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
2 changes: 2 additions & 0 deletions phpunit/phpunit/4.7/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
KERNEL_CLASS='App\Kernel'
APP_SECRET='$ecretf0rt3st'
SYMFONY_DEPRECATIONS_HELPER=999999
PANTHER_APP_ENV=panther
PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots
14 changes: 14 additions & 0 deletions phpunit/phpunit/4.7/phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,18 @@
<directory suffix=".php">src</directory>
</whitelist>
</filter>

<!-- Run `composer require symfony/phpunit-bridge` before enabling this extension -->
<!--
<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>
-->
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 just to make this file consistent with the phpunit.xml.dist file from the phpunit-bridge recipe, in case someone installs phpunit directly (and not via the pack, where you will get the phpunit.xml.dist file from phpunit-bridge)

Copy link
Member

Choose a reason for hiding this comment

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

A nice addition would be to have a PHPUnit configurator in Flex.

</phpunit>
11 changes: 0 additions & 11 deletions phpunit/phpunit/4.7/post-install.txt

This file was deleted.

6 changes: 6 additions & 0 deletions symfony/phpunit-bridge/5.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
16 changes: 16 additions & 0 deletions symfony/phpunit-bridge/5.3/bin/phpunit
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env php
<?php
if (file_exists(dirname(__DIR__).'/vendor/phpunit/phpunit/phpunit')) {
require(dirname(__DIR__).'/vendor/phpunit/phpunit/phpunit');
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 new part: if PHPUnit is install directly, use it.

Choose a reason for hiding this comment

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

I tried adding this to my bin/phpunit file and I'm getting

PHP Fatal error:  strict_types declaration must be the very first statement in the script

Copy link
Member

Choose a reason for hiding this comment

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

Did you try without strict type declaration?
This file don't include any.

Copy link
Member

Choose a reason for hiding this comment

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

Already fixed in #952

Choose a reason for hiding this comment

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

Already fixed in #952

Indeed, thanks

} else {
if (!file_exists(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';
}
14 changes: 14 additions & 0 deletions symfony/phpunit-bridge/5.3/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"copy-from-recipe": {
".env.test": ".env.test",
"bin/": "%BIN_DIR%/",
"phpunit.xml.dist": "phpunit.xml.dist",
"tests/": "tests/"
},
"gitignore": [
".phpunit",
".phpunit.result.cache",
"/phpunit.xml"
],
"aliases": ["simple-phpunit"]
}
45 changes: 45 additions & 0 deletions symfony/phpunit-bridge/5.3/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?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"
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" />
<!-- 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" />
-->
</php>

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

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

<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>
7 changes: 7 additions & 0 deletions symfony/phpunit-bridge/5.3/post-install.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<bg=blue;fg=white> </>
<bg=blue;fg=white> How to test? </>
<bg=blue;fg=white> </>

* <fg=blue>Write</> test cases in the <comment>tests/</> folder
* Use MakerBundle's <comment>make:test</> command as a shortcut!
* <fg=blue>Run</> the tests with <comment>php bin/phpunit</>
11 changes: 11 additions & 0 deletions symfony/phpunit-bridge/5.3/tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

use Symfony\Component\Dotenv\Dotenv;

require dirname(__DIR__).'/vendor/autoload.php';

if (file_exists(dirname(__DIR__).'/config/bootstrap.php')) {
require dirname(__DIR__).'/config/bootstrap.php';
} elseif (method_exists(Dotenv::class, 'bootEnv')) {
(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
}