Short question: Did the behavior of $this
in a scope change from PHP 5.3.29 to 5.5.24? I couldn't find any relevant changes in the PHP 5 Changelog.
Details: In this question, I thought I had a solution for my problem (In PHPUnit, expect method call with array as argument). This was my solution
public function test_actionUpload_v10MasterdataFile()
{
/*
* Create a stub to disable the original constructor.
* Exposing data and rendering are stubbed.
* All other methods behave exactly the same as in the real Controller.
*/
$sut = $this->getMockBuilder('MasterdataController')
->setMethods(array('exposeAndSaveDataLines', 'render'))
->disableOriginalConstructor()
->getMock();
$sut->expects($this->once())
->method('exposeAndSaveDataLines')
->will($this->returnCallback(function($lines) {
$expectedLines = include ($this->dataDir() . 'ExpectedLines.php');
PHPUnit_Framework_Assert::assertTrue($this->similar_arrays($lines, $expectedLines));
}));
// Execute the test
$sut->actionUpload();
}
It is working on my local environment (PHP 5.5.24, Zend Engine v2.5.0), but when I copy the code to our test server (PHP 5.3.29, Zend Engine v2.3.0), this does not work, due to this line:
$expectedLines = include ($this->dataDir() . 'ExpectedLines.php');
The error is:
Using $this when not in object context
Could this be due to PHP version, or should I look somewhere else for the reason why it fails on one server, but not on another?