From 9d6f955cbbb1b540aee4b4f4d95a94a313ffa47b Mon Sep 17 00:00:00 2001 From: Jeroen van Oort Date: Sat, 4 Jan 2020 10:29:40 +0100 Subject: [PATCH] Added phpstan for tests folder (#485) --- .travis.yml | 2 +- composer.json | 5 ++ lib/PHPUnitAssertions.php | 3 +- tests/VObject/CliTest.php | 3 + tests/VObject/Component/VCardTest.php | 6 +- tests/VObject/FreeBusyGeneratorTest.php | 2 +- tests/VObject/JCalTest.php | 42 +++++----- tests/VObject/JCardTest.php | 36 ++++---- tests/VObject/Parser/JsonTest.php | 82 +++++++++---------- .../EventIterator/ByMonthInDailyTest.php | 2 +- .../Recur/EventIterator/BySetPosHangTest.php | 2 +- .../EventIterator/InfiniteLoopProblemTest.php | 3 + .../Recur/EventIterator/Issue48Test.php | 6 +- .../Recur/EventIterator/Issue50Test.php | 6 +- .../Recur/EventIterator/NoInstancesTest.php | 3 +- .../EventIterator/OverrideFirstEventTest.php | 2 +- .../SameDateForRecurringEventsTest.php | 3 +- tests/VObject/TimeZoneUtilTest.php | 2 +- tests/bootstrap.php | 2 - 19 files changed, 113 insertions(+), 99 deletions(-) diff --git a/.travis.yml b/.travis.yml index d0b32bc3a..d42b4d748 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ before_script: - composer install script: - - if [[ $TRAVIS_PHP_VERSION =~ ^7\.1|7\.2|7\.3|7\.4$ ]]; then php phpstan.phar analyse -c phpstan.neon lib; fi + - if [[ $TRAVIS_PHP_VERSION =~ ^7\.1|7\.2|7\.3|7\.4$ ]]; then php phpstan.phar analyse -c phpstan.neon lib tests; fi - ./bin/phpunit --configuration tests/phpunit.xml --coverage-clover=coverage.xml after_success: diff --git a/composer.json b/composer.json index d757a4bc8..1d249c60c 100644 --- a/composer.json +++ b/composer.json @@ -71,6 +71,11 @@ "Sabre\\VObject\\" : "lib/" } }, + "autoload-dev" : { + "psr-4" : { + "Sabre\\VObject\\" : "tests/VObject" + } + }, "bin" : [ "bin/vobject", "bin/generate_vcards" diff --git a/lib/PHPUnitAssertions.php b/lib/PHPUnitAssertions.php index d77e4b1ed..635988387 100644 --- a/lib/PHPUnitAssertions.php +++ b/lib/PHPUnitAssertions.php @@ -34,8 +34,7 @@ trait PHPUnitAssertions */ public function assertVObjectEqualsVObject($expected, $actual, $message = '') { - $self = $this; - $getObj = function ($input) use ($self) { + $getObj = function ($input) { if (is_resource($input)) { $input = stream_get_contents($input); } diff --git a/tests/VObject/CliTest.php b/tests/VObject/CliTest.php index 11c969c9d..cae424d96 100644 --- a/tests/VObject/CliTest.php +++ b/tests/VObject/CliTest.php @@ -11,6 +11,9 @@ */ class CliTest extends TestCase { + /** @var CliMock */ + private $cli; + public function setUp() { $this->cli = new CliMock(); diff --git a/tests/VObject/Component/VCardTest.php b/tests/VObject/Component/VCardTest.php index 1895ce6c5..3124fec84 100644 --- a/tests/VObject/Component/VCardTest.php +++ b/tests/VObject/Component/VCardTest.php @@ -204,7 +204,7 @@ public function testNoUIDCardDAV() VCF; $this->assertValidate( $vcard, - VCARD::PROFILE_CARDDAV, + VCard::PROFILE_CARDDAV, 3, 'vCards on CardDAV servers MUST have a UID property.' ); @@ -236,7 +236,7 @@ public function testNoUIDNoCardDAVRepair() VCF; $this->assertValidate( $vcard, - VCARD::REPAIR, + VCard::REPAIR, 1, 'Adding a UID to a vCard property is recommended.' ); @@ -253,7 +253,7 @@ public function testVCard21CardDAV() VCF; $this->assertValidate( $vcard, - VCARD::PROFILE_CARDDAV, + VCard::PROFILE_CARDDAV, 3, 'CardDAV servers are not allowed to accept vCard 2.1.' ); diff --git a/tests/VObject/FreeBusyGeneratorTest.php b/tests/VObject/FreeBusyGeneratorTest.php index 323cf632b..e2dd59409 100644 --- a/tests/VObject/FreeBusyGeneratorTest.php +++ b/tests/VObject/FreeBusyGeneratorTest.php @@ -30,7 +30,7 @@ public function testInvalidArg() $gen = new FreeBusyGenerator( new \DateTime('2012-01-01'), new \DateTime('2012-12-31'), - new \StdClass() + new \stdClass() ); } diff --git a/tests/VObject/JCalTest.php b/tests/VObject/JCalTest.php index d2de80281..9332b6413 100644 --- a/tests/VObject/JCalTest.php +++ b/tests/VObject/JCalTest.php @@ -43,19 +43,19 @@ public function testToJCal() [ [ 'version', - new \StdClass(), + new \stdClass(), 'text', '2.0', ], [ 'prodid', - new \StdClass(), + new \stdClass(), 'text', '-//Sabre//Sabre VObject '.Version::VERSION.'//EN', ], [ 'calscale', - new \StdClass(), + new \stdClass(), 'text', 'GREGORIAN', ], @@ -64,22 +64,22 @@ public function testToJCal() ['vevent', [ [ - 'uid', new \StdClass(), 'text', 'foo', + 'uid', new \stdClass(), 'text', 'foo', ], [ - 'dtstart', new \StdClass(), 'date', '2013-05-26', + 'dtstart', new \stdClass(), 'date', '2013-05-26', ], [ - 'duration', new \StdClass(), 'duration', 'P1D', + 'duration', new \stdClass(), 'duration', 'P1D', ], [ - 'categories', new \StdClass(), 'text', 'home', 'testing', + 'categories', new \stdClass(), 'text', 'home', 'testing', ], [ - 'created', new \StdClass(), 'date-time', '2013-05-26T18:10:00Z', + 'created', new \stdClass(), 'date-time', '2013-05-26T18:10:00Z', ], [ - 'attendee', new \StdClass(), 'cal-address', 'mailto:armin@example.org', + 'attendee', new \stdClass(), 'cal-address', 'mailto:armin@example.org', ], [ 'attendee', @@ -91,50 +91,50 @@ public function testToJCal() 'mailto:dominik@example.org', ], [ - 'geo', new \StdClass(), 'float', [51.96668, 7.61876], + 'geo', new \stdClass(), 'float', [51.96668, 7.61876], ], [ - 'sequence', new \StdClass(), 'integer', 5, + 'sequence', new \stdClass(), 'integer', 5, ], [ - 'freebusy', new \StdClass(), 'period', ['2013-05-26T21:02:13', 'PT1H'], ['2013-06-26T12:00:00', '2013-06-26T13:00:00'], + 'freebusy', new \stdClass(), 'period', ['2013-05-26T21:02:13', 'PT1H'], ['2013-06-26T12:00:00', '2013-06-26T13:00:00'], ], [ - 'url', new \StdClass(), 'uri', 'http://example.org/', + 'url', new \stdClass(), 'uri', 'http://example.org/', ], [ - 'tzoffsetfrom', new \StdClass(), 'utc-offset', '+05:00', + 'tzoffsetfrom', new \stdClass(), 'utc-offset', '+05:00', ], [ - 'rrule', new \StdClass(), 'recur', [ + 'rrule', new \stdClass(), 'recur', [ 'freq' => 'WEEKLY', 'byday' => ['MO', 'TU'], ], ], [ - 'x-bool', new \StdClass(), 'boolean', true, + 'x-bool', new \stdClass(), 'boolean', true, ], [ - 'x-time', new \StdClass(), 'time', '08:00:00', + 'x-time', new \stdClass(), 'time', '08:00:00', ], [ - 'attach', new \StdClass(), 'binary', base64_encode('attachment'), + 'attach', new \stdClass(), 'binary', base64_encode('attachment'), ], [ 'request-status', - new \StdClass(), + new \stdClass(), 'text', ['2.0', 'Success'], ], [ 'request-status', - new \StdClass(), + new \stdClass(), 'text', ['3.7', 'Invalid Calendar User', 'ATTENDEE:mailto:jsmith@example.org'], ], [ 'dtend', - new \StdClass(), + new \stdClass(), 'date-time', '2015-01-08T13:30:00', ], diff --git a/tests/VObject/JCardTest.php b/tests/VObject/JCardTest.php index 2100a07a9..1864f666d 100644 --- a/tests/VObject/JCardTest.php +++ b/tests/VObject/JCardTest.php @@ -48,25 +48,25 @@ public function testToJCard() [ [ 'version', - new \StdClass(), + new \stdClass(), 'text', '4.0', ], [ 'prodid', - new \StdClass(), + new \stdClass(), 'text', '-//Sabre//Sabre VObject '.Version::VERSION.'//EN', ], [ 'uid', - new \StdClass(), + new \stdClass(), 'text', 'foo', ], [ 'bday', - new \StdClass(), + new \stdClass(), 'date-and-or-time', '1985-04-07', ], @@ -80,25 +80,25 @@ public function testToJCard() ], [ 'bday', - new \StdClass(), + new \stdClass(), 'date-time', '1979-12-25T02:00:00', ], [ 'rev', - new \StdClass(), + new \stdClass(), 'timestamp', '1995-10-31T22:27:10Z', ], [ 'lang', - new \StdClass(), + new \stdClass(), 'language-tag', 'nl', ], [ 'n', - new \StdClass(), + new \stdClass(), 'text', ['Last', 'First', 'Middle', '', ''], ], @@ -120,7 +120,7 @@ public function testToJCard() ], [ 'adr', - new \StdClass(), + new \stdClass(), 'text', [ '', @@ -134,55 +134,55 @@ public function testToJCard() ], [ 'x-truncated', - new \StdClass(), + new \stdClass(), 'date', '--12-25', ], [ 'x-time-local', - new \StdClass(), + new \stdClass(), 'time', '12:30:00', ], [ 'x-time-utc', - new \StdClass(), + new \stdClass(), 'time', '12:30:00Z', ], [ 'x-time-offset', - new \StdClass(), + new \stdClass(), 'time', '12:30:00-08:00', ], [ 'x-time-reduced', - new \StdClass(), + new \stdClass(), 'time', '23', ], [ 'x-time-truncated', - new \StdClass(), + new \stdClass(), 'time', '--30', ], [ 'x-karma-points', - new \StdClass(), + new \stdClass(), 'integer', 42, ], [ 'x-grade', - new \StdClass(), + new \stdClass(), 'float', 1.3, ], [ 'tz', - new \StdClass(), + new \stdClass(), 'utc-offset', '-05:00', ], diff --git a/tests/VObject/Parser/JsonTest.php b/tests/VObject/Parser/JsonTest.php index 587f55f70..2aa0d9dab 100644 --- a/tests/VObject/Parser/JsonTest.php +++ b/tests/VObject/Parser/JsonTest.php @@ -14,25 +14,25 @@ public function testRoundTripJCard() [ [ 'version', - new \StdClass(), + new \stdClass(), 'text', '4.0', ], [ 'prodid', - new \StdClass(), + new \stdClass(), 'text', '-//Sabre//Sabre VObject '.VObject\Version::VERSION.'//EN', ], [ 'uid', - new \StdClass(), + new \stdClass(), 'text', 'foo', ], [ 'bday', - new \StdClass(), + new \stdClass(), 'date-and-or-time', '1985-04-07', ], @@ -46,25 +46,25 @@ public function testRoundTripJCard() ], [ 'bday', - new \StdClass(), + new \stdClass(), 'date-time', '1979-12-25T02:00:00', ], [ 'rev', - new \StdClass(), + new \stdClass(), 'timestamp', '1995-10-31T22:27:10Z', ], [ 'lang', - new \StdClass(), + new \stdClass(), 'language-tag', 'nl', ], [ 'n', - new \StdClass(), + new \stdClass(), 'text', ['Last', 'First', 'Middle', '', ''], ], @@ -86,7 +86,7 @@ public function testRoundTripJCard() ], [ 'adr', - new \StdClass(), + new \stdClass(), 'text', [ '', @@ -101,55 +101,55 @@ public function testRoundTripJCard() [ 'x-truncated', - new \StdClass(), + new \stdClass(), 'date', '--12-25', ], [ 'x-time-local', - new \StdClass(), + new \stdClass(), 'time', '12:30:00', ], [ 'x-time-utc', - new \StdClass(), + new \stdClass(), 'time', '12:30:00Z', ], [ 'x-time-offset', - new \StdClass(), + new \stdClass(), 'time', '12:30:00-08:00', ], [ 'x-time-reduced', - new \StdClass(), + new \stdClass(), 'time', '23', ], [ 'x-time-truncated', - new \StdClass(), + new \stdClass(), 'time', '--30', ], [ 'x-karma-points', - new \StdClass(), + new \stdClass(), 'integer', 42, ], [ 'x-grade', - new \StdClass(), + new \stdClass(), 'float', 1.3, ], [ 'tz', - new \StdClass(), + new \stdClass(), 'utc-offset', '-05:00', ], @@ -203,19 +203,19 @@ public function testRoundTripJCal() [ [ 'version', - new \StdClass(), + new \stdClass(), 'text', '2.0', ], [ 'prodid', - new \StdClass(), + new \stdClass(), 'text', '-//Sabre//Sabre VObject '.VObject\Version::VERSION.'//EN', ], [ 'calscale', - new \StdClass(), + new \stdClass(), 'text', 'GREGORIAN', ], @@ -224,25 +224,25 @@ public function testRoundTripJCal() ['vevent', [ [ - 'uid', new \StdClass(), 'text', 'foo', + 'uid', new \stdClass(), 'text', 'foo', ], [ - 'dtstart', new \StdClass(), 'date', '2013-05-26', + 'dtstart', new \stdClass(), 'date', '2013-05-26', ], [ - 'duration', new \StdClass(), 'duration', 'P1D', + 'duration', new \stdClass(), 'duration', 'P1D', ], [ - 'categories', new \StdClass(), 'text', 'home', 'testing', + 'categories', new \stdClass(), 'text', 'home', 'testing', ], [ - 'created', new \StdClass(), 'date-time', '2013-05-26T18:10:00Z', + 'created', new \stdClass(), 'date-time', '2013-05-26T18:10:00Z', ], [ - 'attach', new \StdClass(), 'binary', base64_encode('attachment'), + 'attach', new \stdClass(), 'binary', base64_encode('attachment'), ], [ - 'attendee', new \StdClass(), 'cal-address', 'mailto:armin@example.org', + 'attendee', new \stdClass(), 'cal-address', 'mailto:armin@example.org', ], [ 'attendee', @@ -254,41 +254,41 @@ public function testRoundTripJCal() 'mailto:dominik@example.org', ], [ - 'geo', new \StdClass(), 'float', [51.96668, 7.61876], + 'geo', new \stdClass(), 'float', [51.96668, 7.61876], ], [ - 'sequence', new \StdClass(), 'integer', 5, + 'sequence', new \stdClass(), 'integer', 5, ], [ - 'freebusy', new \StdClass(), 'period', ['2013-05-26T21:02:13', 'PT1H'], ['2013-06-26T12:00:00', '2013-06-26T13:00:00'], + 'freebusy', new \stdClass(), 'period', ['2013-05-26T21:02:13', 'PT1H'], ['2013-06-26T12:00:00', '2013-06-26T13:00:00'], ], [ - 'url', new \StdClass(), 'uri', 'http://example.org/', + 'url', new \stdClass(), 'uri', 'http://example.org/', ], [ - 'tzoffsetfrom', new \StdClass(), 'utc-offset', '+05:00', + 'tzoffsetfrom', new \stdClass(), 'utc-offset', '+05:00', ], [ - 'rrule', new \StdClass(), 'recur', [ + 'rrule', new \stdClass(), 'recur', [ 'freq' => 'WEEKLY', 'byday' => ['MO', 'TU'], ], ], [ - 'x-bool', new \StdClass(), 'boolean', true, + 'x-bool', new \stdClass(), 'boolean', true, ], [ - 'x-time', new \StdClass(), 'time', '08:00:00', + 'x-time', new \stdClass(), 'time', '08:00:00', ], [ 'request-status', - new \StdClass(), + new \stdClass(), 'text', ['2.0', 'Success'], ], [ 'request-status', - new \StdClass(), + new \stdClass(), 'text', ['3.7', 'Invalid Calendar User', 'ATTENDEE:mailto:jsmith@example.org'], ], @@ -297,7 +297,7 @@ public function testRoundTripJCal() ['valarm', [ [ - 'action', new \StdClass(), 'text', 'DISPLAY', + 'action', new \stdClass(), 'text', 'DISPLAY', ], ], [], @@ -358,7 +358,7 @@ public function testParseStreamArg() 'vcard', [ [ - 'FN', new \StdClass(), 'text', 'foo', + 'FN', new \stdClass(), 'text', 'foo', ], ], ]; @@ -381,7 +381,7 @@ public function testParseInvalidData() 'vlist', [ [ - 'FN', new \StdClass(), 'text', 'foo', + 'FN', new \stdClass(), 'text', 'foo', ], ], ]; diff --git a/tests/VObject/Recur/EventIterator/ByMonthInDailyTest.php b/tests/VObject/Recur/EventIterator/ByMonthInDailyTest.php index 40f09364f..71858c36f 100644 --- a/tests/VObject/Recur/EventIterator/ByMonthInDailyTest.php +++ b/tests/VObject/Recur/EventIterator/ByMonthInDailyTest.php @@ -1,6 +1,6 @@ vcal = new VCalendar(); diff --git a/tests/VObject/Recur/EventIterator/Issue48Test.php b/tests/VObject/Recur/EventIterator/Issue48Test.php index fe4b06755..f08f0ccce 100644 --- a/tests/VObject/Recur/EventIterator/Issue48Test.php +++ b/tests/VObject/Recur/EventIterator/Issue48Test.php @@ -1,10 +1,12 @@ assertInstanceOf('Sabre\\VObject\\Component\\VCalendar', $vcal); - $it = new Recur\EventIterator($vcal, 'foo'); + $it = new EventIterator($vcal, 'foo'); $result = iterator_to_array($it); diff --git a/tests/VObject/Recur/EventIterator/Issue50Test.php b/tests/VObject/Recur/EventIterator/Issue50Test.php index df9c15519..faa04e829 100644 --- a/tests/VObject/Recur/EventIterator/Issue50Test.php +++ b/tests/VObject/Recur/EventIterator/Issue50Test.php @@ -1,10 +1,12 @@ assertInstanceOf('Sabre\\VObject\\Component\\VCalendar', $vcal); - $it = new Recur\EventIterator($vcal, '1aef0b27-3d92-4581-829a-11999dd36724'); + $it = new EventIterator($vcal, '1aef0b27-3d92-4581-829a-11999dd36724'); $result = []; foreach ($it as $instance) { diff --git a/tests/VObject/Recur/EventIterator/NoInstancesTest.php b/tests/VObject/Recur/EventIterator/NoInstancesTest.php index b3e5a11fa..24810db14 100644 --- a/tests/VObject/Recur/EventIterator/NoInstancesTest.php +++ b/tests/VObject/Recur/EventIterator/NoInstancesTest.php @@ -1,9 +1,10 @@ addPsr4('Sabre\\VObject\\', __DIR__.'/VObject'); - if (!defined('SABRE_TEMPDIR')) { define('SABRE_TEMPDIR', __DIR__.'/temp/'); }