Don't use runInSeparateProcess

Directly calling "header" in the PHPUnit process causes the "Cannot
modify header information - headers already sent by" error to be thrown.
Instead of running the test in a separate process, which is slower, this
commit wraps the call to "header" in a method that can be mocked in the
tests.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
Thomas Müller 2017-11-27 19:41:48 +01:00 committed by Daniel Calviño Sánchez
parent a5e4c2ea11
commit ffe034abb0
2 changed files with 11 additions and 7 deletions

View File

@ -235,7 +235,7 @@ class File extends Node implements IFile {
if (isset($this->request->server['HTTP_X_OC_MTIME'])) {
$mtime = $this->sanitizeMtime($this->request->server['HTTP_X_OC_MTIME']);
if ($this->fileView->touch($this->path, $mtime)) {
header('X-OC-MTime: accepted');
$this->header('X-OC-MTime: accepted');
}
}
@ -492,7 +492,7 @@ class File extends Node implements IFile {
if (isset($this->request->server['HTTP_X_OC_MTIME'])) {
$mtime = $this->sanitizeMtime($this->request->server['HTTP_X_OC_MTIME']);
if ($targetStorage->touch($targetInternalPath, $mtime)) {
header('X-OC-MTime: accepted');
$this->header('X-OC-MTime: accepted');
}
}
@ -605,4 +605,8 @@ class File extends Node implements IFile {
public function getChecksum() {
return $this->info->getChecksum();
}
protected function header($string) {
\header($string);
}
}

View File

@ -310,7 +310,11 @@ class FileTest extends \Test\TestCase {
null
);
$file = new \OCA\DAV\Connector\Sabre\File($view, $info, null, $request);
/** @var \OCA\DAV\Connector\Sabre\File | \PHPUnit_Framework_MockObject_MockObject $file */
$file = $this->getMockBuilder(\OCA\DAV\Connector\Sabre\File::class)
->setConstructorArgs([$view, $info, null, $request])
->setMethods(['header'])
->getMock();
// beforeMethod locks
$view->lockFile($path, ILockingProvider::LOCK_SHARED);
@ -385,8 +389,6 @@ class FileTest extends \Test\TestCase {
/**
* Test putting a file with string Mtime
* @runInSeparateProcess
* @preserveGlobalState disabled
* @dataProvider legalMtimeProvider
*/
public function testPutSingleFileLegalMtime($requestMtime, $resultMtime) {
@ -411,8 +413,6 @@ class FileTest extends \Test\TestCase {
/**
* Test putting a file with string Mtime using chunking
* @runInSeparateProcess
* @preserveGlobalState disabled
* @dataProvider legalMtimeProvider
*/
public function testChunkedPutLegalMtime($requestMtime, $resultMtime) {