diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 150f4678c2..f973f5d73d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,7 +53,7 @@ jobs: strategy: fail-fast: false matrix: - php-versions: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ] + php-versions: [ '7.4', '8.0', '8.1', '8.2' ] coverage: [ 'xdebug' ] streaming: [ false ] include: diff --git a/composer.json b/composer.json index d7fc7bbd9b..d08cfdc657 100644 --- a/composer.json +++ b/composer.json @@ -14,29 +14,28 @@ } ], "require": { - "php": "^7.1.0 || ^8.0", - "sabre/vobject": "^4.2.1", - "sabre/event" : "^5.0", - "sabre/xml" : "^2.0.1", - "sabre/http" : "^5.0.5", - "sabre/uri" : "^2.0", + "php": "^7.4.0 || ^8.0", + "ext-ctype": "*", + "ext-date": "*", "ext-dom": "*", + "ext-iconv": "*", + "ext-json": "*", + "ext-mbstring": "*", "ext-pcre": "*", - "ext-spl": "*", "ext-simplexml": "*", - "ext-mbstring" : "*", - "ext-ctype" : "*", - "ext-date" : "*", - "ext-iconv" : "*", - "lib-libxml" : ">=2.7.0", + "ext-spl": "*", + "lib-libxml": ">=2.7.0", "psr/log": "^1.0 || ^2.0 || ^3.0", - "ext-json": "*" + "sabre/event": "^6.0", + "sabre/http": "^7.0", + "sabre/vobject": "^4.5" }, "require-dev" : { + "ext-sqlite3": "*", "friendsofphp/php-cs-fixer": "^2.19", + "monolog/monolog": "^1.27", "phpstan/phpstan": "^0.12 || ^1.0", - "phpunit/phpunit" : "^7.5 || ^8.5 || ^9.6", - "monolog/monolog": "^1.27" + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.6" }, "suggest" : { "ext-curl" : "*", @@ -78,7 +77,7 @@ "php-cs-fixer fix" ], "phpunit": [ - "phpunit --configuration tests/phpunit.xml" + "phpunit --configuration tests/phpunit.xml tests" ], "test": [ "composer phpstan", diff --git a/lib/CalDAV/Xml/Notification/Invite.php b/lib/CalDAV/Xml/Notification/Invite.php index 2dbb0f4984..71ccf49b15 100644 --- a/lib/CalDAV/Xml/Notification/Invite.php +++ b/lib/CalDAV/Xml/Notification/Invite.php @@ -182,7 +182,7 @@ public function __construct(array $values) * * If you are opening new elements, you must also close them again. */ - public function xmlSerialize(Writer $writer) + public function xmlSerialize(Writer $writer): void { $writer->writeElement('{'.CalDAV\Plugin::NS_CALENDARSERVER.'}invite-notification'); } diff --git a/lib/CalDAV/Xml/Notification/InviteReply.php b/lib/CalDAV/Xml/Notification/InviteReply.php index dbdba3b027..60bd0015bb 100644 --- a/lib/CalDAV/Xml/Notification/InviteReply.php +++ b/lib/CalDAV/Xml/Notification/InviteReply.php @@ -131,7 +131,7 @@ public function __construct(array $values) * * If you are opening new elements, you must also close them again. */ - public function xmlSerialize(Writer $writer) + public function xmlSerialize(Writer $writer): void { $writer->writeElement('{'.CalDAV\Plugin::NS_CALENDARSERVER.'}invite-reply'); } diff --git a/lib/CalDAV/Xml/Notification/SystemStatus.php b/lib/CalDAV/Xml/Notification/SystemStatus.php index 6d196b30c6..666f8f4c5e 100644 --- a/lib/CalDAV/Xml/Notification/SystemStatus.php +++ b/lib/CalDAV/Xml/Notification/SystemStatus.php @@ -91,7 +91,7 @@ public function __construct($id, $etag, $type = self::TYPE_HIGH, $description = * Important note 2: If you are writing any new elements, you are also * responsible for closing them. */ - public function xmlSerialize(Writer $writer) + public function xmlSerialize(Writer $writer): void { switch ($this->type) { case self::TYPE_LOW: diff --git a/lib/CalDAV/Xml/Property/AllowedSharingModes.php b/lib/CalDAV/Xml/Property/AllowedSharingModes.php index 58acb6d540..589f1be3c0 100644 --- a/lib/CalDAV/Xml/Property/AllowedSharingModes.php +++ b/lib/CalDAV/Xml/Property/AllowedSharingModes.php @@ -69,7 +69,7 @@ public function __construct($canBeShared, $canBePublished) * * If you are opening new elements, you must also close them again. */ - public function xmlSerialize(Writer $writer) + public function xmlSerialize(Writer $writer): void { if ($this->canBeShared) { $writer->writeElement('{'.Plugin::NS_CALENDARSERVER.'}can-be-shared'); diff --git a/lib/CalDAV/Xml/Property/EmailAddressSet.php b/lib/CalDAV/Xml/Property/EmailAddressSet.php index 84f7ae02f1..0348649b4c 100644 --- a/lib/CalDAV/Xml/Property/EmailAddressSet.php +++ b/lib/CalDAV/Xml/Property/EmailAddressSet.php @@ -62,7 +62,7 @@ public function getValue() * * If you are opening new elements, you must also close them again. */ - public function xmlSerialize(Writer $writer) + public function xmlSerialize(Writer $writer): void { foreach ($this->emails as $email) { $writer->writeElement('{http://calendarserver.org/ns/}email-address', $email); diff --git a/lib/CalDAV/Xml/Property/Invite.php b/lib/CalDAV/Xml/Property/Invite.php index c389ca827d..ea5e505456 100644 --- a/lib/CalDAV/Xml/Property/Invite.php +++ b/lib/CalDAV/Xml/Property/Invite.php @@ -68,7 +68,7 @@ public function getValue() * * If you are opening new elements, you must also close them again. */ - public function xmlSerialize(Writer $writer) + public function xmlSerialize(Writer $writer): void { $cs = '{'.Plugin::NS_CALENDARSERVER.'}'; diff --git a/lib/CalDAV/Xml/Property/ScheduleCalendarTransp.php b/lib/CalDAV/Xml/Property/ScheduleCalendarTransp.php index 1595220250..45e290bc01 100644 --- a/lib/CalDAV/Xml/Property/ScheduleCalendarTransp.php +++ b/lib/CalDAV/Xml/Property/ScheduleCalendarTransp.php @@ -77,7 +77,7 @@ public function getValue() * * If you are opening new elements, you must also close them again. */ - public function xmlSerialize(Writer $writer) + public function xmlSerialize(Writer $writer): void { switch ($this->value) { case self::TRANSPARENT: diff --git a/lib/CalDAV/Xml/Property/SupportedCalendarComponentSet.php b/lib/CalDAV/Xml/Property/SupportedCalendarComponentSet.php index d86e7b77c4..3fe03f4f2d 100644 --- a/lib/CalDAV/Xml/Property/SupportedCalendarComponentSet.php +++ b/lib/CalDAV/Xml/Property/SupportedCalendarComponentSet.php @@ -68,7 +68,7 @@ public function getValue() * * If you are opening new elements, you must also close them again. */ - public function xmlSerialize(Writer $writer) + public function xmlSerialize(Writer $writer): void { foreach ($this->components as $component) { $writer->startElement('{'.Plugin::NS_CALDAV.'}comp'); diff --git a/lib/CalDAV/Xml/Property/SupportedCalendarData.php b/lib/CalDAV/Xml/Property/SupportedCalendarData.php index 5b08933058..1ab646d090 100644 --- a/lib/CalDAV/Xml/Property/SupportedCalendarData.php +++ b/lib/CalDAV/Xml/Property/SupportedCalendarData.php @@ -40,7 +40,7 @@ class SupportedCalendarData implements XmlSerializable * * If you are opening new elements, you must also close them again. */ - public function xmlSerialize(Writer $writer) + public function xmlSerialize(Writer $writer): void { $writer->startElement('{'.Plugin::NS_CALDAV.'}calendar-data'); $writer->writeAttributes([ diff --git a/lib/CalDAV/Xml/Property/SupportedCollationSet.php b/lib/CalDAV/Xml/Property/SupportedCollationSet.php index c5ffeee385..af73a02ffc 100644 --- a/lib/CalDAV/Xml/Property/SupportedCollationSet.php +++ b/lib/CalDAV/Xml/Property/SupportedCollationSet.php @@ -39,7 +39,7 @@ class SupportedCollationSet implements XmlSerializable * * If you are opening new elements, you must also close them again. */ - public function xmlSerialize(Writer $writer) + public function xmlSerialize(Writer $writer): void { $collations = [ 'i;ascii-casemap', diff --git a/lib/CardDAV/Xml/Property/SupportedAddressData.php b/lib/CardDAV/Xml/Property/SupportedAddressData.php index fe5f976a03..a912724bf9 100644 --- a/lib/CardDAV/Xml/Property/SupportedAddressData.php +++ b/lib/CardDAV/Xml/Property/SupportedAddressData.php @@ -63,7 +63,7 @@ public function __construct(array $supportedData = null) * * If you are opening new elements, you must also close them again. */ - public function xmlSerialize(Writer $writer) + public function xmlSerialize(Writer $writer): void { foreach ($this->supportedData as $supported) { $writer->startElement('{'.Plugin::NS_CARDDAV.'}address-data-type'); diff --git a/lib/CardDAV/Xml/Property/SupportedCollationSet.php b/lib/CardDAV/Xml/Property/SupportedCollationSet.php index b19eddd9c2..d8ca982aa7 100644 --- a/lib/CardDAV/Xml/Property/SupportedCollationSet.php +++ b/lib/CardDAV/Xml/Property/SupportedCollationSet.php @@ -35,7 +35,7 @@ class SupportedCollationSet implements XmlSerializable * * If you are opening new elements, you must also close them again. */ - public function xmlSerialize(Writer $writer) + public function xmlSerialize(Writer $writer): void { foreach (['i;ascii-casemap', 'i;octet', 'i;unicode-casemap'] as $coll) { $writer->writeElement('{urn:ietf:params:xml:ns:carddav}supported-collation', $coll); diff --git a/lib/DAV/Xml/Element/Response.php b/lib/DAV/Xml/Element/Response.php index df92914650..86f2d33882 100644 --- a/lib/DAV/Xml/Element/Response.php +++ b/lib/DAV/Xml/Element/Response.php @@ -110,7 +110,7 @@ public function getResponseProperties() * Important note 2: If you are writing any new elements, you are also * responsible for closing them. */ - public function xmlSerialize(Writer $writer) + public function xmlSerialize(Writer $writer): void { /* * Accordingly to the RFC the element looks like: diff --git a/lib/DAV/Xml/Element/Sharee.php b/lib/DAV/Xml/Element/Sharee.php index 33564d8f24..79d6aa90db 100644 --- a/lib/DAV/Xml/Element/Sharee.php +++ b/lib/DAV/Xml/Element/Sharee.php @@ -112,7 +112,7 @@ public function __construct(array $properties = []) * * If you are opening new elements, you must also close them again. */ - public function xmlSerialize(Writer $writer) + public function xmlSerialize(Writer $writer): void { $writer->write([ new Href($this->href), diff --git a/lib/DAV/Xml/Property/Complex.php b/lib/DAV/Xml/Property/Complex.php index 787d30d954..9db5ad6790 100644 --- a/lib/DAV/Xml/Property/Complex.php +++ b/lib/DAV/Xml/Property/Complex.php @@ -77,11 +77,9 @@ public static function xmlDeserialize(Reader $reader) $reader->read(); if ($nonText) { - $new = new self($xml); - - return $new; - } else { - return $text; + return new self($xml); } + + return $text; } } diff --git a/lib/DAV/Xml/Property/GetLastModified.php b/lib/DAV/Xml/Property/GetLastModified.php index efc15c293a..0a1b7f800e 100644 --- a/lib/DAV/Xml/Property/GetLastModified.php +++ b/lib/DAV/Xml/Property/GetLastModified.php @@ -69,7 +69,7 @@ public function getTime() * Important note 2: If you are writing any new elements, you are also * responsible for closing them. */ - public function xmlSerialize(Writer $writer) + public function xmlSerialize(Writer $writer): void { $writer->write( HTTP\toDate($this->time) diff --git a/lib/DAV/Xml/Property/Href.php b/lib/DAV/Xml/Property/Href.php index f88ce814ad..898a4e2328 100644 --- a/lib/DAV/Xml/Property/Href.php +++ b/lib/DAV/Xml/Property/Href.php @@ -85,7 +85,7 @@ public function getHrefs() * * If you are opening new elements, you must also close them again. */ - public function xmlSerialize(Writer $writer) + public function xmlSerialize(Writer $writer): void { foreach ($this->getHrefs() as $href) { $href = Uri\resolve($writer->contextUri, $href); diff --git a/lib/DAV/Xml/Property/Invite.php b/lib/DAV/Xml/Property/Invite.php index e3f0a611bf..a6654dd398 100644 --- a/lib/DAV/Xml/Property/Invite.php +++ b/lib/DAV/Xml/Property/Invite.php @@ -57,7 +57,7 @@ public function __construct(array $sharees) * * If you are opening new elements, you must also close them again. */ - public function xmlSerialize(Writer $writer) + public function xmlSerialize(Writer $writer): void { foreach ($this->sharees as $sharee) { $writer->writeElement('{DAV:}sharee', $sharee); diff --git a/lib/DAV/Xml/Property/LockDiscovery.php b/lib/DAV/Xml/Property/LockDiscovery.php index ec4cbc0c6c..7fdc8ef591 100644 --- a/lib/DAV/Xml/Property/LockDiscovery.php +++ b/lib/DAV/Xml/Property/LockDiscovery.php @@ -63,7 +63,7 @@ public function __construct($locks) * Important note 2: If you are writing any new elements, you are also * responsible for closing them. */ - public function xmlSerialize(Writer $writer) + public function xmlSerialize(Writer $writer): void { foreach ($this->locks as $lock) { $writer->startElement('{DAV:}activelock'); diff --git a/lib/DAV/Xml/Property/ShareAccess.php b/lib/DAV/Xml/Property/ShareAccess.php index fdd55558c9..878e3eeca3 100644 --- a/lib/DAV/Xml/Property/ShareAccess.php +++ b/lib/DAV/Xml/Property/ShareAccess.php @@ -72,7 +72,7 @@ public function getValue() * * If you are opening new elements, you must also close them again. */ - public function xmlSerialize(Writer $writer) + public function xmlSerialize(Writer $writer): void { switch ($this->value) { case SharingPlugin::ACCESS_NOTSHARED: diff --git a/lib/DAV/Xml/Property/SupportedLock.php b/lib/DAV/Xml/Property/SupportedLock.php index 100829c60a..fcbe2fa459 100644 --- a/lib/DAV/Xml/Property/SupportedLock.php +++ b/lib/DAV/Xml/Property/SupportedLock.php @@ -38,7 +38,7 @@ class SupportedLock implements XmlSerializable * * If you are opening new elements, you must also close them again. */ - public function xmlSerialize(Writer $writer) + public function xmlSerialize(Writer $writer): void { $writer->writeElement('{DAV:}lockentry', [ '{DAV:}lockscope' => ['{DAV:}exclusive' => null], diff --git a/lib/DAV/Xml/Property/SupportedMethodSet.php b/lib/DAV/Xml/Property/SupportedMethodSet.php index 6344010932..95d2c29ac6 100644 --- a/lib/DAV/Xml/Property/SupportedMethodSet.php +++ b/lib/DAV/Xml/Property/SupportedMethodSet.php @@ -82,7 +82,7 @@ public function has($methodName) * * If you are opening new elements, you must also close them again. */ - public function xmlSerialize(Writer $writer) + public function xmlSerialize(Writer $writer): void { foreach ($this->getValue() as $val) { $writer->startElement('{DAV:}supported-method'); diff --git a/lib/DAV/Xml/Property/SupportedReportSet.php b/lib/DAV/Xml/Property/SupportedReportSet.php index 0b4990e961..35e1614423 100644 --- a/lib/DAV/Xml/Property/SupportedReportSet.php +++ b/lib/DAV/Xml/Property/SupportedReportSet.php @@ -110,7 +110,7 @@ public function has($reportName) * * If you are opening new elements, you must also close them again. */ - public function xmlSerialize(Writer $writer) + public function xmlSerialize(Writer $writer): void { foreach ($this->getValue() as $val) { $writer->startElement('{DAV:}supported-report'); diff --git a/lib/DAV/Xml/Request/PropPatch.php b/lib/DAV/Xml/Request/PropPatch.php index 4a27095025..c1ed0d3afe 100644 --- a/lib/DAV/Xml/Request/PropPatch.php +++ b/lib/DAV/Xml/Request/PropPatch.php @@ -46,10 +46,10 @@ class PropPatch implements Element * * If you are opening new elements, you must also close them again. */ - public function xmlSerialize(Writer $writer) + public function xmlSerialize(Writer $writer): void { foreach ($this->properties as $propertyName => $propertyValue) { - if (is_null($propertyValue)) { + if (null === $propertyValue) { $writer->startElement('{DAV:}remove'); $writer->write(['{DAV:}prop' => [$propertyName => $propertyValue]]); $writer->endElement(); diff --git a/lib/DAV/Xml/Response/MultiStatus.php b/lib/DAV/Xml/Response/MultiStatus.php index e824cda429..8f9d45c80f 100644 --- a/lib/DAV/Xml/Response/MultiStatus.php +++ b/lib/DAV/Xml/Response/MultiStatus.php @@ -81,7 +81,7 @@ public function getSyncToken() * Important note 2: If you are writing any new elements, you are also * responsible for closing them. */ - public function xmlSerialize(Writer $writer) + public function xmlSerialize(Writer $writer): void { foreach ($this->getResponses() as $response) { $writer->writeElement('{DAV:}response', $response); diff --git a/lib/DAV/Xml/Service.php b/lib/DAV/Xml/Service.php index 4406b022d0..e718606b96 100644 --- a/lib/DAV/Xml/Service.php +++ b/lib/DAV/Xml/Service.php @@ -19,7 +19,7 @@ class Service extends \Sabre\Xml\Service * For instance, this list may contain an entry `{DAV:}propfind` that would * be mapped to Sabre\DAV\Xml\Request\PropFind */ - public $elementMap = [ + public array $elementMap = [ '{DAV:}multistatus' => 'Sabre\\DAV\\Xml\\Response\\MultiStatus', '{DAV:}response' => 'Sabre\\DAV\\Xml\\Element\\Response', @@ -37,10 +37,8 @@ class Service extends \Sabre\Xml\Service * * If you are defining your own custom namespace, add it here to reduce * bandwidth and improve legibility of xml bodies. - * - * @var array */ - public $namespaceMap = [ + public array $namespaceMap = [ 'DAV:' => 'd', 'http://sabredav.org/ns' => 's', ]; diff --git a/lib/DAVACL/Xml/Property/Acl.php b/lib/DAVACL/Xml/Property/Acl.php index c6e236dc59..086d123037 100644 --- a/lib/DAVACL/Xml/Property/Acl.php +++ b/lib/DAVACL/Xml/Property/Acl.php @@ -92,7 +92,7 @@ public function getPrivileges() * * If you are opening new elements, you must also close them again. */ - public function xmlSerialize(Writer $writer) + public function xmlSerialize(Writer $writer): void { foreach ($this->privileges as $ace) { $this->serializeAce($writer, $ace); diff --git a/lib/DAVACL/Xml/Property/AclRestrictions.php b/lib/DAVACL/Xml/Property/AclRestrictions.php index b5629c8096..f93f415a24 100644 --- a/lib/DAVACL/Xml/Property/AclRestrictions.php +++ b/lib/DAVACL/Xml/Property/AclRestrictions.php @@ -34,7 +34,7 @@ class AclRestrictions implements XmlSerializable * * If you are opening new elements, you must also close them again. */ - public function xmlSerialize(Writer $writer) + public function xmlSerialize(Writer $writer): void { $writer->writeElement('{DAV:}grant-only'); $writer->writeElement('{DAV:}no-invert'); diff --git a/lib/DAVACL/Xml/Property/CurrentUserPrivilegeSet.php b/lib/DAVACL/Xml/Property/CurrentUserPrivilegeSet.php index e38a45c61e..4a7ad25b48 100644 --- a/lib/DAVACL/Xml/Property/CurrentUserPrivilegeSet.php +++ b/lib/DAVACL/Xml/Property/CurrentUserPrivilegeSet.php @@ -55,7 +55,7 @@ public function __construct(array $privileges) * * If you are opening new elements, you must also close them again. */ - public function xmlSerialize(Writer $writer) + public function xmlSerialize(Writer $writer): void { foreach ($this->privileges as $privName) { $writer->startElement('{DAV:}privilege'); diff --git a/lib/DAVACL/Xml/Property/Principal.php b/lib/DAVACL/Xml/Property/Principal.php index 52092128f3..e19ad61744 100644 --- a/lib/DAVACL/Xml/Property/Principal.php +++ b/lib/DAVACL/Xml/Property/Principal.php @@ -99,7 +99,7 @@ public function getType() * * If you are opening new elements, you must also close them again. */ - public function xmlSerialize(Writer $writer) + public function xmlSerialize(Writer $writer): void { switch ($this->type) { case self::UNAUTHENTICATED: diff --git a/lib/DAVACL/Xml/Property/SupportedPrivilegeSet.php b/lib/DAVACL/Xml/Property/SupportedPrivilegeSet.php index 6e7514bd95..b965f3c078 100644 --- a/lib/DAVACL/Xml/Property/SupportedPrivilegeSet.php +++ b/lib/DAVACL/Xml/Property/SupportedPrivilegeSet.php @@ -66,7 +66,7 @@ public function getValue() * * If you are opening new elements, you must also close them again. */ - public function xmlSerialize(Writer $writer) + public function xmlSerialize(Writer $writer): void { $this->serializePriv($writer, '{DAV:}all', ['aggregates' => $this->privileges]); } diff --git a/tests/Sabre/CalDAV/Backend/SimplePDOTest.php b/tests/Sabre/CalDAV/Backend/SimplePDOTest.php index 932c975236..cb1bd8efec 100644 --- a/tests/Sabre/CalDAV/Backend/SimplePDOTest.php +++ b/tests/Sabre/CalDAV/Backend/SimplePDOTest.php @@ -13,15 +13,11 @@ class SimplePDOTest extends \PHPUnit\Framework\TestCase public function setup(): void { - if (!SABRE_HASSQLITE) { - $this->markTestSkipped('SQLite driver is not available'); + if (file_exists(\Sabre\TestUtil::SABRE_TEMPDIR.'/testdb.sqlite')) { + unlink(\Sabre\TestUtil::SABRE_TEMPDIR.'/testdb.sqlite'); } - if (file_exists(SABRE_TEMPDIR.'/testdb.sqlite')) { - unlink(SABRE_TEMPDIR.'/testdb.sqlite'); - } - - $pdo = new \PDO('sqlite:'.SABRE_TEMPDIR.'/testdb.sqlite'); + $pdo = new \PDO('sqlite:'.\Sabre\TestUtil::SABRE_TEMPDIR.'/testdb.sqlite'); $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $pdo->exec(<<markTestSkipped('SQLite driver is not available'); - } $this->backend = new Backend\MockScheduling(); $this->data = <<server->sapi = new HTTP\SapiMock(); $this->server->httpResponse = $this->response; $this->server->debugExceptions = true; - $this->deleteTree(SABRE_TEMPDIR, false); - file_put_contents(SABRE_TEMPDIR.'/test.txt', 'Test contents'); - mkdir(SABRE_TEMPDIR.'/dir'); - file_put_contents(SABRE_TEMPDIR.'/dir/child.txt', 'Child contents'); + $this->deleteTree(\Sabre\TestUtil::SABRE_TEMPDIR, false); + file_put_contents(\Sabre\TestUtil::SABRE_TEMPDIR.'/test.txt', 'Test contents'); + mkdir(\Sabre\TestUtil::SABRE_TEMPDIR.'/dir'); + file_put_contents(\Sabre\TestUtil::SABRE_TEMPDIR.'/dir/child.txt', 'Child contents'); } public function teardown(): void { - $this->deleteTree(SABRE_TEMPDIR, false); + $this->deleteTree(\Sabre\TestUtil::SABRE_TEMPDIR, false); } protected function getRootNode() { - return new FS\Directory(SABRE_TEMPDIR); + return new FS\Directory(\Sabre\TestUtil::SABRE_TEMPDIR); } protected function getSanitizedBody() diff --git a/tests/Sabre/DAV/Auth/Backend/FileTest.php b/tests/Sabre/DAV/Auth/Backend/FileTest.php index 956768835f..46b253c79f 100644 --- a/tests/Sabre/DAV/Auth/Backend/FileTest.php +++ b/tests/Sabre/DAV/Auth/Backend/FileTest.php @@ -8,8 +8,8 @@ class FileTest extends \PHPUnit\Framework\TestCase { public function teardown(): void { - if (file_exists(SABRE_TEMPDIR.'/filebackend')) { - unlink(SABRE_TEMPDIR.'/filebackend'); + if (file_exists(\Sabre\TestUtil::SABRE_TEMPDIR.'/filebackend')) { + unlink(\Sabre\TestUtil::SABRE_TEMPDIR.'/filebackend'); } } @@ -22,15 +22,15 @@ public function testConstruct() public function testLoadFileBroken() { $this->expectException('Sabre\DAV\Exception'); - file_put_contents(SABRE_TEMPDIR.'/backend', 'user:realm:hash'); - $file = new File(SABRE_TEMPDIR.'/backend'); + file_put_contents(\Sabre\TestUtil::SABRE_TEMPDIR.'/backend', 'user:realm:hash'); + $file = new File(\Sabre\TestUtil::SABRE_TEMPDIR.'/backend'); } public function testLoadFile() { - file_put_contents(SABRE_TEMPDIR.'/backend', 'user:realm:'.md5('user:realm:password')); + file_put_contents(\Sabre\TestUtil::SABRE_TEMPDIR.'/backend', 'user:realm:'.md5('user:realm:password')); $file = new File(); - $file->loadFile(SABRE_TEMPDIR.'/backend'); + $file->loadFile(\Sabre\TestUtil::SABRE_TEMPDIR.'/backend'); self::assertFalse($file->getDigestHash('realm', 'blabla')); self::assertEquals(md5('user:realm:password'), $file->getDigestHash('realm', 'user')); diff --git a/tests/Sabre/DAV/Browser/GuessContentTypeTest.php b/tests/Sabre/DAV/Browser/GuessContentTypeTest.php index e856127bb8..3da77f8b33 100644 --- a/tests/Sabre/DAV/Browser/GuessContentTypeTest.php +++ b/tests/Sabre/DAV/Browser/GuessContentTypeTest.php @@ -12,8 +12,8 @@ public function setUp(): void { parent::setUp(); \Sabre\TestUtil::clearTempDir(); - file_put_contents(SABRE_TEMPDIR.'/somefile.jpg', 'blabla'); - file_put_contents(SABRE_TEMPDIR.'/somefile.hoi', 'blabla'); + file_put_contents(\Sabre\TestUtil::SABRE_TEMPDIR.'/somefile.jpg', 'blabla'); + file_put_contents(\Sabre\TestUtil::SABRE_TEMPDIR.'/somefile.hoi', 'blabla'); } public function tearDown(): void diff --git a/tests/Sabre/DAV/Browser/PluginTest.php b/tests/Sabre/DAV/Browser/PluginTest.php index ead458e27e..9e2cfd692e 100644 --- a/tests/Sabre/DAV/Browser/PluginTest.php +++ b/tests/Sabre/DAV/Browser/PluginTest.php @@ -146,7 +146,7 @@ public function testPostMkCol() 'Location' => ['/'], ], $this->response->getHeaders()); - self::assertTrue(is_dir(SABRE_TEMPDIR.'/new_collection')); + self::assertTrue(is_dir(\Sabre\TestUtil::SABRE_TEMPDIR.'/new_collection')); } public function testGetAsset() diff --git a/tests/Sabre/DAV/ClientMock.php b/tests/Sabre/DAV/ClientMock.php index 7d787744a1..ab4675f8b9 100644 --- a/tests/Sabre/DAV/ClientMock.php +++ b/tests/Sabre/DAV/ClientMock.php @@ -13,7 +13,7 @@ class ClientMock extends Client public $response; public $url; - public $curlSettings; + public array $curlSettings; /** * Just making this method public. diff --git a/tests/Sabre/DAV/DbTestHelperTrait.php b/tests/Sabre/DAV/DbTestHelperTrait.php index 007a40f924..6fee5e2f94 100644 --- a/tests/Sabre/DAV/DbTestHelperTrait.php +++ b/tests/Sabre/DAV/DbTestHelperTrait.php @@ -6,6 +6,7 @@ use PDO; use PDOException; +use Sabre\TestUtil; class DbCache { @@ -44,13 +45,16 @@ public function getDb() try { switch ($this->driver) { case 'mysql': - $pdo = new PDO(SABRE_MYSQLDSN, SABRE_MYSQLUSER, SABRE_MYSQLPASS); + $dsn = getenv('SABRE_MYSQLDSN'); + $user = getenv('SABRE_MYSQLUSER'); + $pass = getenv('SABRE_MYSQLPASS'); + $pdo = new PDO($dsn, $user, $pass); break; case 'sqlite': - $pdo = new \PDO('sqlite:'.SABRE_TEMPDIR.'/testdb'); + $pdo = new PDO('sqlite:'.TestUtil::SABRE_TEMPDIR.'/testdb'); break; case 'pgsql': - $pdo = new \PDO(SABRE_PGSQLDSN); + $pdo = new PDO(getenv('SABRE_PGSQLDSN')); $version = $pdo->query('SELECT VERSION()')->fetchColumn(); preg_match('|([0-9\.]){5,}|', $version, $matches); $version = $matches[0]; @@ -65,7 +69,7 @@ public function getDb() $this->markTestSkipped($this->driver.' was not recognised'); } - $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); + $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { $this->markTestSkipped($this->driver.' was not enabled or not correctly configured. Error message: '.$e->getMessage()); } @@ -127,7 +131,7 @@ public function tearDown(): void case 'sqlite': // Recreating sqlite, just in case unset(DbCache::$cache[$this->driver]); - unlink(SABRE_TEMPDIR.'/testdb'); + unlink(TestUtil::SABRE_TEMPDIR.'/testdb'); } } } diff --git a/tests/Sabre/DAV/FSExt/DirectoryTest.php b/tests/Sabre/DAV/FSExt/DirectoryTest.php index 5c9efc8e08..aecd9580f5 100644 --- a/tests/Sabre/DAV/FSExt/DirectoryTest.php +++ b/tests/Sabre/DAV/FSExt/DirectoryTest.php @@ -8,13 +8,13 @@ class DirectoryTest extends \PHPUnit\Framework\TestCase { public function create() { - return new Directory(SABRE_TEMPDIR); + return new Directory(\Sabre\TestUtil::SABRE_TEMPDIR); } public function testCreate() { $dir = $this->create(); - self::assertEquals(basename(SABRE_TEMPDIR), $dir->getName()); + self::assertEquals(basename(\Sabre\TestUtil::SABRE_TEMPDIR), $dir->getName()); } public function testChildExistDot() diff --git a/tests/Sabre/DAV/FSExt/FileTest.php b/tests/Sabre/DAV/FSExt/FileTest.php index c5aa82b577..db050b2f39 100644 --- a/tests/Sabre/DAV/FSExt/FileTest.php +++ b/tests/Sabre/DAV/FSExt/FileTest.php @@ -8,7 +8,7 @@ class FileTest extends \PHPUnit\Framework\TestCase { public function setup(): void { - file_put_contents(SABRE_TEMPDIR.'/file.txt', 'Contents'); + file_put_contents(\Sabre\TestUtil::SABRE_TEMPDIR.'/file.txt', 'Contents'); } public function teardown(): void @@ -18,11 +18,11 @@ public function teardown(): void public function testPut() { - $filename = SABRE_TEMPDIR.'/file.txt'; + $filename = \Sabre\TestUtil::SABRE_TEMPDIR.'/file.txt'; $file = new File($filename); $result = $file->put('New contents'); - self::assertEquals('New contents', file_get_contents(SABRE_TEMPDIR.'/file.txt')); + self::assertEquals('New contents', file_get_contents(\Sabre\TestUtil::SABRE_TEMPDIR.'/file.txt')); self::assertEquals( '"'. sha1( @@ -36,38 +36,38 @@ public function testPut() public function testRangeAppend() { - $file = new File(SABRE_TEMPDIR.'/file.txt'); + $file = new File(\Sabre\TestUtil::SABRE_TEMPDIR.'/file.txt'); $file->put('0000000'); $file->patch('111', 1); - self::assertEquals('0000000111', file_get_contents(SABRE_TEMPDIR.'/file.txt')); + self::assertEquals('0000000111', file_get_contents(\Sabre\TestUtil::SABRE_TEMPDIR.'/file.txt')); } public function testRangeOffset() { - $file = new File(SABRE_TEMPDIR.'/file.txt'); + $file = new File(\Sabre\TestUtil::SABRE_TEMPDIR.'/file.txt'); $file->put('0000000'); $file->patch('111', 2, 3); - self::assertEquals('0001110', file_get_contents(SABRE_TEMPDIR.'/file.txt')); + self::assertEquals('0001110', file_get_contents(\Sabre\TestUtil::SABRE_TEMPDIR.'/file.txt')); } public function testRangeOffsetEnd() { - $file = new File(SABRE_TEMPDIR.'/file.txt'); + $file = new File(\Sabre\TestUtil::SABRE_TEMPDIR.'/file.txt'); $file->put('0000000'); $file->patch('11', 3, -4); - self::assertEquals('0001100', file_get_contents(SABRE_TEMPDIR.'/file.txt')); + self::assertEquals('0001100', file_get_contents(\Sabre\TestUtil::SABRE_TEMPDIR.'/file.txt')); } public function testRangeOffsetDefault() { - $file = new File(SABRE_TEMPDIR.'/file.txt'); + $file = new File(\Sabre\TestUtil::SABRE_TEMPDIR.'/file.txt'); $file->put('0000000'); $file->patch('11', 0); - self::assertEquals('000000011', file_get_contents(SABRE_TEMPDIR.'/file.txt')); + self::assertEquals('000000011', file_get_contents(\Sabre\TestUtil::SABRE_TEMPDIR.'/file.txt')); } public function testRangeStream() @@ -76,30 +76,30 @@ public function testRangeStream() fwrite($stream, '222'); rewind($stream); - $file = new File(SABRE_TEMPDIR.'/file.txt'); + $file = new File(\Sabre\TestUtil::SABRE_TEMPDIR.'/file.txt'); $file->put('0000000'); $file->patch($stream, 2, 3); - self::assertEquals('0002220', file_get_contents(SABRE_TEMPDIR.'/file.txt')); + self::assertEquals('0002220', file_get_contents(\Sabre\TestUtil::SABRE_TEMPDIR.'/file.txt')); } public function testGet() { - $file = new File(SABRE_TEMPDIR.'/file.txt'); + $file = new File(\Sabre\TestUtil::SABRE_TEMPDIR.'/file.txt'); self::assertEquals('Contents', stream_get_contents($file->get())); } public function testDelete() { - $file = new File(SABRE_TEMPDIR.'/file.txt'); + $file = new File(\Sabre\TestUtil::SABRE_TEMPDIR.'/file.txt'); $file->delete(); - self::assertFalse(file_exists(SABRE_TEMPDIR.'/file.txt')); + self::assertFalse(file_exists(\Sabre\TestUtil::SABRE_TEMPDIR.'/file.txt')); } public function testGetETag() { - $filename = SABRE_TEMPDIR.'/file.txt'; + $filename = \Sabre\TestUtil::SABRE_TEMPDIR.'/file.txt'; $file = new File($filename); self::assertEquals( '"'. @@ -114,13 +114,13 @@ public function testGetETag() public function testGetContentType() { - $file = new File(SABRE_TEMPDIR.'/file.txt'); + $file = new File(\Sabre\TestUtil::SABRE_TEMPDIR.'/file.txt'); self::assertNull($file->getContentType()); } public function testGetSize() { - $file = new File(SABRE_TEMPDIR.'/file.txt'); + $file = new File(\Sabre\TestUtil::SABRE_TEMPDIR.'/file.txt'); self::assertEquals(8, $file->getSize()); } } diff --git a/tests/Sabre/DAV/Issue33Test.php b/tests/Sabre/DAV/Issue33Test.php index 6bdb68b2d9..f9598f1529 100644 --- a/tests/Sabre/DAV/Issue33Test.php +++ b/tests/Sabre/DAV/Issue33Test.php @@ -37,8 +37,8 @@ public function testCopyMoveInfo() public function testTreeMove() { - mkdir(SABRE_TEMPDIR.'/issue33'); - $dir = new FS\Directory(SABRE_TEMPDIR.'/issue33'); + mkdir(\Sabre\TestUtil::SABRE_TEMPDIR.'/issue33'); + $dir = new FS\Directory(\Sabre\TestUtil::SABRE_TEMPDIR.'/issue33'); $dir->createDirectory('bar'); @@ -73,8 +73,8 @@ public function testEverything() $response = new HTTP\ResponseMock(); // Server setup - mkdir(SABRE_TEMPDIR.'/issue33'); - $dir = new FS\Directory(SABRE_TEMPDIR.'/issue33'); + mkdir(\Sabre\TestUtil::SABRE_TEMPDIR.'/issue33'); + $dir = new FS\Directory(\Sabre\TestUtil::SABRE_TEMPDIR.'/issue33'); $dir->createDirectory('bar'); @@ -88,6 +88,6 @@ public function testEverything() $server->sapi = new HTTP\SapiMock(); $server->exec(); - self::assertTrue(file_exists(SABRE_TEMPDIR.'/issue33/'.urldecode('%C3%A0fo%C3%B3'))); + self::assertTrue(file_exists(\Sabre\TestUtil::SABRE_TEMPDIR.'/issue33/'.urldecode('%C3%A0fo%C3%B3'))); } } diff --git a/tests/Sabre/DAV/Locks/Backend/FileTest.php b/tests/Sabre/DAV/Locks/Backend/FileTest.php index 57a3255c71..f96c09e282 100644 --- a/tests/Sabre/DAV/Locks/Backend/FileTest.php +++ b/tests/Sabre/DAV/Locks/Backend/FileTest.php @@ -9,7 +9,7 @@ class FileTest extends AbstractTest public function getBackend() { \Sabre\TestUtil::clearTempDir(); - $backend = new File(SABRE_TEMPDIR.'/lockdb'); + $backend = new File(\Sabre\TestUtil::SABRE_TEMPDIR.'/lockdb'); return $backend; } diff --git a/tests/Sabre/DAV/Locks/MSWordTest.php b/tests/Sabre/DAV/Locks/MSWordTest.php index d16782322e..2fb9aeb2e7 100644 --- a/tests/Sabre/DAV/Locks/MSWordTest.php +++ b/tests/Sabre/DAV/Locks/MSWordTest.php @@ -16,12 +16,12 @@ public function teardown(): void public function testLockEtc() { - mkdir(SABRE_TEMPDIR.'/mstest'); - $tree = new DAV\FS\Directory(SABRE_TEMPDIR.'/mstest'); + mkdir(\Sabre\TestUtil::SABRE_TEMPDIR.'/mstest'); + $tree = new DAV\FS\Directory(\Sabre\TestUtil::SABRE_TEMPDIR.'/mstest'); $server = new DAV\Server($tree); $server->debugExceptions = true; - $locksBackend = new Backend\File(SABRE_TEMPDIR.'/locksdb'); + $locksBackend = new Backend\File(\Sabre\TestUtil::SABRE_TEMPDIR.'/locksdb'); $locksPlugin = new Plugin($locksBackend); $server->addPlugin($locksPlugin); diff --git a/tests/Sabre/DAV/Locks/Plugin2Test.php b/tests/Sabre/DAV/Locks/Plugin2Test.php index ddd634c234..9548363e9d 100644 --- a/tests/Sabre/DAV/Locks/Plugin2Test.php +++ b/tests/Sabre/DAV/Locks/Plugin2Test.php @@ -12,7 +12,7 @@ class Plugin2Test extends \Sabre\DAVServerTest public function setUpTree() { - $this->tree = new \Sabre\DAV\FS\Directory(SABRE_TEMPDIR); + $this->tree = new \Sabre\DAV\FS\Directory(\Sabre\TestUtil::SABRE_TEMPDIR); } public function teardown(): void diff --git a/tests/Sabre/DAV/Locks/PluginTest.php b/tests/Sabre/DAV/Locks/PluginTest.php index fbfb758557..70530d2f53 100644 --- a/tests/Sabre/DAV/Locks/PluginTest.php +++ b/tests/Sabre/DAV/Locks/PluginTest.php @@ -17,7 +17,7 @@ class PluginTest extends DAV\AbstractServer public function setup(): void { parent::setUp(); - $locksBackend = new Backend\File(SABRE_TEMPDIR.'/locksdb'); + $locksBackend = new Backend\File(\Sabre\TestUtil::SABRE_TEMPDIR.'/locksdb'); $locksPlugin = new Plugin($locksBackend); $this->server->addPlugin($locksPlugin); $this->locksPlugin = $locksPlugin; @@ -853,10 +853,10 @@ public function testPutWithIncorrectETag() public function testPutWithCorrectETag() { // We need an ETag-enabled file node. - $tree = new DAV\Tree(new DAV\FSExt\Directory(SABRE_TEMPDIR)); + $tree = new DAV\Tree(new DAV\FSExt\Directory(\Sabre\TestUtil::SABRE_TEMPDIR)); $this->server->tree = $tree; - $filename = SABRE_TEMPDIR.'/test.txt'; + $filename = \Sabre\TestUtil::SABRE_TEMPDIR.'/test.txt'; $etag = sha1( fileinode($filename). filesize($filename). diff --git a/tests/Sabre/DAV/ObjectTreeTest.php b/tests/Sabre/DAV/ObjectTreeTest.php index 6173e54247..682a8c38cd 100644 --- a/tests/Sabre/DAV/ObjectTreeTest.php +++ b/tests/Sabre/DAV/ObjectTreeTest.php @@ -11,11 +11,11 @@ class ObjectTreeTest extends \PHPUnit\Framework\TestCase public function setup(): void { \Sabre\TestUtil::clearTempDir(); - mkdir(SABRE_TEMPDIR.'/root'); - mkdir(SABRE_TEMPDIR.'/root/subdir'); - file_put_contents(SABRE_TEMPDIR.'/root/file.txt', 'contents'); - file_put_contents(SABRE_TEMPDIR.'/root/subdir/subfile.txt', 'subcontents'); - $rootNode = new FSExt\Directory(SABRE_TEMPDIR.'/root'); + mkdir(\Sabre\TestUtil::SABRE_TEMPDIR.'/root'); + mkdir(\Sabre\TestUtil::SABRE_TEMPDIR.'/root/subdir'); + file_put_contents(\Sabre\TestUtil::SABRE_TEMPDIR.'/root/file.txt', 'contents'); + file_put_contents(\Sabre\TestUtil::SABRE_TEMPDIR.'/root/subdir/subfile.txt', 'subcontents'); + $rootNode = new FSExt\Directory(\Sabre\TestUtil::SABRE_TEMPDIR.'/root'); $this->tree = new Tree($rootNode); } @@ -39,8 +39,8 @@ public function testGetSubDir() public function testCopyFile() { $this->tree->copy('file.txt', 'file2.txt'); - self::assertTrue(file_exists(SABRE_TEMPDIR.'/root/file2.txt')); - self::assertEquals('contents', file_get_contents(SABRE_TEMPDIR.'/root/file2.txt')); + self::assertTrue(file_exists(\Sabre\TestUtil::SABRE_TEMPDIR.'/root/file2.txt')); + self::assertEquals('contents', file_get_contents(\Sabre\TestUtil::SABRE_TEMPDIR.'/root/file2.txt')); } /** @@ -49,9 +49,9 @@ public function testCopyFile() public function testCopyDirectory() { $this->tree->copy('subdir', 'subdir2'); - self::assertTrue(file_exists(SABRE_TEMPDIR.'/root/subdir2')); - self::assertTrue(file_exists(SABRE_TEMPDIR.'/root/subdir2/subfile.txt')); - self::assertEquals('subcontents', file_get_contents(SABRE_TEMPDIR.'/root/subdir2/subfile.txt')); + self::assertTrue(file_exists(\Sabre\TestUtil::SABRE_TEMPDIR.'/root/subdir2')); + self::assertTrue(file_exists(\Sabre\TestUtil::SABRE_TEMPDIR.'/root/subdir2/subfile.txt')); + self::assertEquals('subcontents', file_get_contents(\Sabre\TestUtil::SABRE_TEMPDIR.'/root/subdir2/subfile.txt')); } /** @@ -60,9 +60,9 @@ public function testCopyDirectory() public function testMoveFile() { $this->tree->move('file.txt', 'file2.txt'); - self::assertTrue(file_exists(SABRE_TEMPDIR.'/root/file2.txt')); - self::assertFalse(file_exists(SABRE_TEMPDIR.'/root/file.txt')); - self::assertEquals('contents', file_get_contents(SABRE_TEMPDIR.'/root/file2.txt')); + self::assertTrue(file_exists(\Sabre\TestUtil::SABRE_TEMPDIR.'/root/file2.txt')); + self::assertFalse(file_exists(\Sabre\TestUtil::SABRE_TEMPDIR.'/root/file.txt')); + self::assertEquals('contents', file_get_contents(\Sabre\TestUtil::SABRE_TEMPDIR.'/root/file2.txt')); } /** @@ -71,9 +71,9 @@ public function testMoveFile() public function testMoveFileNewParent() { $this->tree->move('file.txt', 'subdir/file2.txt'); - self::assertTrue(file_exists(SABRE_TEMPDIR.'/root/subdir/file2.txt')); - self::assertFalse(file_exists(SABRE_TEMPDIR.'/root/file.txt')); - self::assertEquals('contents', file_get_contents(SABRE_TEMPDIR.'/root/subdir/file2.txt')); + self::assertTrue(file_exists(\Sabre\TestUtil::SABRE_TEMPDIR.'/root/subdir/file2.txt')); + self::assertFalse(file_exists(\Sabre\TestUtil::SABRE_TEMPDIR.'/root/file.txt')); + self::assertEquals('contents', file_get_contents(\Sabre\TestUtil::SABRE_TEMPDIR.'/root/subdir/file2.txt')); } /** @@ -82,9 +82,9 @@ public function testMoveFileNewParent() public function testMoveDirectory() { $this->tree->move('subdir', 'subdir2'); - self::assertTrue(file_exists(SABRE_TEMPDIR.'/root/subdir2')); - self::assertTrue(file_exists(SABRE_TEMPDIR.'/root/subdir2/subfile.txt')); - self::assertFalse(file_exists(SABRE_TEMPDIR.'/root/subdir')); - self::assertEquals('subcontents', file_get_contents(SABRE_TEMPDIR.'/root/subdir2/subfile.txt')); + self::assertTrue(file_exists(\Sabre\TestUtil::SABRE_TEMPDIR.'/root/subdir2')); + self::assertTrue(file_exists(\Sabre\TestUtil::SABRE_TEMPDIR.'/root/subdir2/subfile.txt')); + self::assertFalse(file_exists(\Sabre\TestUtil::SABRE_TEMPDIR.'/root/subdir')); + self::assertEquals('subcontents', file_get_contents(\Sabre\TestUtil::SABRE_TEMPDIR.'/root/subdir2/subfile.txt')); } } diff --git a/tests/Sabre/DAV/PartialUpdate/SpecificationTest.php b/tests/Sabre/DAV/PartialUpdate/SpecificationTest.php index 48e6c91490..f92c475071 100644 --- a/tests/Sabre/DAV/PartialUpdate/SpecificationTest.php +++ b/tests/Sabre/DAV/PartialUpdate/SpecificationTest.php @@ -21,7 +21,7 @@ class SpecificationTest extends \PHPUnit\Framework\TestCase public function setup(): void { $tree = [ - new File(SABRE_TEMPDIR.'/foobar.txt'), + new File(\Sabre\TestUtil::SABRE_TEMPDIR.'/foobar.txt'), ]; $server = new Server($tree); $server->debugExceptions = true; @@ -66,7 +66,7 @@ public function testUpdateRange($headerValue, $httpStatus, $endResult, $contentL self::assertEquals($httpStatus, $this->server->httpResponse->status, 'Incorrect http status received: '.$this->server->httpResponse->body); if (!is_null($endResult)) { - self::assertEquals($endResult, file_get_contents(SABRE_TEMPDIR.'/foobar.txt')); + self::assertEquals($endResult, file_get_contents(\Sabre\TestUtil::SABRE_TEMPDIR.'/foobar.txt')); } } diff --git a/tests/Sabre/DAV/ServerPropsInfiniteDepthTest.php b/tests/Sabre/DAV/ServerPropsInfiniteDepthTest.php index 6e4cd900a2..db28680816 100644 --- a/tests/Sabre/DAV/ServerPropsInfiniteDepthTest.php +++ b/tests/Sabre/DAV/ServerPropsInfiniteDepthTest.php @@ -10,28 +10,28 @@ class ServerPropsInfiniteDepthTest extends AbstractServer { protected function getRootNode() { - return new FSExt\Directory(SABRE_TEMPDIR); + return new FSExt\Directory(\Sabre\TestUtil::SABRE_TEMPDIR); } public function setup(): void { - if (file_exists(SABRE_TEMPDIR.'../.sabredav')) { - unlink(SABRE_TEMPDIR.'../.sabredav'); + if (file_exists(\Sabre\TestUtil::SABRE_TEMPDIR.'../.sabredav')) { + unlink(\Sabre\TestUtil::SABRE_TEMPDIR.'../.sabredav'); } parent::setUp(); - file_put_contents(SABRE_TEMPDIR.'/test2.txt', 'Test contents2'); - mkdir(SABRE_TEMPDIR.'/col'); - mkdir(SABRE_TEMPDIR.'/col/col'); - file_put_contents(SABRE_TEMPDIR.'col/col/test.txt', 'Test contents'); - $this->server->addPlugin(new Locks\Plugin(new Locks\Backend\File(SABRE_TEMPDIR.'/.locksdb'))); + file_put_contents(\Sabre\TestUtil::SABRE_TEMPDIR.'/test2.txt', 'Test contents2'); + mkdir(\Sabre\TestUtil::SABRE_TEMPDIR.'/col'); + mkdir(\Sabre\TestUtil::SABRE_TEMPDIR.'/col/col'); + file_put_contents(\Sabre\TestUtil::SABRE_TEMPDIR.'col/col/test.txt', 'Test contents'); + $this->server->addPlugin(new Locks\Plugin(new Locks\Backend\File(\Sabre\TestUtil::SABRE_TEMPDIR.'/.locksdb'))); $this->server->enablePropfindDepthInfinity = true; } public function teardown(): void { parent::tearDown(); - if (file_exists(SABRE_TEMPDIR.'../.locksdb')) { - unlink(SABRE_TEMPDIR.'../.locksdb'); + if (file_exists(\Sabre\TestUtil::SABRE_TEMPDIR.'../.locksdb')) { + unlink(\Sabre\TestUtil::SABRE_TEMPDIR.'../.locksdb'); } } diff --git a/tests/Sabre/DAV/ServerPropsTest.php b/tests/Sabre/DAV/ServerPropsTest.php index 82338c2a54..6f4626f0fd 100644 --- a/tests/Sabre/DAV/ServerPropsTest.php +++ b/tests/Sabre/DAV/ServerPropsTest.php @@ -10,26 +10,26 @@ class ServerPropsTest extends AbstractServer { protected function getRootNode() { - return new FSExt\Directory(SABRE_TEMPDIR); + return new FSExt\Directory(\Sabre\TestUtil::SABRE_TEMPDIR); } public function setup(): void { - if (file_exists(SABRE_TEMPDIR.'../.sabredav')) { - unlink(SABRE_TEMPDIR.'../.sabredav'); + if (file_exists(\Sabre\TestUtil::SABRE_TEMPDIR.'../.sabredav')) { + unlink(\Sabre\TestUtil::SABRE_TEMPDIR.'../.sabredav'); } parent::setUp(); - file_put_contents(SABRE_TEMPDIR.'/test2.txt', 'Test contents2'); - mkdir(SABRE_TEMPDIR.'/col'); - file_put_contents(SABRE_TEMPDIR.'col/test.txt', 'Test contents'); - $this->server->addPlugin(new Locks\Plugin(new Locks\Backend\File(SABRE_TEMPDIR.'/.locksdb'))); + file_put_contents(\Sabre\TestUtil::SABRE_TEMPDIR.'/test2.txt', 'Test contents2'); + mkdir(\Sabre\TestUtil::SABRE_TEMPDIR.'/col'); + file_put_contents(\Sabre\TestUtil::SABRE_TEMPDIR.'col/test.txt', 'Test contents'); + $this->server->addPlugin(new Locks\Plugin(new Locks\Backend\File(\Sabre\TestUtil::SABRE_TEMPDIR.'/.locksdb'))); } public function teardown(): void { parent::tearDown(); - if (file_exists(SABRE_TEMPDIR.'../.locksdb')) { - unlink(SABRE_TEMPDIR.'../.locksdb'); + if (file_exists(\Sabre\TestUtil::SABRE_TEMPDIR.'../.locksdb')) { + unlink(\Sabre\TestUtil::SABRE_TEMPDIR.'../.locksdb'); } } diff --git a/tests/Sabre/DAV/TemporaryFileFilterTest.php b/tests/Sabre/DAV/TemporaryFileFilterTest.php index 560327ba60..95469141e5 100644 --- a/tests/Sabre/DAV/TemporaryFileFilterTest.php +++ b/tests/Sabre/DAV/TemporaryFileFilterTest.php @@ -11,7 +11,7 @@ class TemporaryFileFilterTest extends AbstractServer public function setup(): void { parent::setUp(); - $plugin = new TemporaryFileFilterPlugin(SABRE_TEMPDIR.'/tff'); + $plugin = new TemporaryFileFilterPlugin(\Sabre\TestUtil::SABRE_TEMPDIR.'/tff'); $this->server->addPlugin($plugin); } @@ -26,7 +26,7 @@ public function testPutNormal() self::assertEquals(201, $this->response->status); self::assertEquals('0', $this->response->getHeader('Content-Length')); - self::assertEquals('Testing new file', file_get_contents(SABRE_TEMPDIR.'/testput.txt')); + self::assertEquals('Testing new file', file_get_contents(\Sabre\TestUtil::SABRE_TEMPDIR.'/testput.txt')); } public function testPutTemp() @@ -43,7 +43,7 @@ public function testPutTemp() 'X-Sabre-Temp' => ['true'], ], $this->response->getHeaders()); - self::assertFalse(file_exists(SABRE_TEMPDIR.'/._testput.txt'), '._testput.txt should not exist in the regular file structure.'); + self::assertFalse(file_exists(\Sabre\TestUtil::SABRE_TEMPDIR.'/._testput.txt'), '._testput.txt should not exist in the regular file structure.'); } public function testPutTempIfNoneMatch() @@ -60,7 +60,7 @@ public function testPutTempIfNoneMatch() 'X-Sabre-Temp' => ['true'], ], $this->response->getHeaders()); - self::assertFalse(file_exists(SABRE_TEMPDIR.'/._testput.txt'), '._testput.txt should not exist in the regular file structure.'); + self::assertFalse(file_exists(\Sabre\TestUtil::SABRE_TEMPDIR.'/._testput.txt'), '._testput.txt should not exist in the regular file structure.'); $this->server->exec(); @@ -112,8 +112,8 @@ public function testGetWithBrowserPlugin() public function testLockNonExistant() { - mkdir(SABRE_TEMPDIR.'/locksdir'); - $locksBackend = new Locks\Backend\File(SABRE_TEMPDIR.'/locks'); + mkdir(\Sabre\TestUtil::SABRE_TEMPDIR.'/locksdir'); + $locksBackend = new Locks\Backend\File(\Sabre\TestUtil::SABRE_TEMPDIR.'/locks'); $locksPlugin = new Locks\Plugin($locksBackend); $this->server->addPlugin($locksPlugin); @@ -136,7 +136,7 @@ public function testLockNonExistant() self::assertTrue(1 === preg_match('/^$/', $this->response->getHeader('Lock-Token')), 'We did not get a valid Locktoken back ('.$this->response->getHeader('Lock-Token').')'); self::assertEquals('true', $this->response->getHeader('X-Sabre-Temp')); - self::assertFalse(file_exists(SABRE_TEMPDIR.'/._testlock.txt'), '._testlock.txt should not exist in the regular file structure.'); + self::assertFalse(file_exists(\Sabre\TestUtil::SABRE_TEMPDIR.'/._testlock.txt'), '._testlock.txt should not exist in the regular file structure.'); } public function testPutDelete() diff --git a/tests/Sabre/DAVACL/FS/CollectionTest.php b/tests/Sabre/DAVACL/FS/CollectionTest.php index b75dd0c03b..eded9fc1ee 100644 --- a/tests/Sabre/DAVACL/FS/CollectionTest.php +++ b/tests/Sabre/DAVACL/FS/CollectionTest.php @@ -8,7 +8,7 @@ class CollectionTest extends FileTest { public function setup(): void { - $this->path = SABRE_TEMPDIR; + $this->path = \Sabre\TestUtil::SABRE_TEMPDIR; $this->sut = new Collection($this->path, $this->acl, $this->owner); } @@ -19,7 +19,7 @@ public function teardown(): void public function testGetChildFile() { - file_put_contents(SABRE_TEMPDIR.'/file.txt', 'hello'); + file_put_contents(\Sabre\TestUtil::SABRE_TEMPDIR.'/file.txt', 'hello'); $child = $this->sut->getChild('file.txt'); self::assertInstanceOf('Sabre\\DAVACL\\FS\\File', $child); @@ -30,7 +30,7 @@ public function testGetChildFile() public function testGetChildDirectory() { - mkdir(SABRE_TEMPDIR.'/dir'); + mkdir(\Sabre\TestUtil::SABRE_TEMPDIR.'/dir'); $child = $this->sut->getChild('dir'); self::assertInstanceOf('Sabre\\DAVACL\\FS\\Collection', $child); diff --git a/tests/Sabre/DAVACL/FS/HomeCollectionTest.php b/tests/Sabre/DAVACL/FS/HomeCollectionTest.php index fbfcb2bfda..69f65ba90d 100644 --- a/tests/Sabre/DAVACL/FS/HomeCollectionTest.php +++ b/tests/Sabre/DAVACL/FS/HomeCollectionTest.php @@ -22,7 +22,7 @@ public function setup(): void { $principalBackend = new PrincipalBackend(); - $this->path = SABRE_TEMPDIR.'/home'; + $this->path = \Sabre\TestUtil::SABRE_TEMPDIR.'/home'; $this->sut = new HomeCollection($principalBackend, $this->path); $this->sut->collectionName = $this->name; diff --git a/tests/Sabre/HTTP/ResponseMock.php b/tests/Sabre/HTTP/ResponseMock.php index c5357928a3..0d968e178f 100644 --- a/tests/Sabre/HTTP/ResponseMock.php +++ b/tests/Sabre/HTTP/ResponseMock.php @@ -19,5 +19,5 @@ class ResponseMock extends Response * Making these public. */ public $body; - public $status; + public int $status; } diff --git a/tests/Sabre/HTTP/SapiMock.php b/tests/Sabre/HTTP/SapiMock.php index 4860030d01..c885078324 100644 --- a/tests/Sabre/HTTP/SapiMock.php +++ b/tests/Sabre/HTTP/SapiMock.php @@ -20,7 +20,7 @@ class SapiMock extends Sapi /** * Overriding this so nothing is ever echo'd. */ - public static function sendResponse(ResponseInterface $response) + public static function sendResponse(ResponseInterface $response): void { ++self::$sent; } diff --git a/tests/Sabre/TestUtil.php b/tests/Sabre/TestUtil.php index 4e7ca2fc45..f1a768e6c1 100644 --- a/tests/Sabre/TestUtil.php +++ b/tests/Sabre/TestUtil.php @@ -6,15 +6,17 @@ class TestUtil { + public const SABRE_TEMPDIR = __DIR__.'/../temp/'; + /** * This function deletes all the contents of the temporary directory. */ - public static function clearTempDir() + public static function clearTempDir(): void { - self::deleteTree(SABRE_TEMPDIR, false); + self::deleteTree(self::SABRE_TEMPDIR, false); } - private static function deleteTree($path, $deleteRoot = true) + private static function deleteTree($path, $deleteRoot = true): void { foreach (scandir($path) as $node) { if ('.' == $node || '..' == $node) { @@ -31,36 +33,4 @@ private static function deleteTree($path, $deleteRoot = true) rmdir($path); } } - - public static function getMySQLDB() - { - try { - $pdo = new \PDO(SABRE_MYSQLDSN, SABRE_MYSQLUSER, SABRE_MYSQLPASS); - $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); - - return $pdo; - } catch (\PDOException $e) { - return null; - } - } - - public static function getSQLiteDB() - { - $pdo = new \PDO('sqlite:'.SABRE_TEMPDIR.'/pdobackend'); - $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); - - return $pdo; - } - - public static function getPgSqlDB() - { - //try { - $pdo = new \PDO(SABRE_PGSQLDSN); - $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); - - return $pdo; - //} catch (\PDOException $e) { - // return null; - //} - } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index d158053825..fec0e72410 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -2,6 +2,9 @@ declare(strict_types=1); +use Sabre\DAV\Server; +use Sabre\TestUtil; + set_include_path(__DIR__.'/../lib/'.PATH_SEPARATOR.__DIR__.PATH_SEPARATOR.get_include_path()); $autoLoader = include __DIR__.'/../vendor/autoload.php'; @@ -16,49 +19,11 @@ if ('TRUE' === getenv('RUN_TEST_WITH_STREAMING_PROPFIND')) { echo 'Running unit tests with \Sabre\DAV\Server::$streamMultiStatus = true'; - \Sabre\DAV\Server::$streamMultiStatus = true; -} - -// List of variables that can be set by the environment -$environmentVars = [ - 'SABRE_MYSQLUSER', - 'SABRE_MYSQLPASS', - 'SABRE_MYSQLDSN', - 'SABRE_PGSQLDSN', -]; -foreach ($environmentVars as $var) { - if ($value = getenv($var)) { - define($var, $value); - } -} - -$config = [ - 'SABRE_TEMPDIR' => dirname(__FILE__).'/temp/', - 'SABRE_HASSQLITE' => in_array('sqlite', PDO::getAvailableDrivers()), - 'SABRE_HASMYSQL' => in_array('mysql', PDO::getAvailableDrivers()), - 'SABRE_HASPGSQL' => in_array('pgsql', PDO::getAvailableDrivers()), - 'SABRE_MYSQLDSN' => 'mysql:host=127.0.0.1;dbname=sabredav_test', - 'SABRE_MYSQLUSER' => 'sabredav', - 'SABRE_MYSQLPASS' => '', - 'SABRE_PGSQLDSN' => 'pgsql:host=localhost;dbname=sabredav_test;user=sabredav;password=sabredav', -]; - -if (file_exists(__DIR__.'/config.user.php')) { - $userConfig = []; - include __DIR__.'/config.user.php'; - foreach ($userConfig as $key => $value) { - $config[$key] = $value; - } -} - -foreach ($config as $key => $value) { - if (!defined($key)) { - define($key, $value); - } + Server::$streamMultiStatus = true; } -if (!file_exists(SABRE_TEMPDIR)) { - mkdir(SABRE_TEMPDIR); +if (!file_exists(TestUtil::SABRE_TEMPDIR)) { + mkdir(TestUtil::SABRE_TEMPDIR); } if (file_exists('.sabredav')) { unlink('.sabredav'); diff --git a/tests/phpunit.xml b/tests/phpunit.xml index b836b59964..9186dfc307 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -1,41 +1,33 @@ - - + + + + ../lib/ + + - - ../vendor/sabre/http/tests/HTTP - - - - Sabre/DAV - - - Sabre/DAVACL - - - Sabre/CalDAV - - - Sabre/CardDAV - + + ../vendor/sabre/http/tests/HTTP + + + Sabre/DAV + + + Sabre/DAVACL + + + Sabre/CalDAV + + + Sabre/CardDAV + - - - - ../lib/ - - - + + + +