From 9cb1c2e09dbfd8f792a56c255f19338233117437 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Mon, 1 Dec 2025 19:56:09 +0100 Subject: [PATCH 1/3] Tests: Fix mocked HTTP response state reset between requests --- tests/Sabre/DAV/AbstractServerTestCase.php | 2 +- tests/Sabre/DAV/Locks/PluginTest.php | 16 +++++++------- tests/Sabre/DAV/ServerMock.php | 25 ++++++++++++++++++++++ tests/Sabre/HTTP/ResponseMock.php | 11 ++++++++++ 4 files changed, 45 insertions(+), 9 deletions(-) create mode 100644 tests/Sabre/DAV/ServerMock.php 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..10412bea00 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); } @@ -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..25b83ecd0e 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. + */ + function reset() + { + $this->headers = []; + $this->body = null; + $this->status = 500; + $this->statusText = ''; + } } From c329eca9f3b87957f21fe55169bab0ba93b4adfe Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Mon, 1 Dec 2025 20:05:04 +0100 Subject: [PATCH 2/3] Fix one more assertion --- tests/Sabre/DAV/Locks/PluginTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Sabre/DAV/Locks/PluginTest.php b/tests/Sabre/DAV/Locks/PluginTest.php index 10412bea00..7971c3f674 100644 --- a/tests/Sabre/DAV/Locks/PluginTest.php +++ b/tests/Sabre/DAV/Locks/PluginTest.php @@ -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); From fcd499d444df0024878cefe2a3118b23fdea2b98 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Mon, 1 Dec 2025 20:10:38 +0100 Subject: [PATCH 3/3] Fix coding style --- tests/Sabre/HTTP/ResponseMock.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Sabre/HTTP/ResponseMock.php b/tests/Sabre/HTTP/ResponseMock.php index 25b83ecd0e..318ee6afa3 100644 --- a/tests/Sabre/HTTP/ResponseMock.php +++ b/tests/Sabre/HTTP/ResponseMock.php @@ -24,7 +24,7 @@ class ResponseMock extends Response /** * Reset the response state. Needed if making more than one request in a single test. */ - function reset() + public function reset() { $this->headers = []; $this->body = null;