From 590abaf0efca5bfc33772c9756ec8a4ac71d6638 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Sun, 21 May 2017 17:16:32 -0400 Subject: [PATCH] Start on tests for Feed - Makes use of PHP's internal Web server to deliver expected responses from a real server - Windows batch file can be used to run tests (Linux and Mac test runners to come later) - Added PHPUnit to dev dependencies --- composer.json | 3 +- composer.lock | 1049 +++++++++++++++++- lib/Db/AbstractStatement.php | 2 +- lib/Misc/DateFormatter.php | 44 + tests/Feed/TestFeed.php | 63 ++ tests/docroot/Feed/NextFetch/NotModified.php | 4 + tests/lib/Tools.php | 8 + tests/phpunit.xml | 3 + tests/server.php | 66 ++ tests/test.bat | 10 + 10 files changed, 1232 insertions(+), 20 deletions(-) create mode 100644 lib/Misc/DateFormatter.php create mode 100644 tests/Feed/TestFeed.php create mode 100644 tests/docroot/Feed/NextFetch/NotModified.php create mode 100644 tests/server.php create mode 100644 tests/test.bat diff --git a/composer.json b/composer.json index 8101526a..d732506d 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,8 @@ }, "require-dev": { "mikey179/vfsStream": "^1.6.4", - "phake/phake": "^2.3.2" + "phake/phake": "^2.3.2", + "phpunit/phpunit": "^6.0.5" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 3cc201fa..14a02683 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "58d51aeeabc7ce9d69626938805bb61f", + "content-hash": "3fce3392b0a38874ae31bb602f46c33b", "packages": [ { "name": "fguillot/picofeed", - "version": "v0.1.31", + "version": "v0.1.33", "source": { "type": "git", "url": "https://github.com/fguillot/picoFeed.git", - "reference": "b753961879d0b92c284971d902355e00cad1fd9b" + "reference": "b44f1e1fdecfd2e7f158df86a23e1ea3dfb4e16f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fguillot/picoFeed/zipball/b753961879d0b92c284971d902355e00cad1fd9b", - "reference": "b753961879d0b92c284971d902355e00cad1fd9b", + "url": "https://api.github.com/repos/fguillot/picoFeed/zipball/b44f1e1fdecfd2e7f158df86a23e1ea3dfb4e16f", + "reference": "b44f1e1fdecfd2e7f158df86a23e1ea3dfb4e16f", "shasum": "" }, "require": { @@ -57,7 +57,7 @@ ], "description": "Modern library to handle RSS/Atom feeds", "homepage": "https://github.com/fguillot/picoFeed", - "time": "2017-01-16T03:10:21+00:00" + "time": "2017-04-07T01:57:15+00:00" }, { "name": "hosteurope/password-generator", @@ -146,16 +146,16 @@ }, { "name": "phpseclib/phpseclib", - "version": "2.0.4", + "version": "2.0.5", "source": { "type": "git", "url": "https://github.com/phpseclib/phpseclib.git", - "reference": "ab8028c93c03cc8d9c824efa75dc94f1db2369bf" + "reference": "f8dd0e18d2328c447dd4190fecd11ef52680d968" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/ab8028c93c03cc8d9c824efa75dc94f1db2369bf", - "reference": "ab8028c93c03cc8d9c824efa75dc94f1db2369bf", + "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/f8dd0e18d2328c447dd4190fecd11ef52680d968", + "reference": "f8dd0e18d2328c447dd4190fecd11ef52680d968", "shasum": "" }, "require": { @@ -234,7 +234,7 @@ "x.509", "x509" ], - "time": "2016-10-04T00:57:04+00:00" + "time": "2017-05-08T05:58:35+00:00" }, { "name": "webmozart/assert", @@ -426,6 +426,60 @@ } ], "packages-dev": [ + { + "name": "doctrine/instantiator", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d", + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d", + "shasum": "" + }, + "require": { + "php": ">=5.3,<8.0-DEV" + }, + "require-dev": { + "athletic/athletic": "~0.1.8", + "ext-pdo": "*", + "ext-phar": "*", + "phpunit/phpunit": "~4.0", + "squizlabs/php_codesniffer": "~2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://github.com/doctrine/instantiator", + "keywords": [ + "constructor", + "instantiate" + ], + "time": "2015-06-14T21:17:01+00:00" + }, { "name": "mikey179/vfsStream", "version": "v1.6.4", @@ -472,6 +526,48 @@ "homepage": "http://vfs.bovigo.org/", "time": "2016-07-18T14:02:57+00:00" }, + { + "name": "myclabs/deep-copy", + "version": "1.6.1", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "8e6e04167378abf1ddb4d3522d8755c5fd90d102" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/8e6e04167378abf1ddb4d3522d8755c5fd90d102", + "reference": "8e6e04167378abf1ddb4d3522d8755c5fd90d102", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "doctrine/collections": "1.*", + "phpunit/phpunit": "~4.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "homepage": "https://github.com/myclabs/DeepCopy", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "time": "2017-04-12T18:52:22+00:00" + }, { "name": "phake/phake", "version": "v2.3.2", @@ -530,6 +626,651 @@ ], "time": "2017-03-20T05:16:34+00:00" }, + { + "name": "phpdocumentor/reflection-common", + "version": "1.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionCommon.git", + "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/144c307535e82c8fdcaacbcfc1d6d8eeb896687c", + "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c", + "shasum": "" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "phpunit/phpunit": "^4.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jaap van Otterdijk", + "email": "opensource@ijaap.nl" + } + ], + "description": "Common reflection classes used by phpdocumentor to reflect the code structure", + "homepage": "http://www.phpdoc.org", + "keywords": [ + "FQSEN", + "phpDocumentor", + "phpdoc", + "reflection", + "static analysis" + ], + "time": "2015-12-27T11:43:31+00:00" + }, + { + "name": "phpdocumentor/reflection-docblock", + "version": "3.1.1", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", + "reference": "8331b5efe816ae05461b7ca1e721c01b46bafb3e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/8331b5efe816ae05461b7ca1e721c01b46bafb3e", + "reference": "8331b5efe816ae05461b7ca1e721c01b46bafb3e", + "shasum": "" + }, + "require": { + "php": ">=5.5", + "phpdocumentor/reflection-common": "^1.0@dev", + "phpdocumentor/type-resolver": "^0.2.0", + "webmozart/assert": "^1.0" + }, + "require-dev": { + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^4.4" + }, + "type": "library", + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", + "time": "2016-09-30T07:12:33+00:00" + }, + { + "name": "phpdocumentor/type-resolver", + "version": "0.2.1", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/TypeResolver.git", + "reference": "e224fb2ea2fba6d3ad6fdaef91cd09a172155ccb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/e224fb2ea2fba6d3ad6fdaef91cd09a172155ccb", + "reference": "e224fb2ea2fba6d3ad6fdaef91cd09a172155ccb", + "shasum": "" + }, + "require": { + "php": ">=5.5", + "phpdocumentor/reflection-common": "^1.0" + }, + "require-dev": { + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^5.2||^4.8.24" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "time": "2016-11-25T06:54:22+00:00" + }, + { + "name": "phpspec/prophecy", + "version": "v1.7.0", + "source": { + "type": "git", + "url": "https://github.com/phpspec/prophecy.git", + "reference": "93d39f1f7f9326d746203c7c056f300f7f126073" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/93d39f1f7f9326d746203c7c056f300f7f126073", + "reference": "93d39f1f7f9326d746203c7c056f300f7f126073", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "php": "^5.3|^7.0", + "phpdocumentor/reflection-docblock": "^2.0|^3.0.2", + "sebastian/comparator": "^1.1|^2.0", + "sebastian/recursion-context": "^1.0|^2.0|^3.0" + }, + "require-dev": { + "phpspec/phpspec": "^2.5|^3.2", + "phpunit/phpunit": "^4.8 || ^5.6.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.6.x-dev" + } + }, + "autoload": { + "psr-0": { + "Prophecy\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + }, + { + "name": "Marcello Duarte", + "email": "marcello.duarte@gmail.com" + } + ], + "description": "Highly opinionated mocking framework for PHP 5.3+", + "homepage": "https://github.com/phpspec/prophecy", + "keywords": [ + "Double", + "Dummy", + "fake", + "mock", + "spy", + "stub" + ], + "time": "2017-03-02T20:05:34+00:00" + }, + { + "name": "phpunit/php-code-coverage", + "version": "5.2.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "e648abfd8ffb1d54ad549b027b75e376e9055d02" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/e648abfd8ffb1d54ad549b027b75e376e9055d02", + "reference": "e648abfd8ffb1d54ad549b027b75e376e9055d02", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-xmlwriter": "*", + "php": "^7.0", + "phpunit/php-file-iterator": "^1.3", + "phpunit/php-text-template": "^1.2", + "phpunit/php-token-stream": "^1.4.11 || ^2.0", + "sebastian/code-unit-reverse-lookup": "^1.0", + "sebastian/environment": "^2.0", + "sebastian/version": "^2.0", + "theseer/tokenizer": "^1.1" + }, + "require-dev": { + "ext-xdebug": "^2.5", + "phpunit/phpunit": "^6.0" + }, + "suggest": { + "ext-xdebug": "^2.5.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.2.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "time": "2017-04-20T10:00:57+00:00" + }, + { + "name": "phpunit/php-file-iterator", + "version": "1.4.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/3cc8f69b3028d0f96a9078e6295d86e9bf019be5", + "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "time": "2016-10-03T07:40:28+00:00" + }, + { + "name": "phpunit/php-text-template", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "time": "2015-06-21T13:50:34+00:00" + }, + { + "name": "phpunit/php-timer", + "version": "1.0.9", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", + "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "time": "2017-02-26T11:10:40+00:00" + }, + { + "name": "phpunit/php-token-stream", + "version": "1.4.11", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "e03f8f67534427a787e21a385a67ec3ca6978ea7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/e03f8f67534427a787e21a385a67ec3ca6978ea7", + "reference": "e03f8f67534427a787e21a385a67ec3ca6978ea7", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Wrapper around PHP's tokenizer extension.", + "homepage": "https://github.com/sebastianbergmann/php-token-stream/", + "keywords": [ + "tokenizer" + ], + "time": "2017-02-27T10:12:30+00:00" + }, + { + "name": "phpunit/phpunit", + "version": "6.0.8", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "47ee3fa1bca5c50f1d25105201eb20df777bd7b6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/47ee3fa1bca5c50f1d25105201eb20df777bd7b6", + "reference": "47ee3fa1bca5c50f1d25105201eb20df777bd7b6", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", + "myclabs/deep-copy": "^1.3", + "php": "^7.0", + "phpspec/prophecy": "^1.6.2", + "phpunit/php-code-coverage": "^5.0", + "phpunit/php-file-iterator": "^1.4", + "phpunit/php-text-template": "^1.2", + "phpunit/php-timer": "^1.0.6", + "phpunit/phpunit-mock-objects": "^4.0", + "sebastian/comparator": "^1.2.4 || ^2.0", + "sebastian/diff": "^1.2", + "sebastian/environment": "^2.0", + "sebastian/exporter": "^2.0 || ^3.0", + "sebastian/global-state": "^1.1 || ^2.0", + "sebastian/object-enumerator": "^2.0 || ^3.0", + "sebastian/resource-operations": "^1.0", + "sebastian/version": "^2.0" + }, + "conflict": { + "phpdocumentor/reflection-docblock": "3.0.2", + "phpunit/dbunit": "<3.0" + }, + "require-dev": { + "ext-pdo": "*" + }, + "suggest": { + "ext-xdebug": "*", + "phpunit/php-invoker": "^1.1" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "6.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "time": "2017-03-02T15:24:03+00:00" + }, + { + "name": "phpunit/phpunit-mock-objects", + "version": "4.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", + "reference": "3819745c44f3aff9518fd655f320c4535d541af7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/3819745c44f3aff9518fd655f320c4535d541af7", + "reference": "3819745c44f3aff9518fd655f320c4535d541af7", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "php": "^7.0", + "phpunit/php-text-template": "^1.2", + "sebastian/exporter": "^2.0" + }, + "conflict": { + "phpunit/phpunit": "<6.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "suggest": { + "ext-soap": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Mock Object library for PHPUnit", + "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", + "keywords": [ + "mock", + "xunit" + ], + "time": "2017-02-02T10:36:38+00:00" + }, + { + "name": "sebastian/code-unit-reverse-lookup", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", + "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.7 || ^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Looks up which function or method a line of code belongs to", + "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "time": "2017-03-04T06:30:41+00:00" + }, { "name": "sebastian/comparator", "version": "1.2.4", @@ -596,23 +1337,23 @@ }, { "name": "sebastian/diff", - "version": "1.4.1", + "version": "1.4.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e" + "reference": "3c7d21999e815cdfac70c6c7d79d3a9cb1bc7bc2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/13edfd8706462032c2f52b4b862974dd46b71c9e", - "reference": "13edfd8706462032c2f52b4b862974dd46b71c9e", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/3c7d21999e815cdfac70c6c7d79d3a9cb1bc7bc2", + "reference": "3c7d21999e815cdfac70c6c7d79d3a9cb1bc7bc2", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^5.3.3 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "~4.8" + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" }, "type": "library", "extra": { @@ -644,7 +1385,57 @@ "keywords": [ "diff" ], - "time": "2015-12-08T07:14:41+00:00" + "time": "2017-05-18T13:44:30+00:00" + }, + { + "name": "sebastian/environment", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5795ffe5dc5b02460c3e34222fee8cbe245d8fac", + "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "http://www.github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "time": "2016-11-26T07:53:53+00:00" }, { "name": "sebastian/exporter", @@ -713,6 +1504,103 @@ ], "time": "2016-11-19T08:54:04+00:00" }, + { + "name": "sebastian/global-state", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4", + "reference": "e8ba02eed7bbbb9e59e43dedd3dddeff4a56b0c4", + "shasum": "" + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "suggest": { + "ext-uopz": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "time": "2017-04-27T15:39:26+00:00" + }, + { + "name": "sebastian/object-enumerator", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-enumerator.git", + "reference": "1311872ac850040a79c3c058bea3e22d0f09cbb7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/1311872ac850040a79c3c058bea3e22d0f09cbb7", + "reference": "1311872ac850040a79c3c058bea3e22d0f09cbb7", + "shasum": "" + }, + "require": { + "php": ">=5.6", + "sebastian/recursion-context": "~2.0" + }, + "require-dev": { + "phpunit/phpunit": "~5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Traverses array structures and object graphs to enumerate all referenced objects", + "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "time": "2017-02-18T15:18:39+00:00" + }, { "name": "sebastian/recursion-context", "version": "2.0.0", @@ -765,6 +1653,131 @@ "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", "time": "2016-11-19T07:33:16+00:00" + }, + { + "name": "sebastian/resource-operations", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/resource-operations.git", + "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", + "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", + "shasum": "" + }, + "require": { + "php": ">=5.6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides a list of PHP built-in functions that operate on resources", + "homepage": "https://www.github.com/sebastianbergmann/resource-operations", + "time": "2015-07-28T20:34:47+00:00" + }, + { + "name": "sebastian/version", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/99732be0ddb3361e16ad77b68ba41efc8e979019", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "time": "2016-10-03T07:35:21+00:00" + }, + { + "name": "theseer/tokenizer", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/theseer/tokenizer.git", + "reference": "cb2f008f3f05af2893a87208fe6a6c4985483f8b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/cb2f008f3f05af2893a87208fe6a6c4985483f8b", + "reference": "cb2f008f3f05af2893a87208fe6a6c4985483f8b", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": "^7.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + } + ], + "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", + "time": "2017-04-07T12:08:54+00:00" } ], "aliases": [], diff --git a/lib/Db/AbstractStatement.php b/lib/Db/AbstractStatement.php index 48633503..74a849d7 100644 --- a/lib/Db/AbstractStatement.php +++ b/lib/Db/AbstractStatement.php @@ -95,6 +95,6 @@ abstract class AbstractStatement implements Statement { $time = (int) $date; } // ISO 8601 with space in the middle instead of T. - return date($this->dateFormat($part), $time); + return gmdate($this->dateFormat($part), $time); } } \ No newline at end of file diff --git a/lib/Misc/DateFormatter.php b/lib/Misc/DateFormatter.php new file mode 100644 index 00000000..55438f5c --- /dev/null +++ b/lib/Misc/DateFormatter.php @@ -0,0 +1,44 @@ +dateNormalize($date); + $format = strtolower($format); + if($format=="unix") return $date; + switch ($format) { + case 'http': $f = "D, d M Y H:i:s \G\M\T"; break; + case 'iso8601': $f = \DateTime::ATOM; break; + case 'sql': $f = "Y-m-d H:i:s"; break; + case 'date': $f = "Y-m-d"; break; + case 'time': $f = "H:i:s"; break; + default: $f = \DateTime::ATOM; break; + } + if($local) { + return date($f, $date); + } else { + return gmdate($f, $date); + } + } + + protected function dateNormalize($date) { + // convert input to a Unix timestamp + if($date instanceof \DateTimeInterface) { + $time = $date->getTimestamp(); + } else if(is_numeric($date)) { + $time = (int) $date; + } else if($date===null) { + return null; + } else if(is_string($date)) { + $time = strtotime($date); + if($time===false) return null; + } else if (is_bool($date)) { + return null; + } else { + $time = (int) $date; + } + return $time; + } +} \ No newline at end of file diff --git a/tests/Feed/TestFeed.php b/tests/Feed/TestFeed.php new file mode 100644 index 00000000..caeac1af --- /dev/null +++ b/tests/Feed/TestFeed.php @@ -0,0 +1,63 @@ +clearData(); + Data::$conf = new Conf(); + } + + function testComputeNextFetchFrom304() { + // if less than half an hour, check in 15 minutes + $exp = strtotime("now + 15 minutes"); + $t = strtotime("now"); + $f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http")); + $this->assertTime($exp, $f->nextFetch); + $t = strtotime("now - 29 minutes"); + $f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http")); + $this->assertTime($exp, $f->nextFetch); + // if less than an hour, check in 30 minutes + $exp = strtotime("now + 30 minutes"); + $t = strtotime("now - 30 minutes"); + $f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http")); + $this->assertTime($exp, $f->nextFetch); + $t = strtotime("now - 59 minutes"); + $f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http")); + $this->assertTime($exp, $f->nextFetch); + // if less than three hours, check in an hour + $exp = strtotime("now + 1 hour"); + $t = strtotime("now - 1 hour"); + $f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http")); + $this->assertTime($exp, $f->nextFetch); + $t = strtotime("now - 2 hours 59 minutes"); + $f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http")); + $this->assertTime($exp, $f->nextFetch); + // if more than 36 hours, check in 24 hours + $exp = strtotime("now + 1 day"); + $t = strtotime("now - 36 hours"); + $f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http")); + $this->assertTime($exp, $f->nextFetch); + $t = strtotime("now - 2 years"); + $f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http")); + $this->assertTime($exp, $f->nextFetch); + // otherwise check in three hours + $exp = strtotime("now + 3 hours"); + $t = strtotime("now - 6 hours"); + $f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http")); + $this->assertTime($exp, $f->nextFetch); + $t = strtotime("now - 35 hours"); + $f = new Feed(null, $this->base."NextFetch/NotModified?t=$t", $this->dateTransform($t, "http")); + $this->assertTime($exp, $f->nextFetch); + } +} \ No newline at end of file diff --git a/tests/docroot/Feed/NextFetch/NotModified.php b/tests/docroot/Feed/NextFetch/NotModified.php new file mode 100644 index 00000000..865659b6 --- /dev/null +++ b/tests/docroot/Feed/NextFetch/NotModified.php @@ -0,0 +1,4 @@ + 304, + 'lastMod' => (int) $_GET['t'], +]; \ No newline at end of file diff --git a/tests/lib/Tools.php b/tests/lib/Tools.php index a79d3fda..1ffd1270 100644 --- a/tests/lib/Tools.php +++ b/tests/lib/Tools.php @@ -5,6 +5,8 @@ use JKingWeb\Arsse\Exception; use JKingWeb\Arsse\Data; trait Tools { + use \JKingWeb\Arsse\Misc\DateFormatter; + function assertException(string $msg, string $prefix = "", string $type = "Exception") { $class = \JKingWeb\Arsse\NS_BASE . ($prefix !== "" ? str_replace("/", "\\", $prefix) . "\\" : "") . $type; $msgID = ($prefix !== "" ? $prefix . "/" : "") . $type. ".$msg"; @@ -17,6 +19,12 @@ trait Tools { $this->expectExceptionCode($code); } + function assertTime($exp, $test) { + $exp = $this->dateTransform($exp); + $test = $this->dateTransform($test); + $this->assertSame($exp, $test); + } + function clearData(bool $loadLang = true): bool { $r = new \ReflectionClass(\JKingWeb\Arsse\Data::class); $props = array_keys($r->getStaticProperties()); diff --git a/tests/phpunit.xml b/tests/phpunit.xml index b235701b..83fd0b38 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -43,5 +43,8 @@ REST/NextCloudNews/TestNCNVersionDiscovery.php REST/NextCloudNews/TestNCNV1_2.php + + Feed/TestFeed.php + \ No newline at end of file diff --git a/tests/server.php b/tests/server.php new file mode 100644 index 00000000..c80b14d8 --- /dev/null +++ b/tests/server.php @@ -0,0 +1,66 @@ + + +It is used to test feed parsing in a controlled environment, +answering specific requests used in tests with the data required +to pass the test. + +The parameters of the responses are kept in separate files, +which include the following data: + +- Response content +- Response code +- Content type +- Whether to send cache headers +- Last modified +- Any other headers + +*/ + + +$defaults = [ // default values for response + 'code' => 200, + 'content' => "", + 'mime' => "application/octet-stream", + 'lastMod' => time(), + 'cache' => true, + 'fields' => [], +]; + +$url = explode("?",$_SERVER['REQUEST_URI'])[0]; +$base = BASE."tests".\DIRECTORY_SEPARATOR."docroot"; +$test = $base.str_replace("/",\DIRECTORY_SEPARATOR,$url).".php"; +if(!file_exists($test)) { + $response = [ + 'code' => 499, + 'content' => "Test '$test' missing.", + 'mime' => "application/octet-stream", + 'lastMod' => time(), + 'cache' => true, + 'fields' => [], + ]; +} else { + $response = array_merge($defaults, (include $test)); +} +// set the response code +http_response_code((int) $response['code']); +// if the response has a body, set the content type and (possibly) the ETag. +if(strlen($response['content'])) { + header("Content-Type: ".$response['mime']); + if($response['cache']) header("ETag: ".md5($response['content'])); +} +// if caching is enabled, set the last-modified date +if($response['cache']) header("Last-Modified: ".gmdate("D, d M Y H:i:s \G\M\T", $response['lastMod'])); +// set any other specified fields verbatim +foreach($response['fields'] as $h) { + header($h); +} +// send the content +echo $response['content']; \ No newline at end of file diff --git a/tests/test.bat b/tests/test.bat new file mode 100644 index 00000000..819b0aa6 --- /dev/null +++ b/tests/test.bat @@ -0,0 +1,10 @@ +@echo off +setlocal +set base=%~dp0 +start php -S localhost:8000 "%base%\server.php" +php "%base%\..\vendor\phpunit\phpunit\phpunit" -c "%base%\phpunit.xml" +timeout /nobreak /t 1 >nul +for /f "usebackq tokens=5" %%a in (`netstat -aon ^| find "LISTENING" ^| find ":8000"`) do ( + taskkill /pid %%a >nul + goto :eof +) \ No newline at end of file