Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/Sabre/DAV/AbstractServerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions tests/Sabre/DAV/Locks/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('/^<opaquelocktoken:(.*)>$/', $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);
}
Expand Down Expand Up @@ -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('/^<opaquelocktoken:(.*)>$/', $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);
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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('/^<opaquelocktoken:(.*)>$/', $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);
}
Expand Down Expand Up @@ -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('/^<opaquelocktoken:(.*)>$/', $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);
}
Expand Down
25 changes: 25 additions & 0 deletions tests/Sabre/DAV/ServerMock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Sabre\DAV;

/**
* DAV Server Mock object.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class ServerMock extends Server
{
/**
* Starts the DAV Server making sure the mocked response state is reset.
*/
public function start()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function start()
public function start(): void

{
$this->httpResponse->reset();

parent::start();
}
}
11 changes: 11 additions & 0 deletions tests/Sabre/HTTP/ResponseMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function reset()
public function reset(): void

{
$this->headers = [];
$this->body = null;
$this->status = 500;
$this->statusText = '';
}
}