Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

define() + runInSeparateProcess = Constant already defined #856

Closed
cweiske opened this Issue Mar 13, 2013 · 1 comment

Comments

Projects
None yet
2 participants

cweiske commented Mar 13, 2013

Two test cases, the first includes a file with a define() call. The second has a test that is run in a separate process. The define() call will be made twice, which I can't understand.

Happens with PHP 5.4.6, xdebug 2.2.1 and PHPUnit 3.7.18

Files

ATest.php:

<?php
require_once 'Define.php';
class ATest extends PHPUnit_Framework_TestCase
{
    public function testA2() {}
}
?>

BTest.php:

<?php
class BTest extends PHPUnit_Framework_TestCase
{
    /**
     * @runInSeparateProcess
     */
    public function testB() {}
}
?>

Define.php:

<?php
define('FOO', 1);
?>

Results:

$ phpunit .
PHPUnit 3.7.18 by Sebastian Bergmann.

.E

Time: 0 seconds, Memory: 4.25Mb

There was 1 error:

1) BTest::testB
PHPUnit_Framework_Exception: PHP Notice:  Constant FOO already defined in /home/cweiske/Dev/pear/phpunit-defbug/tests/Define.php on line 2
PHP Stack trace:
PHP   1. {main}() -:0
PHP   2. require_once() -:53
PHP   3. require_once() /home/cweiske/Dev/pear/phpunit-defbug/tests/ATest.php:2
PHP   4. define() /home/cweiske/Dev/pear/phpunit-defbug/tests/Define.php:2

Notice: Constant FOO already defined in /home/cweiske/Dev/pear/phpunit-defbug/tests/Define.php on line 2

Call Stack:
    0.0005     261336   1. {main}() -:0
    0.0022     410920   2. require_once('/home/cweiske/Dev/pear/phpunit-defbug/tests/ATest.#php') -:53
    0.0022     412176   3. require_once('/home/cweiske/Dev/pear/phpunit-defbug/tests/Define.php') /home/cweiske/Dev/pear/phpunit-defbug/tests/ATest.php:2
    0.0022     412352   4. define() /home/cweiske/Dev/pear/phpunit-defbug/tests/Define.php:2


FAILURES!
Tests: 2, Assertions: 0, Errors: 1.
Contributor

whatthejeff commented Mar 13, 2013

This is a duplicate of #314. If possible, you can use @preserveGlobalState disabled as a workaround.

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