Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok, I figured out what is going on here and boy is it a doozy.</p> <p>During testing the framework attempts to preserve global state. In the <code>PHPUnit_Framework_TestCase::run()</code> function the current globals are converted into a string of PHP code by <code>PHPUnit_Util_GlobalState::getGlobalsAsString()</code>. I am currently using an autoloading library to take care of requiring appropriate class files. This class was declared in a variable that was in the global scope, causing a serialization of that object to be put into the <code>$GLOBALS</code> array created by <code>getGlobalsAsString()</code>. This serialization, for whatever reason, includes the null byte character <code>\u0000</code>. When you attempt to unserialize this you get an error and is ultimately causing the output to be corrupted as well.</p> <p>I fixed this issue by create a function in my test bootstrap that creates the autoloading object outside of the global scope. Now that the script is no longer attempting to unserialize a null byte the script produces no errors and the test case works as expected. This is a really funky issue, not sure if its an error in my code, PHPUnit's code or an internal error with the <code>serialize</code> function.</p> <hr> <p>Alternatively you can override the <code>run()</code> function in your test case and explicitly set the test case to not preserve global state. This is probably a cleaner solution as you could easily run into other issues with requiring all included files again as is the default behavior.</p> <pre><code>class ManagerTest extends PHPUnit_Framework_TestCase { public function run(PHPUnit_Framework_TestResult $result = null) { $this-&gt;setPreserveGlobalState(false); parent::run($result); } } </code></pre> <p>Global state must be set <em>before</em> the <code>PHPUnit_Framework_TestCase::run()</code> function is invoked. This is likely the only way to reliably set the global state preservation properly.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload