Skip to content
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

Notice: Undefined index: _SERVER in PHPUnit/Util/Filter.php on line 69 #705

Closed
ValerchikV opened this issue Nov 2, 2012 · 7 comments
Closed

Comments

@ValerchikV
Copy link

I run tests and got this error:
Notice: Undefined index: _SERVER in /usr/share/pear/PHPUnit/Util/Filter.php on line 69

Full output dump:
phpunit --bootstrap=modules/unittest/bootstrap.php modules/unittest/tests.php
PHPUnit 3.7.8 by Sebastian Bergmann.

.............................S..........SSSSSSSSSSSSSSSSSSSSS 61 / 1299 ( 4%)
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS 122 / 1299 ( 9%)
SSSS......................................................... 183 / 1299 ( 14%)
............................................................. 244 / 1299 ( 18%)
.SSSSSS............SS........................................ 305 / 1299 ( 23%)
............................................................. 366 / 1299 ( 28%)
..............................................F.............S 427 / 1299 ( 32%)
.SS.......................................................... 488 / 1299 ( 37%)
............................................................. 549 / 1299 ( 42%)
............................................................. 610 / 1299 ( 46%)
............................................................. 671 / 1299 ( 51%)
.........................S.................................SS 732 / 1299 ( 56%)
SSS..I....................................................... 793 / 1299 ( 61%)
............................................................. 854 / 1299 ( 65%)
.....................................F....................... 915 / 1299 ( 70%)
............................................................. 976 / 1299 ( 75%)
............................................................. 1037 / 1299 ( 79%)
............................................................. 1098 / 1299 ( 84%)
............................................................. 1159 / 1299 ( 89%)
............................................................. 1220 / 1299 ( 93%)
............................................................. 1281 / 1299 ( 98%)
..................

Time: 34 seconds, Memory: 22.50Mb

There were 2 failures:

  1. Kohana_DebugTest::test_dump with data set junit xml log for phpt tests does not appear to work #6 ('foo▒' . "\0" . 'bar▒±10', 128, 10, 'string(10) "foobar±10"')

Notice: Undefined index: _SERVER in /usr/share/pear/PHPUnit/Util/Filter.php on line 69
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'string(10) "foobar±10"'
+'string(0) ""'

/mnt/hgfs/ipnew/system/tests/kohana/DebugTest.php:124
/mnt/hgfs/ipnew/modules/unittest/classes/Kohana/Unittest/TestSuite.php:51
/usr/bin/phpunit:46

  1. Kohana_UTF8Test::test_clean with data set Mocking class Imagick of pecl/imagick 3.0.0 fails with PHPUnit 3.4.2 and 3.5 beta1 #3 ('▒', '')

Notice: Undefined index: _SERVER in /usr/share/pear/PHPUnit/Util/Filter.php on line 69
Failed asserting that false is identical to ''.

/mnt/hgfs/ipnew/system/tests/kohana/UTF8Test.php:41
/mnt/hgfs/ipnew/modules/unittest/classes/Kohana/Unittest/TestSuite.php:51
/usr/bin/phpunit:46

FAILURES!
Tests: 1299, Assertions: 2749, Failures: 2, Incomplete: 1, Skipped: 104.

@sebastianbergmann
Copy link
Owner

Are you unsetting $GLOBALS['_SERVER'] in your code?

@ValerchikV
Copy link
Author

I did text search of all usages of $GLOBALS['_SERVER'] and dont found anything.

var_dump($GLOBALS['_SERVER']); Giving me NULL also

@acidtv
Copy link

acidtv commented Nov 14, 2012

I noticed ValerchikV runs Kohana. I have the same problem trying to unittest kohana.

@acidtv
Copy link

acidtv commented Nov 14, 2012

Think this can be closed here. Kohana messes up the $GLOBALS array in CoreTest.php:110

$GLOBALS = array('hackers' => 'foobar','name' => array('','',''), '_POST' => array());

@hkdobrev
Copy link

hkdobrev commented Feb 3, 2013

Sorry comment on this unrelated issue, but I have a quick fix for anyone in the thread. Just disable the core Kohana tests from the unittest config with 'system' => FALSE and be happy :)

@g105b
Copy link

g105b commented Jul 3, 2014

This thread turned up at number 1 search result when I searched for Undefined index: _SERVER, which is what I was experiencing while writing some tests earlier.

I wanted to clean up the modifications to _SERVER that my tests made in order to test the code I'm writing which relies upon indices such as REQUEST_URI, REQUEST_METHOD and SERVER_PROTOCOL, for instance. In the tearDown method, I simply unset($_SERVER) to allow all my test cases to have the same starting point (so I thought).

Here's how I am currently getting round this issue, in case it helps others who are searching for the same thing:

<?php
class Example_Test extends \PHPUnit_Framework_TestCase {

private $_SERVER;

public function setUp() {
    // Store a copy of the superglobal on the testcase object.
    $this->_SERVER = $_SERVER;
    // ...
}

public function tearDown() {
    // ...
    // Restore the original superglobal its pre-test state.
    $_SERVER = $this->_SERVER;
}

@sebastianbergmann
Copy link
Owner

By default, PHPUnit runs your tests in a way where changes to global and super-global variables ($GLOBALS, $_ENV, $_POST, $_GET, $_COOKIE, $_SERVER, $_FILES, $_REQUEST) do not affect other tests.

See http://phpunit.de/manual/current/en/fixtures.html#fixtures.global-state for details.

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

No branches or pull requests

5 participants