Skip to content

Make it easy for Drupal to use the PHPUnit bridge #24685

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

Closed
wants to merge 5 commits into from

Conversation

alexpott
Copy link
Contributor

@alexpott alexpott commented Oct 24, 2017

Q A
Branch? 3.3
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #...
License MIT
Doc PR symfony/symfony-docs#...

Drupal doesn't use src/Symfony/Bridge/PhpUnit/bin/simple-phpunit but would like to use the deprecation collection features of src/Symfony/Bridge/PhpUnit. The checks in src/Symfony/Bridge/PhpUnit/bootstrap.php mean that this is difficult because they rely on simple-phpunit - but I'm not sure that that is necessary.

@@ -342,8 +342,9 @@ public function request($method, $uri, array $parameters = array(), array $files
protected function doRequestInProcess($request)
{
$deprecationsFile = tempnam(sys_get_temp_dir(), 'deprec');
putenv('SYMFONY_DEPRECATIONS_SERIALIZE='.$deprecationsFile);
$process = new PhpProcess($this->getScript($request), null, null);
$environment = getenv();
Copy link
Member

Choose a reason for hiding this comment

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

this doesn't work before PHP 7.1
but I don't get what it changes in fact, so maybe it's not required at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What this was trying to do was only set SYMFONY_DEPRECATIONS_SERIALIZE in the sub process so we didn't have to unset it after making the request.

Copy link
Member

Choose a reason for hiding this comment

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

why not just relying on the feature of the Process component inheriting the env variables ?

@nicolas-grekas
Copy link
Member

I'm not sure I understand the technical purpose of this PR :)

@alexpott
Copy link
Contributor Author

The technical purpose of this PR is to make PHPUnit Bridge's bootstrap.php not rely on assumptions about the environment. The problem is that we're doing

// We define the COMPOSER_INSTALL constant, so that PHPUnit knows where to
// autoload from. This is needed for tests run in isolation mode, because
// phpunit.xml.dist is located in a non-default directory relative to the
// PHPUnit executable.
if (!defined('PHPUNIT_COMPOSER_INSTALL')) {
  define('PHPUNIT_COMPOSER_INSTALL', __DIR__ . '/../../autoload.php');
}

in our test bootstrap - so the assumption made by
if (!defined('PHPUNIT_COMPOSER_INSTALL') && !class_exists('PHPUnit_TextUI_Command', false) && !class_exists('PHPUnit\TextUI\Command', false)) {
is not correct for us.

@@ -12,11 +12,9 @@
use Doctrine\Common\Annotations\AnnotationRegistry;
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler;

// Detect if we're loaded by an actual run of phpunit
if (!defined('PHPUNIT_COMPOSER_INSTALL') && !class_exists('PHPUnit_TextUI_Command', false) && !class_exists('PHPUnit\TextUI\Command', false)) {
Copy link
Member

Choose a reason for hiding this comment

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

removing this is broken. The logic will now register the bridge error handler even when the bootstrap.php file was not loaded during a composer run but during a normal usage of the app using the composer autoloader.

@stof
Copy link
Member

stof commented Oct 25, 2017

@alexpott are you actually defining PHPUNIT_COMPOSER_INSTALL even when not running PHPUnit ?

@alexpott
Copy link
Contributor Author

@stof nope we're not defining when not running PHPUnit - we define it when running PHPUnit and inside an isolated test. This is because in PHPUnit's src/Util/PHP/Template/TestCaseMethod.tpl.dist it does

$configurationFilePath = '{configurationFilePath}';

if ('' !== $configurationFilePath) {
    $configuration = PHPUnit\Util\Configuration::getInstance($configurationFilePath);
    $configuration->handlePHPConfiguration();
    unset($configuration);
}

which needs to be able to autoload PHPUnit\Util\Configuration for drupal because we use a non-standard configurationFilePath. See https://www.drupal.org/node/2597814 for a bit more info.

@nicolas-grekas nicolas-grekas added this to the 3.3 milestone Oct 25, 2017
@alexpott alexpott force-pushed the allow-drupal-to-use-bridge branch from 145bcd1 to be56b35 Compare October 25, 2017 10:48
@alexpott alexpott changed the base branch from master to 3.3 October 25, 2017 10:48
@alexpott
Copy link
Contributor Author

I've updated the PR to only remove the check against PHPUNIT_COMPOSER_INSTALL since this constant is necessary for PHPUnit isolated tests where you are using a custom configuration file. I've tested this approach with Drupal and it works great. I've also tested Symfony locally with 5.5, 5.6 and 7.1 and it passes.

@alexpott
Copy link
Contributor Author

I'm just testing this with Drupal and I've found something more odd going on. Still investigating. :(

@nicolas-grekas
Copy link
Member

Thank you @alexpott.

nicolas-grekas added a commit that referenced this pull request Oct 25, 2017
…e (alexpott)"

This reverts commit 41509a2, reversing
changes made to 3e3e74c.
nicolas-grekas added a commit that referenced this pull request Oct 25, 2017
* 3.3:
  Revert "minor #24685 Make it easy for Drupal to use the PHPUnit bridge (alexpott)"
nicolas-grekas added a commit that referenced this pull request Oct 25, 2017
* 3.4:
  Revert "minor #24685 Make it easy for Drupal to use the PHPUnit bridge (alexpott)"
@nicolas-grekas
Copy link
Member

Reverted as it breaks something on our CI.

1) Symfony\Component\Process\Tests\ProcessTest::testThatProcessDoesNotThrowWarningDuringRun
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'Test Error'
+'The Symfony\Component\Process\Process::setEnhanceSigchildCompatibility() method is deprecated since version 3.3 and will be removed in 4.0. Sigchild compatibility will always be enabled.'

/home/nicolas/Code/symfony/src/Symfony/Component/Process/Tests/ProcessTest.php:100

This can be reproduced locally by applying this patch:

--- a/src/Symfony/Component/Process/Tests/ProcessTest.php
+++ b/src/Symfony/Component/Process/Tests/ProcessTest.php
@@ -1583,7 +1583,7 @@ EOTXT;
             try {
                 $process->setEnhanceSigchildCompatibility(false);
                 $process->getExitCode();
-                $this->fail('ENHANCE_SIGCHLD must be used together with a sigchild-enabled PHP.');
+ //               $this->fail('ENHANCE_SIGCHLD must be used together with a sigchild-enabled PHP.');
             } catch (RuntimeException $e) {
                 $this->assertSame('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.', $e->getMessage());
                 if ($enhance) {

then running
SYMFONY_DEPRECATIONS_HELPER=weak ENHANCE_SIGCHLD=0 ./phpunit src/Symfony/Component/Process/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants