diff --git a/tests/Sabre/DAV/AbstractServerTestCase.php b/tests/Sabre/DAV/AbstractServerTestCase.php index 053a229dbc..dcc2e908bf 100644 --- a/tests/Sabre/DAV/AbstractServerTestCase.php +++ b/tests/Sabre/DAV/AbstractServerTestCase.php @@ -25,7 +25,7 @@ abstract class AbstractServerTestCase extends TestCase public function setup(): void { $this->response = new ResponseMock(); - $this->server = new Server($this->getRootNode()); + $this->server = new ServerMock($this->getRootNode()); $this->server->sapi = new HTTP\SapiMock(); $this->server->httpResponse = $this->response; $this->server->debugExceptions = true; diff --git a/tests/Sabre/DAV/Locks/PluginTest.php b/tests/Sabre/DAV/Locks/PluginTest.php index 465bbc1609..7971c3f674 100644 --- a/tests/Sabre/DAV/Locks/PluginTest.php +++ b/tests/Sabre/DAV/Locks/PluginTest.php @@ -321,7 +321,7 @@ public function testLockPutNoToken() $this->server->exec(); self::assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - self::assertTrue(1 === preg_match('/^$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); + self::assertFalse($this->response->hasHeader('Lock-Token'), 'Unexpected Lock-Token in response'); self::assertEquals(423, $this->response->status); } @@ -451,7 +451,7 @@ public function testLockPutBadToken() $this->server->exec(); self::assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - self::assertTrue(1 === preg_match('/^$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); + self::assertFalse($this->response->hasHeader('Lock-Token'), 'We did get unexpected Lock-Token header back in PUT response'); // self::assertEquals('412 Precondition failed',$this->response->status); self::assertEquals(423, $this->response->status); @@ -518,7 +518,7 @@ public function testLockDeleteSucceed() $this->server->exec(); self::assertEquals(204, $this->response->status); - self::assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); + self::assertNull($this->response->body); } /** @@ -591,7 +591,7 @@ public function testLockCopyLockSource() $this->server->exec(); self::assertEquals(201, $this->response->status, 'Copy must succeed if only the source is locked, but not the destination'); - self::assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); + self::assertNull($this->response->body); } /** @@ -759,7 +759,7 @@ public function testLockMoveLockParent() $this->server->exec(); self::assertEquals(201, $this->response->status, 'We locked the parent of both the source and destination, but the move didn\'t succeed.'); - self::assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); + self::assertNull($this->response->body); } /** @@ -792,8 +792,8 @@ public function testLockPutGoodToken() $this->server->httpRequest = $request; $this->server->exec(); - self::assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - self::assertTrue(1 === preg_match('/^$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); + self::assertNull($this->response->body); + self::assertFalse($this->response->hasHeader('Lock-Token'), 'Unexpected Lock-Token header'); self::assertEquals(204, $this->response->status); } @@ -830,8 +830,8 @@ public function testLockPutUnrelatedToken() $this->server->httpRequest = $request; $this->server->exec(); - self::assertEquals('application/xml; charset=utf-8', $this->response->getHeader('Content-Type')); - self::assertTrue(1 === preg_match('/^$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); + self::assertNull($this->response->body); + self::assertFalse($this->response->hasHeader('Lock-Token'), 'Unexpected Lock-Token header'); self::assertEquals(204, $this->response->status); } diff --git a/tests/Sabre/DAV/ServerMock.php b/tests/Sabre/DAV/ServerMock.php new file mode 100644 index 0000000000..bac419a60d --- /dev/null +++ b/tests/Sabre/DAV/ServerMock.php @@ -0,0 +1,25 @@ +httpResponse->reset(); + + parent::start(); + } +} diff --git a/tests/Sabre/HTTP/ResponseMock.php b/tests/Sabre/HTTP/ResponseMock.php index 0d968e178f..318ee6afa3 100644 --- a/tests/Sabre/HTTP/ResponseMock.php +++ b/tests/Sabre/HTTP/ResponseMock.php @@ -20,4 +20,15 @@ class ResponseMock extends Response */ public $body; public int $status; + + /** + * Reset the response state. Needed if making more than one request in a single test. + */ + public function reset() + { + $this->headers = []; + $this->body = null; + $this->status = 500; + $this->statusText = ''; + } }