From f1e33f3ada31b585fddcc7dbfb9f09ef5fb13259 Mon Sep 17 00:00:00 2001 From: Donald Szeto Date: Thu, 13 Sep 2018 11:19:54 -0700 Subject: [PATCH] [PIO-163] Travis fixes Also include ASF license fixes and PSR-2 --- .travis.yml | 17 + build.xml | 15 + composer.json | 2 +- composer.lock | 404 +++++++++++---- examples/ItemrankImport.php | 39 +- examples/ItemrankQuery.php | 22 +- examples/SampleEvent.php | 117 +++-- phpunit.xml.dist | 15 + src/predictionio/BaseClient.php | 111 +++-- src/predictionio/EngineClient.php | 56 ++- src/predictionio/EventClient.php | 509 ++++++++++--------- src/predictionio/Exporter.php | 39 +- src/predictionio/FileExporter.php | 30 +- src/predictionio/PredictionIOAPIError.php | 22 +- tests/Unit/EngineClientTest.php | 79 +-- tests/Unit/EventClientTest.php | 581 ++++++++++++---------- tests/Unit/ExporterTest.php | 60 ++- tests/Unit/FileExporterTest.php | 47 +- 18 files changed, 1346 insertions(+), 819 deletions(-) diff --git a/.travis.yml b/.travis.yml index d8c9e70..b10fe09 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,17 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. language: php php: - 7.2 @@ -9,3 +23,6 @@ before_script: - pear install phing/phing - phpenv rehash - phing + - composer install +script: + - phing test diff --git a/build.xml b/build.xml index fdb6fcf..309634f 100644 --- a/build.xml +++ b/build.xml @@ -1,5 +1,20 @@ + + diff --git a/composer.json b/composer.json index 19b745d..917e5b6 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ }, "require-dev": { "symfony/class-loader": "^2.3", - "phpunit/phpunit": "^4.7", + "phpunit/phpunit": "^5", "apigen/apigen": "^4.1.2" }, "autoload": { diff --git a/composer.lock b/composer.lock index 518a120..09c15f2 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4a82d4080e44a89330d5e6268a08e601", + "content-hash": "bae15d857f4a61c45b8021628d1b2f72", "packages": [ { "name": "guzzlehttp/guzzle", @@ -464,32 +464,32 @@ }, { "name": "doctrine/instantiator", - "version": "1.1.0", + "version": "1.0.5", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda" + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda", - "reference": "185b8868aa9bf7159f5f953ed5afb2d7fcdc3bda", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d", + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d", "shasum": "" }, "require": { - "php": "^7.1" + "php": ">=5.3,<8.0-DEV" }, "require-dev": { "athletic/athletic": "~0.1.8", "ext-pdo": "*", "ext-phar": "*", - "phpunit/phpunit": "^6.2.3", - "squizlabs/php_codesniffer": "^3.0.2" + "phpunit/phpunit": "~4.0", + "squizlabs/php_codesniffer": "~2.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.2.x-dev" + "dev-master": "1.0.x-dev" } }, "autoload": { @@ -514,7 +514,7 @@ "constructor", "instantiate" ], - "time": "2017-07-22T11:58:36+00:00" + "time": "2015-06-14T21:17:01+00:00" }, { "name": "herrera-io/json", @@ -977,6 +977,51 @@ ], "time": "2018-01-15T00:49:33+00:00" }, + { + "name": "myclabs/deep-copy", + "version": "1.7.0", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e", + "reference": "3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "require-dev": { + "doctrine/collections": "^1.0", + "doctrine/common": "^2.6", + "phpunit/phpunit": "^4.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + }, + "files": [ + "src/DeepCopy/deep_copy.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "time": "2017-10-19T19:58:43+00:00" + }, { "name": "nette/application", "version": "v2.4.12", @@ -1604,21 +1649,21 @@ }, { "name": "nette/php-generator", - "version": "v3.0.5", + "version": "v2.6.4", "source": { "type": "git", "url": "https://github.com/nette/php-generator.git", - "reference": "ea90209c2e8a7cd087b2742ca553c047a8df5eff" + "reference": "c1f6b2163c5471c4d94cd94b93362f12bceef183" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nette/php-generator/zipball/ea90209c2e8a7cd087b2742ca553c047a8df5eff", - "reference": "ea90209c2e8a7cd087b2742ca553c047a8df5eff", + "url": "https://api.github.com/repos/nette/php-generator/zipball/c1f6b2163c5471c4d94cd94b93362f12bceef183", + "reference": "c1f6b2163c5471c4d94cd94b93362f12bceef183", "shasum": "" }, "require": { "nette/utils": "^2.4.2 || ~3.0.0", - "php": ">=7.0" + "php": ">=5.6.0" }, "conflict": { "nette/nette": "<2.2" @@ -1630,7 +1675,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-master": "2.6-dev" } }, "autoload": { @@ -1654,7 +1699,7 @@ "homepage": "https://nette.org/contributors" } ], - "description": "🐘 Nette PHP Generator: generates neat PHP code for you. Supports new PHP 7.2 features.", + "description": "🐘 Nette PHP Generator: generates neat PHP code for you. Supports new PHP 7.1 features.", "homepage": "https://nette.org", "keywords": [ "code", @@ -1662,7 +1707,7 @@ "php", "scaffolding" ], - "time": "2018-08-09T14:32:27+00:00" + "time": "2018-04-26T16:47:39+00:00" }, { "name": "nette/reflection", @@ -1993,35 +2038,29 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "4.3.0", + "version": "3.3.2", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "94fd0001232e47129dd3504189fa1c7225010d08" + "reference": "bf329f6c1aadea3299f08ee804682b7c45b326a2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/94fd0001232e47129dd3504189fa1c7225010d08", - "reference": "94fd0001232e47129dd3504189fa1c7225010d08", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/bf329f6c1aadea3299f08ee804682b7c45b326a2", + "reference": "bf329f6c1aadea3299f08ee804682b7c45b326a2", "shasum": "" }, "require": { - "php": "^7.0", + "php": "^5.6 || ^7.0", "phpdocumentor/reflection-common": "^1.0.0", "phpdocumentor/type-resolver": "^0.4.0", "webmozart/assert": "^1.0" }, "require-dev": { - "doctrine/instantiator": "~1.0.5", - "mockery/mockery": "^1.0", - "phpunit/phpunit": "^6.4" + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^4.4" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.x-dev" - } - }, "autoload": { "psr-4": { "phpDocumentor\\Reflection\\": [ @@ -2040,7 +2079,7 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2017-11-30T07:14:17+00:00" + "time": "2017-11-10T14:09:06+00:00" }, { "name": "phpdocumentor/type-resolver", @@ -2154,39 +2193,40 @@ }, { "name": "phpunit/php-code-coverage", - "version": "2.2.4", + "version": "4.0.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979" + "reference": "ef7b2f56815df854e66ceaee8ebe9393ae36a40d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/eabf68b476ac7d0f73793aada060f1c1a9bf8979", - "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/ef7b2f56815df854e66ceaee8ebe9393ae36a40d", + "reference": "ef7b2f56815df854e66ceaee8ebe9393ae36a40d", "shasum": "" }, "require": { - "php": ">=5.3.3", - "phpunit/php-file-iterator": "~1.3", - "phpunit/php-text-template": "~1.2", - "phpunit/php-token-stream": "~1.3", - "sebastian/environment": "^1.3.2", - "sebastian/version": "~1.0" + "ext-dom": "*", + "ext-xmlwriter": "*", + "php": "^5.6 || ^7.0", + "phpunit/php-file-iterator": "^1.3", + "phpunit/php-text-template": "^1.2", + "phpunit/php-token-stream": "^1.4.2 || ^2.0", + "sebastian/code-unit-reverse-lookup": "^1.0", + "sebastian/environment": "^1.3.2 || ^2.0", + "sebastian/version": "^1.0 || ^2.0" }, "require-dev": { - "ext-xdebug": ">=2.1.4", - "phpunit/phpunit": "~4" + "ext-xdebug": "^2.1.4", + "phpunit/phpunit": "^5.7" }, "suggest": { - "ext-dom": "*", - "ext-xdebug": ">=2.2.1", - "ext-xmlwriter": "*" + "ext-xdebug": "^2.5.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.2.x-dev" + "dev-master": "4.0.x-dev" } }, "autoload": { @@ -2212,7 +2252,7 @@ "testing", "xunit" ], - "time": "2015-10-06T15:47:00+00:00" + "time": "2017-04-02T07:44:40+00:00" }, { "name": "phpunit/php-file-iterator", @@ -2402,40 +2442,50 @@ }, { "name": "phpunit/phpunit", - "version": "4.8.36", + "version": "5.7.27", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "46023de9a91eec7dfb06cc56cb4e260017298517" + "reference": "b7803aeca3ccb99ad0a506fa80b64cd6a56bbc0c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/46023de9a91eec7dfb06cc56cb4e260017298517", - "reference": "46023de9a91eec7dfb06cc56cb4e260017298517", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/b7803aeca3ccb99ad0a506fa80b64cd6a56bbc0c", + "reference": "b7803aeca3ccb99ad0a506fa80b64cd6a56bbc0c", "shasum": "" }, "require": { "ext-dom": "*", "ext-json": "*", - "ext-pcre": "*", - "ext-reflection": "*", - "ext-spl": "*", - "php": ">=5.3.3", - "phpspec/prophecy": "^1.3.1", - "phpunit/php-code-coverage": "~2.1", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", + "myclabs/deep-copy": "~1.3", + "php": "^5.6 || ^7.0", + "phpspec/prophecy": "^1.6.2", + "phpunit/php-code-coverage": "^4.0.4", "phpunit/php-file-iterator": "~1.4", "phpunit/php-text-template": "~1.2", "phpunit/php-timer": "^1.0.6", - "phpunit/phpunit-mock-objects": "~2.3", - "sebastian/comparator": "~1.2.2", - "sebastian/diff": "~1.2", - "sebastian/environment": "~1.3", - "sebastian/exporter": "~1.2", - "sebastian/global-state": "~1.0", - "sebastian/version": "~1.0", - "symfony/yaml": "~2.1|~3.0" + "phpunit/phpunit-mock-objects": "^3.2", + "sebastian/comparator": "^1.2.4", + "sebastian/diff": "^1.4.3", + "sebastian/environment": "^1.3.4 || ^2.0", + "sebastian/exporter": "~2.0", + "sebastian/global-state": "^1.1", + "sebastian/object-enumerator": "~2.0", + "sebastian/resource-operations": "~1.0", + "sebastian/version": "^1.0.6|^2.0.1", + "symfony/yaml": "~2.1|~3.0|~4.0" + }, + "conflict": { + "phpdocumentor/reflection-docblock": "3.0.2" + }, + "require-dev": { + "ext-pdo": "*" }, "suggest": { + "ext-xdebug": "*", "phpunit/php-invoker": "~1.1" }, "bin": [ @@ -2444,7 +2494,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.8.x-dev" + "dev-master": "5.7.x-dev" } }, "autoload": { @@ -2470,30 +2520,33 @@ "testing", "xunit" ], - "time": "2017-06-21T08:07:12+00:00" + "time": "2018-02-01T05:50:59+00:00" }, { "name": "phpunit/phpunit-mock-objects", - "version": "2.3.8", + "version": "3.4.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983" + "reference": "a23b761686d50a560cc56233b9ecf49597cc9118" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/ac8e7a3db35738d56ee9a76e78a4e03d97628983", - "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/a23b761686d50a560cc56233b9ecf49597cc9118", + "reference": "a23b761686d50a560cc56233b9ecf49597cc9118", "shasum": "" }, "require": { "doctrine/instantiator": "^1.0.2", - "php": ">=5.3.3", - "phpunit/php-text-template": "~1.2", - "sebastian/exporter": "~1.2" + "php": "^5.6 || ^7.0", + "phpunit/php-text-template": "^1.2", + "sebastian/exporter": "^1.2 || ^2.0" + }, + "conflict": { + "phpunit/phpunit": "<5.4.0" }, "require-dev": { - "phpunit/phpunit": "~4.4" + "phpunit/phpunit": "^5.4" }, "suggest": { "ext-soap": "*" @@ -2501,7 +2554,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.3.x-dev" + "dev-master": "3.2.x-dev" } }, "autoload": { @@ -2526,7 +2579,7 @@ "mock", "xunit" ], - "time": "2015-10-02T06:51:40+00:00" + "time": "2017-06-30T09:13:00+00:00" }, { "name": "psr/log", @@ -2575,6 +2628,51 @@ ], "time": "2016-10-10T12:19:37+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", @@ -2693,28 +2791,28 @@ }, { "name": "sebastian/environment", - "version": "1.3.8", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "be2c607e43ce4c89ecd60e75c6a85c126e754aea" + "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/be2c607e43ce4c89ecd60e75c6a85c126e754aea", - "reference": "be2c607e43ce4c89ecd60e75c6a85c126e754aea", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5795ffe5dc5b02460c3e34222fee8cbe245d8fac", + "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac", "shasum": "" }, "require": { - "php": "^5.3.3 || ^7.0" + "php": "^5.6 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "^4.8 || ^5.0" + "phpunit/phpunit": "^5.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.3.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { @@ -2739,25 +2837,25 @@ "environment", "hhvm" ], - "time": "2016-08-18T05:49:44+00:00" + "time": "2016-11-26T07:53:53+00:00" }, { "name": "sebastian/exporter", - "version": "1.2.2", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "42c4c2eec485ee3e159ec9884f95b431287edde4" + "reference": "ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/42c4c2eec485ee3e159ec9884f95b431287edde4", - "reference": "42c4c2eec485ee3e159ec9884f95b431287edde4", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4", + "reference": "ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4", "shasum": "" }, "require": { "php": ">=5.3.3", - "sebastian/recursion-context": "~1.0" + "sebastian/recursion-context": "~2.0" }, "require-dev": { "ext-mbstring": "*", @@ -2766,7 +2864,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.3.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { @@ -2806,7 +2904,7 @@ "export", "exporter" ], - "time": "2016-06-17T09:04:28+00:00" + "time": "2016-11-19T08:54:04+00:00" }, { "name": "sebastian/global-state", @@ -2859,18 +2957,64 @@ ], "time": "2015-10-12T03:26:01+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": "1.0.5", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "b19cc3298482a335a95f3016d2f8a6950f0fbcd7" + "reference": "2c3ba150cbec723aa057506e73a8d33bdb286c9a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/b19cc3298482a335a95f3016d2f8a6950f0fbcd7", - "reference": "b19cc3298482a335a95f3016d2f8a6950f0fbcd7", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/2c3ba150cbec723aa057506e73a8d33bdb286c9a", + "reference": "2c3ba150cbec723aa057506e73a8d33bdb286c9a", "shasum": "" }, "require": { @@ -2882,7 +3026,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { @@ -2910,23 +3054,73 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2016-10-03T07:41:43+00:00" + "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": "1.0.6", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/version.git", - "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6" + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", - "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", + "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/" @@ -2945,7 +3139,7 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", - "time": "2015-06-21T13:59:46+00:00" + "time": "2016-10-03T07:35:21+00:00" }, { "name": "seld/jsonlint", diff --git a/examples/ItemrankImport.php b/examples/ItemrankImport.php index 4266a7f..4bdd0e5 100644 --- a/examples/ItemrankImport.php +++ b/examples/ItemrankImport.php @@ -1,4 +1,20 @@ setUser($u, array('age'=>20+$u, 'gender'=>'M')); - print_r($response); + $response=$client->setUser($u, array('age'=>20+$u, 'gender'=>'M')); + print_r($response); } // set item - generate 50 items for ($i=1; $i<=50; $i++) { - $response=$client->setItem($i, array('itypes'=>array('1'))); - print_r($response); + $response=$client->setItem($i, array('itypes'=>array('1'))); + print_r($response); } // record event - each user randomly views 10 items for ($u=1; $u<=10; $u++) { - for ($count=0; $count<10; $count++) { - $i = rand(1,50); - $response=$client->recordUserActionOnItem('view', $u, $i); - print_r($response); - } -} - - -?> + for ($count=0; $count<10; $count++) { + $i = rand(1, 50); + $response=$client->recordUserActionOnItem('view', $u, $i); + print_r($response); + } +} diff --git a/examples/ItemrankQuery.php b/examples/ItemrankQuery.php index 2d06346..0598a51 100644 --- a/examples/ItemrankQuery.php +++ b/examples/ItemrankQuery.php @@ -1,4 +1,20 @@ sendQuery(array('uid'=>$i, 'iids'=>array(1,2,3,4,5))); - print_r($response); + $response=$client->sendQuery(array('uid'=>$i, 'iids'=>array(1,2,3,4,5))); + print_r($response); } - -?> diff --git a/examples/SampleEvent.php b/examples/SampleEvent.php index b41fc07..f813a45 100644 --- a/examples/SampleEvent.php +++ b/examples/SampleEvent.php @@ -1,68 +1,89 @@ getStatus(); - echo($response); + // check Event Server status + $client = new EventClient( + "j4jIdbq59JsF2f4CXwwkIiVHNFnyNvWXqMqXxcIbQDqFRz5K0fe9e3QfqjKwvW3O" + ); + $response=$client->getStatus(); + echo($response); - // set user with event time - $response=$client->setUser(9, array('age'=>10), - '2014-01-01T10:20:30.400+08:00'); - print_r($response); + // set user with event time + $response=$client->setUser( + 9, + array('age'=>10), + '2014-01-01T10:20:30.400+08:00' + ); + print_r($response); - // set user - $response=$client->setUser(8, array('age'=>20, 'gender'=>'M')); - print_r($response); + // set user + $response=$client->setUser(8, array('age'=>20, 'gender'=>'M')); + print_r($response); - // unset user - $response=$client->unsetUser(8, array('age'=>20)); - print_r($response); + // unset user + $response=$client->unsetUser(8, array('age'=>20)); + print_r($response); - // delete user - $response=$client->deleteUser(9); - print_r($response); - - // set item with event time - $response=$client->setItem(3, array('itypes'=>array('1')), - '2013-12-20T05:15:25.350+08:00'); - print_r($response); + // delete user + $response=$client->deleteUser(9); + print_r($response); - // set item - $response=$client->setItem(2, array('itypes'=>array('1'))); - print_r($response); + // set item with event time + $response=$client->setItem( + 3, + array('itypes'=>array('1')), + '2013-12-20T05:15:25.350+08:00' + ); + print_r($response); - // unset item - $response=$client->unsetItem(2, array('itypes'=>array('1'))); - print_r($response); + // set item + $response=$client->setItem(2, array('itypes'=>array('1'))); + print_r($response); - // delete item - $response=$client->deleteItem(3, '2000-01-01T01:01:01.001+01:00'); - print_r($response); + // unset item + $response=$client->unsetItem(2, array('itypes'=>array('1'))); + print_r($response); - // record user action on item - $response=$client->recordUserActionOnItem('view', 8, 2); - print_r($response); + // delete item + $response=$client->deleteItem(3, '2000-01-01T01:01:01.001+01:00'); + print_r($response); - // create event - $response=$client->createEvent(array( - 'event' => 'my_event', - 'entityType' => 'user', - 'entityId' => '8', - 'properties' => array('prop1'=>1, 'prop2'=>2), - )); - print_r($response); + // record user action on item + $response=$client->recordUserActionOnItem('view', 8, 2); + print_r($response); - // get event - $response=$client->getEvent('U_7eotSbeeK0BwshqEfRFAAAAUm-8gOyjP3FR73aBFo'); - print_r($response); + // create event + $response=$client->createEvent(array( + 'event' => 'my_event', + 'entityType' => 'user', + 'entityId' => '8', + 'properties' => array('prop1'=>1, 'prop2'=>2), + )); + print_r($response); + // get event + $response=$client->getEvent('U_7eotSbeeK0BwshqEfRFAAAAUm-8gOyjP3FR73aBFo'); + print_r($response); } catch (PredictionIOAPIError $e) { - echo $e->getMessage(); + echo $e->getMessage(); } -?> diff --git a/phpunit.xml.dist b/phpunit.xml.dist index d313305..80c60eb 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,20 @@ + + baseUrl = $baseUrl; - $this->client = new Client([ + /** + * @param string $baseUrl Base URL to the server + * @param float $timeout Timeout of the request in seconds. Use 0 to wait indefinitely + * @param float $connectTimeout Number of seconds to wait while trying to connect to a server + */ + public function __construct($baseUrl, $timeout, $connectTimeout) + { + $this->baseUrl = $baseUrl; + $this->client = new Client([ 'base_uri' => $this->baseUrl, 'timeout' => $timeout, 'connect_timeout' => $connectTimeout - ]); - - } + ]); + } - /** - * Get the status of the Event Server or Engine Instance - * - * @return string status - */ - public function getStatus() { - return $this->client->get('/')->getBody(); - } + /** + * Get the status of the Event Server or Engine Instance + * + * @return string status + */ + public function getStatus() + { + return $this->client->get('/')->getBody(); + } - /** - * Send a HTTP request to the server - * - * @param string $method HTTP request method - * @param string $url Relative or absolute url - * @param string $body HTTP request body - * - * @return array JSON response - * @throws PredictionIOAPIError Request error - */ - protected function sendRequest($method, $url, $body) { - $options = [ - 'headers' => [ - 'Accept-Encoding' => 'gzip', - 'Content-Type' => 'application/json', - ], - 'body' => $body, - ]; + /** + * Send a HTTP request to the server + * + * @param string $method HTTP request method + * @param string $url Relative or absolute url + * @param string $body HTTP request body + * + * @return array JSON response + * @throws PredictionIOAPIError Request error + */ + protected function sendRequest($method, $url, $body) + { + $options = [ + 'headers' => [ + 'Accept-Encoding' => 'gzip', + 'Content-Type' => 'application/json', + ], + 'body' => $body, + ]; - try { - $response = $this->client->request($method, $url, $options); - return json_decode($response->getBody(), true); - } catch (ClientException $e) { - throw new PredictionIOAPIError($e->getMessage()); + try { + $response = $this->client->request($method, $url, $options); + return json_decode($response->getBody(), true); + } catch (ClientException $e) { + throw new PredictionIOAPIError($e->getMessage()); + } } - } } -?> diff --git a/src/predictionio/EngineClient.php b/src/predictionio/EngineClient.php index f45ac35..7355937 100644 --- a/src/predictionio/EngineClient.php +++ b/src/predictionio/EngineClient.php @@ -1,12 +1,28 @@ sendRequest("POST", "/queries.json", json_encode($query)); - } + /** + * Send prediction query to an Engine Instance + * + * @param array Query + * + * @return array JSON response + * + * @throws PredictionIOAPIError Request error + */ + public function sendQuery(array $query) + { + return $this->sendRequest("POST", "/queries.json", json_encode($query)); + } } - -?> diff --git a/src/predictionio/EventClient.php b/src/predictionio/EventClient.php index df4286f..7a31bc7 100644 --- a/src/predictionio/EventClient.php +++ b/src/predictionio/EventClient.php @@ -1,267 +1,310 @@ accessKey = $accessKey; - $this->eventUrl = "/events.json?accessKey=$this->accessKey"; - } + /** + * @param string Access Key + * @param string Base URL to the Event Server. Default is localhost:7070. + * @param float Timeout of the request in seconds. Use 0 to wait indefinitely + * Default is 0. + * @param float Number of seconds to wait while trying to connect to a server. + * Default is 5. + */ + public function __construct( + $accessKey, + $baseUrl='http://localhost:7070', + $timeout=0, + $connectTimeout=5 + ) { + parent::__construct($baseUrl, $timeout, $connectTimeout); + $this->accessKey = $accessKey; + $this->eventUrl = "/events.json?accessKey=$this->accessKey"; + } - private function getEventTime($eventTime) { - $result = $eventTime; - if (!isset($eventTime)) { - $result = (new DateTime('NOW'))->format(self::DATE_TIME_FORMAT); - } + private function getEventTime($eventTime) + { + $result = $eventTime; + if (!isset($eventTime)) { + $result = (new DateTime('NOW'))->format(self::DATE_TIME_FORMAT); + } - return $result; - } + return $result; + } - /** - * Set a user entity - * - * @param int|string User Id - * @param array Properties of the user entity to set - * @param string Time of the event in ISO 8601 format - * (e.g. 2014-09-09T16:17:42.937-08:00). - * Default is the current time. - * - * @return string JSON response - * - * @throws PredictionIOAPIError Request error - */ - public function setUser($uid, array $properties=array(), $eventTime=null) { - $eventTime = $this->getEventTime($eventTime); + /** + * Set a user entity + * + * @param int|string User Id + * @param array Properties of the user entity to set + * @param string Time of the event in ISO 8601 format + * (e.g. 2014-09-09T16:17:42.937-08:00). + * Default is the current time. + * + * @return string JSON response + * + * @throws PredictionIOAPIError Request error + */ + public function setUser($uid, array $properties=array(), $eventTime=null) + { + $eventTime = $this->getEventTime($eventTime); - // casting to object so that an empty array would be represented as {} - if (empty($properties)) $properties = (object)$properties; + // casting to object so that an empty array would be represented as {} + if (empty($properties)) { + $properties = (object)$properties; + } - $json = json_encode([ - 'event' => '$set', - 'entityType' => 'user', - 'entityId' => $uid, - 'properties' => $properties, - 'eventTime' => $eventTime, - ]); + $json = json_encode([ + 'event' => '$set', + 'entityType' => 'user', + 'entityId' => $uid, + 'properties' => $properties, + 'eventTime' => $eventTime, + ]); - return $this->sendRequest('POST', $this->eventUrl, $json); - } + return $this->sendRequest('POST', $this->eventUrl, $json); + } - /** - * Unset a user entity - * - * @param int|string User Id - * @param array Properties of the user entity to unset - * @param string Time of the event in ISO 8601 format - * (e.g. 2014-09-09T16:17:42.937-08:00). - * Default is the current time. - * - * @return string JSON response - * - * @throws PredictionIOAPIError Request error - */ - public function unsetUser($uid, array $properties, $eventTime=null) { - $eventTime = $this->getEventTime($eventTime); - if (empty($properties)) - throw new PredictionIOAPIError('Specify at least one property'); + /** + * Unset a user entity + * + * @param int|string User Id + * @param array Properties of the user entity to unset + * @param string Time of the event in ISO 8601 format + * (e.g. 2014-09-09T16:17:42.937-08:00). + * Default is the current time. + * + * @return string JSON response + * + * @throws PredictionIOAPIError Request error + */ + public function unsetUser($uid, array $properties, $eventTime=null) + { + $eventTime = $this->getEventTime($eventTime); + if (empty($properties)) { + throw new PredictionIOAPIError('Specify at least one property'); + } - $json = json_encode([ - 'event' => '$unset', - 'entityType' => 'user', - 'entityId' => $uid, - 'properties' => $properties, - 'eventTime' => $eventTime, - ]); + $json = json_encode([ + 'event' => '$unset', + 'entityType' => 'user', + 'entityId' => $uid, + 'properties' => $properties, + 'eventTime' => $eventTime, + ]); - return $this->sendRequest('POST', $this->eventUrl, $json); - } + return $this->sendRequest('POST', $this->eventUrl, $json); + } - /** - * Delete a user entity - * - * @param int|string User Id - * @param string Time of the event in ISO 8601 format - * (e.g. 2014-09-09T16:17:42.937-08:00). - * Default is the current time. - * - * @return string JSON response - * - * @throws PredictionIOAPIError Request error - */ - public function deleteUser($uid, $eventTime=null) { - $eventTime = $this->getEventTime($eventTime); + /** + * Delete a user entity + * + * @param int|string User Id + * @param string Time of the event in ISO 8601 format + * (e.g. 2014-09-09T16:17:42.937-08:00). + * Default is the current time. + * + * @return string JSON response + * + * @throws PredictionIOAPIError Request error + */ + public function deleteUser($uid, $eventTime=null) + { + $eventTime = $this->getEventTime($eventTime); - $json = json_encode([ - 'event' => '$delete', - 'entityType' => 'user', - 'entityId' => $uid, - 'eventTime' => $eventTime, - ]); + $json = json_encode([ + 'event' => '$delete', + 'entityType' => 'user', + 'entityId' => $uid, + 'eventTime' => $eventTime, + ]); - return $this->sendRequest('POST', $this->eventUrl, $json); - } - - /** - * Set an item entity - * - * @param int|string Item Id - * @param array Properties of the item entity to set - * @param string Time of the event in ISO 8601 format - * (e.g. 2014-09-09T16:17:42.937-08:00). - * Default is the current time. - * - * @return string JSON response - * - * @throws PredictionIOAPIError Request error - */ - public function setItem($iid, array $properties=array(), $eventTime=null) { - $eventTime = $this->getEventTime($eventTime); - if (empty($properties)) $properties = (object)$properties; - $json = json_encode([ - 'event' => '$set', - 'entityType' => 'item', - 'entityId' => $iid, - 'properties' => $properties, - 'eventTime' => $eventTime, - ]); + return $this->sendRequest('POST', $this->eventUrl, $json); + } - return $this->sendRequest('POST', $this->eventUrl, $json); - } + /** + * Set an item entity + * + * @param int|string Item Id + * @param array Properties of the item entity to set + * @param string Time of the event in ISO 8601 format + * (e.g. 2014-09-09T16:17:42.937-08:00). + * Default is the current time. + * + * @return string JSON response + * + * @throws PredictionIOAPIError Request error + */ + public function setItem($iid, array $properties=array(), $eventTime=null) + { + $eventTime = $this->getEventTime($eventTime); + if (empty($properties)) { + $properties = (object)$properties; + } + $json = json_encode([ + 'event' => '$set', + 'entityType' => 'item', + 'entityId' => $iid, + 'properties' => $properties, + 'eventTime' => $eventTime, + ]); - /** - * Unset an item entity - * - * @param int|string Item Id - * @param array Properties of the item entity to unset - * @param string Time of the event in ISO 8601 format - * (e.g. 2014-09-09T16:17:42.937-08:00). - * Default is the current time. - * - * @return string JSON response - * - * @throws PredictionIOAPIError Request error - */ - public function unsetItem($iid, array $properties, $eventTime=null) { - $eventTime = $this->getEventTime($eventTime); - if (empty($properties)) - throw new PredictionIOAPIError('Specify at least one property'); - $json = json_encode([ - 'event' => '$unset', - 'entityType' => 'item', - 'entityId' => $iid, - 'properties' => $properties, - 'eventTime' => $eventTime, - ]); + return $this->sendRequest('POST', $this->eventUrl, $json); + } - return $this->sendRequest('POST', $this->eventUrl, $json); - } + /** + * Unset an item entity + * + * @param int|string Item Id + * @param array Properties of the item entity to unset + * @param string Time of the event in ISO 8601 format + * (e.g. 2014-09-09T16:17:42.937-08:00). + * Default is the current time. + * + * @return string JSON response + * + * @throws PredictionIOAPIError Request error + */ + public function unsetItem($iid, array $properties, $eventTime=null) + { + $eventTime = $this->getEventTime($eventTime); + if (empty($properties)) { + throw new PredictionIOAPIError('Specify at least one property'); + } + $json = json_encode([ + 'event' => '$unset', + 'entityType' => 'item', + 'entityId' => $iid, + 'properties' => $properties, + 'eventTime' => $eventTime, + ]); - /** - * Delete an item entity - * - * @param int|string Item Id - * @param string Time of the event in ISO 8601 format - * (e.g. 2014-09-09T16:17:42.937-08:00). - * Default is the current time. - * - * @return string JSON response - * - * @throws PredictionIOAPIError Request error - */ - public function deleteItem($iid, $eventTime=null) { - $eventTime = $this->getEventTime($eventTime); + return $this->sendRequest('POST', $this->eventUrl, $json); + } - $json = json_encode([ - 'event' => '$delete', - 'entityType' => 'item', - 'entityId' => $iid, - 'eventTime' => $eventTime, - ]); + /** + * Delete an item entity + * + * @param int|string Item Id + * @param string Time of the event in ISO 8601 format + * (e.g. 2014-09-09T16:17:42.937-08:00). + * Default is the current time. + * + * @return string JSON response + * + * @throws PredictionIOAPIError Request error + */ + public function deleteItem($iid, $eventTime=null) + { + $eventTime = $this->getEventTime($eventTime); - return $this->sendRequest('POST', $this->eventUrl, $json); - } + $json = json_encode([ + 'event' => '$delete', + 'entityType' => 'item', + 'entityId' => $iid, + 'eventTime' => $eventTime, + ]); - /** - * Record a user action on an item - * - * @param string Event name - * @param int|string User Id - * @param int|string Item Id - * @param array Properties of the event - * @param string Time of the event in ISO 8601 format - * (e.g. 2014-09-09T16:17:42.937-08:00). - * Default is the current time. - * - * @return string JSON response - * - * @throws PredictionIOAPIError Request error - */ - public function recordUserActionOnItem($event, $uid, $iid, - array $properties=array(), - $eventTime=null) { - $eventTime = $this->getEventTime($eventTime); - if (empty($properties)) $properties = (object)$properties; - $json = json_encode([ - 'event' => $event, - 'entityType' => 'user', - 'entityId' => $uid, - 'targetEntityType' => 'item', - 'targetEntityId' => $iid, - 'properties' => $properties, - 'eventTime' => $eventTime, - ]); + return $this->sendRequest('POST', $this->eventUrl, $json); + } - return $this->sendRequest('POST', $this->eventUrl, $json); - } + /** + * Record a user action on an item + * + * @param string Event name + * @param int|string User Id + * @param int|string Item Id + * @param array Properties of the event + * @param string Time of the event in ISO 8601 format + * (e.g. 2014-09-09T16:17:42.937-08:00). + * Default is the current time. + * + * @return string JSON response + * + * @throws PredictionIOAPIError Request error + */ + public function recordUserActionOnItem( + $event, + $uid, + $iid, + array $properties=array(), + $eventTime=null + ) { + $eventTime = $this->getEventTime($eventTime); + if (empty($properties)) { + $properties = (object)$properties; + } + $json = json_encode([ + 'event' => $event, + 'entityType' => 'user', + 'entityId' => $uid, + 'targetEntityType' => 'item', + 'targetEntityId' => $iid, + 'properties' => $properties, + 'eventTime' => $eventTime, + ]); - /** - * Create an event - * - * @param array An array describing the event - * - * @return string JSON response - * - * @throws PredictionIOAPIError Request error - */ - public function createEvent(array $data) { - $json = json_encode($data); + return $this->sendRequest('POST', $this->eventUrl, $json); + } - return $this->sendRequest('POST', $this->eventUrl, $json); - } + /** + * Create an event + * + * @param array An array describing the event + * + * @return string JSON response + * + * @throws PredictionIOAPIError Request error + */ + public function createEvent(array $data) + { + $json = json_encode($data); - /** - * Retrieve an event - * - * @param string Event ID - * - * @return string JSON response - * - * @throws PredictionIOAPIError Request error - */ - public function getEvent($eventId) { - return $this->sendRequest('GET', - "/events/$eventId.json?accessKey=$this->accessKey", ''); - } -} + return $this->sendRequest('POST', $this->eventUrl, $json); + } -?> + /** + * Retrieve an event + * + * @param string Event ID + * + * @return string JSON response + * + * @throws PredictionIOAPIError Request error + */ + public function getEvent($eventId) + { + return $this->sendRequest( + 'GET', + "/events/$eventId.json?accessKey=$this->accessKey", + '' + ); + } +} diff --git a/src/predictionio/Exporter.php b/src/predictionio/Exporter.php index 35b7a03..c965dc7 100644 --- a/src/predictionio/Exporter.php +++ b/src/predictionio/Exporter.php @@ -1,13 +1,28 @@ export($json); } - -} \ No newline at end of file +} diff --git a/src/predictionio/FileExporter.php b/src/predictionio/FileExporter.php index d0ee711..8e820dc 100644 --- a/src/predictionio/FileExporter.php +++ b/src/predictionio/FileExporter.php @@ -1,5 +1,20 @@ file = fopen($fileName, 'w'); } - public function export($json) { + public function export($json) + { fwrite($this->file, "$json\n"); } - public function close() { + public function close() + { fclose($this->file); } -} \ No newline at end of file +} diff --git a/src/predictionio/PredictionIOAPIError.php b/src/predictionio/PredictionIOAPIError.php index ca4cacd..b51414f 100644 --- a/src/predictionio/PredictionIOAPIError.php +++ b/src/predictionio/PredictionIOAPIError.php @@ -1,9 +1,25 @@ diff --git a/tests/Unit/EngineClientTest.php b/tests/Unit/EngineClientTest.php index 66c43b9..2f5fbbf 100644 --- a/tests/Unit/EngineClientTest.php +++ b/tests/Unit/EngineClientTest.php @@ -1,4 +1,20 @@ container); - $mock=new MockHandler([new Response(200)]); - $handler=HandlerStack::create($mock); - $handler->push($history); - $this->engineClient=new EngineClient(); - $existingOptions = $this->engineClient->client->getConfig(); - $existingOptions['handler'] = $handler; - $mockClient=new Client($existingOptions); - $this->engineClient->client = $mockClient; - } - - public function testSendQuery() { - $this->engineClient->sendQuery(array('uid'=>5, 'iids'=>array(1,2,3))); - $result=array_shift($this->container); - /** @var Request[] $result['request'] */ - $body=json_decode($result['request']->getBody(), true); - - $this->assertEquals(5,$body['uid']); - $this->assertEquals(array(1,2,3),$body['iids']); - $this->assertEquals('POST',$result['request']->getMethod()); - $this->assertEquals('http://localhost:8000/queries.json',$result['request']->getUri()); - } - +class EngineClientTest extends \PHPUnit_Framework_TestCase +{ + /** @var EngineClient $engineClient */ + protected $engineClient; + protected $container = []; + + protected function setUp() + { + $history=Middleware::History($this->container); + $mock=new MockHandler([new Response(200)]); + $handler=HandlerStack::create($mock); + $handler->push($history); + $this->engineClient=new EngineClient(); + $existingOptions = $this->engineClient->client->getConfig(); + $existingOptions['handler'] = $handler; + $mockClient=new Client($existingOptions); + $this->engineClient->client = $mockClient; + } + + public function testSendQuery() + { + $this->engineClient->sendQuery(array('uid'=>5, 'iids'=>array(1,2,3))); + $result=array_shift($this->container); + /** @var Request[] $result['request'] */ + $body=json_decode($result['request']->getBody(), true); + + $this->assertEquals(5, $body['uid']); + $this->assertEquals(array(1,2,3), $body['iids']); + $this->assertEquals('POST', $result['request']->getMethod()); + $this->assertEquals('http://localhost:8000/queries.json', $result['request']->getUri()); + } } - -?> diff --git a/tests/Unit/EventClientTest.php b/tests/Unit/EventClientTest.php index 7a463ff..6c442ea 100644 --- a/tests/Unit/EventClientTest.php +++ b/tests/Unit/EventClientTest.php @@ -1,4 +1,20 @@ container); - $mock=new MockHandler([new Response(200)]); - $handler=HandlerStack::create($mock); - $handler->push($history); - $this->eventClient=new EventClient( - "j4jIdbq59JsF2f4CXwwkIiVHNFnyNvWXqMqXxcIbQDqFRz5K0fe9e3QfqjKwvW3O"); - $existingOptions = $this->eventClient->client->getConfig(); - $existingOptions['handler'] = $handler; - $mockClient=new Client($existingOptions); - $this->eventClient->client = $mockClient; - } - - public function testSetUser() { - $this->eventClient->setUser(1,array('age'=>20)); - $result=array_shift($this->container); - /** @var Request $request */ - $request=$result['request']; - $body=json_decode($request->getBody(), true); - - $this->assertEquals('$set',$body['event']); - $this->assertEquals('user',$body['entityType']); - $this->assertEquals(1,$body['entityId']); - $this->assertEquals(20,$body['properties']['age']); - $this->assertNotNull($body['eventTime']); - $this->assertEquals('POST',$request->getMethod()); - $this->assertEquals('http://localhost:7070/events.json?accessKey=j4jIdbq59JsF2f4CXwwkIiVHNFnyNvWXqMqXxcIbQDqFRz5K0fe9e3QfqjKwvW3O',$request->getUri()); - } - - public function testSetUserWithEventTime() { - $eventTime='1982-09-25T01:23:45+0800'; - - $this->eventClient->setUser(1,array('age'=>20), $eventTime); - $result=array_shift($this->container); - /** @var Request $request */ - $request=$result['request']; - $body=json_decode($request->getBody(), true); - - $this->assertEquals('$set',$body['event']); - $this->assertEquals($eventTime, $body['eventTime']); - } - - public function testUnsetUser() { - $this->eventClient->unsetUser(1,array('age'=>20)); - $result=array_shift($this->container); - /** @var Request $request */ - $request=$result['request']; - $body=json_decode($request->getBody(), true); - - $this->assertEquals('$unset',$body['event']); - $this->assertEquals('user',$body['entityType']); - $this->assertEquals(1,$body['entityId']); - $this->assertEquals(20,$body['properties']['age']); - $this->assertNotNull($body['eventTime']); - $this->assertEquals('POST',$request->getMethod()); - $this->assertEquals('http://localhost:7070/events.json?accessKey=j4jIdbq59JsF2f4CXwwkIiVHNFnyNvWXqMqXxcIbQDqFRz5K0fe9e3QfqjKwvW3O',$request->getUri()); - } - - public function testUnsetUserWithEventTime() { - $eventTime='1982-09-25T01:23:45+0800'; - - $this->eventClient->unsetUser(1,array('age'=>20), $eventTime); - $result=array_shift($this->container); - /** @var Request $request */ - $request=$result['request']; - $body=json_decode($request->getBody(), true); - - $this->assertEquals('$unset',$body['event']); - $this->assertEquals($eventTime, $body['eventTime']); - } - - /** - * @expectedException \predictionio\PredictionIOAPIError - */ - public function testUnsetUserWithoutProperties() { - $this->eventClient->unsetUser(1, array()); - } - - public function testDeleteUser() { - $this->eventClient->deleteUser(1); - $result=array_shift($this->container); - /** @var Request $request */ - $request=$result['request']; - $body=json_decode($request->getBody(), true); - - $this->assertEquals('$delete',$body['event']); - $this->assertEquals('user',$body['entityType']); - $this->assertEquals(1,$body['entityId']); - $this->assertNotNull($body['eventTime']); - $this->assertEquals('POST',$request->getMethod()); - $this->assertEquals('http://localhost:7070/events.json?accessKey=j4jIdbq59JsF2f4CXwwkIiVHNFnyNvWXqMqXxcIbQDqFRz5K0fe9e3QfqjKwvW3O',$request->getUri()); - } - - public function testDeleteUserWithEventTime() { - $eventTime='1982-09-25T01:23:45+0800'; - - $this->eventClient->deleteUser(1, $eventTime); - $result=array_shift($this->container); - /** @var Request $request */ - $request=$result['request']; - $body=json_decode($request->getBody(), true); - - $this->assertEquals('$delete',$body['event']); - $this->assertEquals($eventTime, $body['eventTime']); - } - - public function testSetItem() { - $this->eventClient->setItem(1,array('type'=>'book')); - $result=array_shift($this->container); - /** @var Request $request */ - $request=$result['request']; - $body=json_decode($request->getBody(), true); - - $this->assertEquals('$set',$body['event']); - $this->assertEquals('item',$body['entityType']); - $this->assertEquals(1,$body['entityId']); - $this->assertEquals('book',$body['properties']['type']); - $this->assertNotNull($body['eventTime']); - $this->assertEquals('POST',$request->getMethod()); - $this->assertEquals('http://localhost:7070/events.json?accessKey=j4jIdbq59JsF2f4CXwwkIiVHNFnyNvWXqMqXxcIbQDqFRz5K0fe9e3QfqjKwvW3O',$request->getUri()); - } - - public function testSetItemWithEventTime() { - $eventTime='1982-09-25T01:23:45+0800'; - - $this->eventClient->setItem(1,array('type'=>'book'), $eventTime); - $result=array_shift($this->container); - /** @var Request $request */ - $request=$result['request']; - $body=json_decode($request->getBody(), true); - - $this->assertEquals('$set',$body['event']); - $this->assertEquals($eventTime, $body['eventTime']); - } - - public function testUnsetItem() { - $this->eventClient->unsetItem(1,array('type'=>'book')); - $result=array_shift($this->container); - /** @var Request $request */ - $request=$result['request']; - $body=json_decode($request->getBody(), true); - - $this->assertEquals('$unset',$body['event']); - $this->assertEquals('item',$body['entityType']); - $this->assertEquals(1,$body['entityId']); - $this->assertEquals('book',$body['properties']['type']); - $this->assertNotNull($body['eventTime']); - $this->assertEquals('POST',$request->getMethod()); - $this->assertEquals('http://localhost:7070/events.json?accessKey=j4jIdbq59JsF2f4CXwwkIiVHNFnyNvWXqMqXxcIbQDqFRz5K0fe9e3QfqjKwvW3O',$request->getUri()); - } - - public function testUnsetItemWithEventTime() { - $eventTime='1982-09-25T01:23:45+0800'; - - $this->eventClient->unsetItem(1,array('type'=>'book'), $eventTime); - $result=array_shift($this->container); - /** @var Request $request */ - $request=$result['request']; - $body=json_decode($request->getBody(), true); - - $this->assertEquals('$unset',$body['event']); - $this->assertEquals($eventTime, $body['eventTime']); - } - - /** - * @expectedException \predictionio\PredictionIOAPIError - */ - public function testUnsetItemWithoutProperties() { - $this->eventClient->unsetItem(1, array()); - } - - public function testDeleteItem() { - $this->eventClient->deleteItem(1); - $result=array_shift($this->container); - /** @var Request $request */ - $request=$result['request']; - $body=json_decode($request->getBody(), true); - - $this->assertEquals('$delete',$body['event']); - $this->assertEquals('item',$body['entityType']); - $this->assertEquals(1,$body['entityId']); - $this->assertNotNull($body['eventTime']); - $this->assertEquals('POST',$request->getMethod()); - $this->assertEquals('http://localhost:7070/events.json?accessKey=j4jIdbq59JsF2f4CXwwkIiVHNFnyNvWXqMqXxcIbQDqFRz5K0fe9e3QfqjKwvW3O',$request->getUri()); - } - - public function testDeleteItemWithEventTime() { - $eventTime='1982-09-25T01:23:45+0800'; - - $this->eventClient->deleteItem(1, $eventTime); - $result=array_shift($this->container); - /** @var Request $request */ - $request=$result['request']; - $body=json_decode($request->getBody(), true); - - $this->assertEquals('$delete',$body['event']); - $this->assertEquals($eventTime, $body['eventTime']); - } - - public function testRecordAction() { - $this->eventClient->recordUserActionOnItem('view',1,888, array('count'=>2)); - $result=array_shift($this->container); - /** @var Request $request */ - $request=$result['request']; - $body=json_decode($request->getBody(), true); - - $this->assertEquals('view',$body['event']); - $this->assertEquals('user',$body['entityType']); - $this->assertEquals(1,$body['entityId']); - $this->assertEquals('item',$body['targetEntityType']); - $this->assertEquals(888,$body['targetEntityId']); - $this->assertEquals(2,$body['properties']['count']); - $this->assertNotNull($body['eventTime']); - $this->assertEquals('POST',$request->getMethod()); - $this->assertEquals('http://localhost:7070/events.json?accessKey=j4jIdbq59JsF2f4CXwwkIiVHNFnyNvWXqMqXxcIbQDqFRz5K0fe9e3QfqjKwvW3O',$request->getUri()); - } - - public function testRecordActionWithEventTime() { - $eventTime='1982-09-25T01:23:45+0800'; - - $this->eventClient->recordUserActionOnItem('view',1, 8, array(),$eventTime); - $result=array_shift($this->container); - /** @var Request $request */ - $request=$result['request']; - $body=json_decode($request->getBody(), true); - - $this->assertEquals('view',$body['event']); - $this->assertEquals($eventTime, $body['eventTime']); - } - - public function testCreateEvent() { - $this->eventClient->createEvent(array( +class EventClientTest extends \PHPUnit_Framework_TestCase +{ + /** @var EventClient $eventClient */ + protected $eventClient; + protected $container = []; + + protected function setUp() + { + $history=Middleware::History($this->container); + $mock=new MockHandler([new Response(200)]); + $handler=HandlerStack::create($mock); + $handler->push($history); + $this->eventClient=new EventClient( + "j4jIdbq59JsF2f4CXwwkIiVHNFnyNvWXqMqXxcIbQDqFRz5K0fe9e3QfqjKwvW3O" + ); + $existingOptions = $this->eventClient->client->getConfig(); + $existingOptions['handler'] = $handler; + $mockClient=new Client($existingOptions); + $this->eventClient->client = $mockClient; + } + + public function testSetUser() + { + $this->eventClient->setUser(1, array('age'=>20)); + $result=array_shift($this->container); + /** @var Request $request */ + $request=$result['request']; + $body=json_decode($request->getBody(), true); + + $this->assertEquals('$set', $body['event']); + $this->assertEquals('user', $body['entityType']); + $this->assertEquals(1, $body['entityId']); + $this->assertEquals(20, $body['properties']['age']); + $this->assertNotNull($body['eventTime']); + $this->assertEquals('POST', $request->getMethod()); + $this->assertEquals('http://localhost:7070/events.json?accessKey=j4jIdbq59JsF2f4CXwwkIiVHNFnyNvWXqMqXxcIbQDqFRz5K0fe9e3QfqjKwvW3O', $request->getUri()); + } + + public function testSetUserWithEventTime() + { + $eventTime='1982-09-25T01:23:45+0800'; + + $this->eventClient->setUser(1, array('age'=>20), $eventTime); + $result=array_shift($this->container); + /** @var Request $request */ + $request=$result['request']; + $body=json_decode($request->getBody(), true); + + $this->assertEquals('$set', $body['event']); + $this->assertEquals($eventTime, $body['eventTime']); + } + + public function testUnsetUser() + { + $this->eventClient->unsetUser(1, array('age'=>20)); + $result=array_shift($this->container); + /** @var Request $request */ + $request=$result['request']; + $body=json_decode($request->getBody(), true); + + $this->assertEquals('$unset', $body['event']); + $this->assertEquals('user', $body['entityType']); + $this->assertEquals(1, $body['entityId']); + $this->assertEquals(20, $body['properties']['age']); + $this->assertNotNull($body['eventTime']); + $this->assertEquals('POST', $request->getMethod()); + $this->assertEquals('http://localhost:7070/events.json?accessKey=j4jIdbq59JsF2f4CXwwkIiVHNFnyNvWXqMqXxcIbQDqFRz5K0fe9e3QfqjKwvW3O', $request->getUri()); + } + + public function testUnsetUserWithEventTime() + { + $eventTime='1982-09-25T01:23:45+0800'; + + $this->eventClient->unsetUser(1, array('age'=>20), $eventTime); + $result=array_shift($this->container); + /** @var Request $request */ + $request=$result['request']; + $body=json_decode($request->getBody(), true); + + $this->assertEquals('$unset', $body['event']); + $this->assertEquals($eventTime, $body['eventTime']); + } + + /** + * @expectedException \predictionio\PredictionIOAPIError + */ + public function testUnsetUserWithoutProperties() + { + $this->eventClient->unsetUser(1, array()); + } + + public function testDeleteUser() + { + $this->eventClient->deleteUser(1); + $result=array_shift($this->container); + /** @var Request $request */ + $request=$result['request']; + $body=json_decode($request->getBody(), true); + + $this->assertEquals('$delete', $body['event']); + $this->assertEquals('user', $body['entityType']); + $this->assertEquals(1, $body['entityId']); + $this->assertNotNull($body['eventTime']); + $this->assertEquals('POST', $request->getMethod()); + $this->assertEquals('http://localhost:7070/events.json?accessKey=j4jIdbq59JsF2f4CXwwkIiVHNFnyNvWXqMqXxcIbQDqFRz5K0fe9e3QfqjKwvW3O', $request->getUri()); + } + + public function testDeleteUserWithEventTime() + { + $eventTime='1982-09-25T01:23:45+0800'; + + $this->eventClient->deleteUser(1, $eventTime); + $result=array_shift($this->container); + /** @var Request $request */ + $request=$result['request']; + $body=json_decode($request->getBody(), true); + + $this->assertEquals('$delete', $body['event']); + $this->assertEquals($eventTime, $body['eventTime']); + } + + public function testSetItem() + { + $this->eventClient->setItem(1, array('type'=>'book')); + $result=array_shift($this->container); + /** @var Request $request */ + $request=$result['request']; + $body=json_decode($request->getBody(), true); + + $this->assertEquals('$set', $body['event']); + $this->assertEquals('item', $body['entityType']); + $this->assertEquals(1, $body['entityId']); + $this->assertEquals('book', $body['properties']['type']); + $this->assertNotNull($body['eventTime']); + $this->assertEquals('POST', $request->getMethod()); + $this->assertEquals('http://localhost:7070/events.json?accessKey=j4jIdbq59JsF2f4CXwwkIiVHNFnyNvWXqMqXxcIbQDqFRz5K0fe9e3QfqjKwvW3O', $request->getUri()); + } + + public function testSetItemWithEventTime() + { + $eventTime='1982-09-25T01:23:45+0800'; + + $this->eventClient->setItem(1, array('type'=>'book'), $eventTime); + $result=array_shift($this->container); + /** @var Request $request */ + $request=$result['request']; + $body=json_decode($request->getBody(), true); + + $this->assertEquals('$set', $body['event']); + $this->assertEquals($eventTime, $body['eventTime']); + } + + public function testUnsetItem() + { + $this->eventClient->unsetItem(1, array('type'=>'book')); + $result=array_shift($this->container); + /** @var Request $request */ + $request=$result['request']; + $body=json_decode($request->getBody(), true); + + $this->assertEquals('$unset', $body['event']); + $this->assertEquals('item', $body['entityType']); + $this->assertEquals(1, $body['entityId']); + $this->assertEquals('book', $body['properties']['type']); + $this->assertNotNull($body['eventTime']); + $this->assertEquals('POST', $request->getMethod()); + $this->assertEquals('http://localhost:7070/events.json?accessKey=j4jIdbq59JsF2f4CXwwkIiVHNFnyNvWXqMqXxcIbQDqFRz5K0fe9e3QfqjKwvW3O', $request->getUri()); + } + + public function testUnsetItemWithEventTime() + { + $eventTime='1982-09-25T01:23:45+0800'; + + $this->eventClient->unsetItem(1, array('type'=>'book'), $eventTime); + $result=array_shift($this->container); + /** @var Request $request */ + $request=$result['request']; + $body=json_decode($request->getBody(), true); + + $this->assertEquals('$unset', $body['event']); + $this->assertEquals($eventTime, $body['eventTime']); + } + + /** + * @expectedException \predictionio\PredictionIOAPIError + */ + public function testUnsetItemWithoutProperties() + { + $this->eventClient->unsetItem(1, array()); + } + + public function testDeleteItem() + { + $this->eventClient->deleteItem(1); + $result=array_shift($this->container); + /** @var Request $request */ + $request=$result['request']; + $body=json_decode($request->getBody(), true); + + $this->assertEquals('$delete', $body['event']); + $this->assertEquals('item', $body['entityType']); + $this->assertEquals(1, $body['entityId']); + $this->assertNotNull($body['eventTime']); + $this->assertEquals('POST', $request->getMethod()); + $this->assertEquals('http://localhost:7070/events.json?accessKey=j4jIdbq59JsF2f4CXwwkIiVHNFnyNvWXqMqXxcIbQDqFRz5K0fe9e3QfqjKwvW3O', $request->getUri()); + } + + public function testDeleteItemWithEventTime() + { + $eventTime='1982-09-25T01:23:45+0800'; + + $this->eventClient->deleteItem(1, $eventTime); + $result=array_shift($this->container); + /** @var Request $request */ + $request=$result['request']; + $body=json_decode($request->getBody(), true); + + $this->assertEquals('$delete', $body['event']); + $this->assertEquals($eventTime, $body['eventTime']); + } + + public function testRecordAction() + { + $this->eventClient->recordUserActionOnItem('view', 1, 888, array('count'=>2)); + $result=array_shift($this->container); + /** @var Request $request */ + $request=$result['request']; + $body=json_decode($request->getBody(), true); + + $this->assertEquals('view', $body['event']); + $this->assertEquals('user', $body['entityType']); + $this->assertEquals(1, $body['entityId']); + $this->assertEquals('item', $body['targetEntityType']); + $this->assertEquals(888, $body['targetEntityId']); + $this->assertEquals(2, $body['properties']['count']); + $this->assertNotNull($body['eventTime']); + $this->assertEquals('POST', $request->getMethod()); + $this->assertEquals('http://localhost:7070/events.json?accessKey=j4jIdbq59JsF2f4CXwwkIiVHNFnyNvWXqMqXxcIbQDqFRz5K0fe9e3QfqjKwvW3O', $request->getUri()); + } + + public function testRecordActionWithEventTime() + { + $eventTime='1982-09-25T01:23:45+0800'; + + $this->eventClient->recordUserActionOnItem('view', 1, 8, array(), $eventTime); + $result=array_shift($this->container); + /** @var Request $request */ + $request=$result['request']; + $body=json_decode($request->getBody(), true); + + $this->assertEquals('view', $body['event']); + $this->assertEquals($eventTime, $body['eventTime']); + } + + public function testCreateEvent() + { + $this->eventClient->createEvent(array( 'event' => 'my_event', 'entityType' => 'user', 'entityId' => 'uid', @@ -255,43 +291,40 @@ public function testCreateEvent() { 'prop4'=>true, 'prop5'=>array('a','b','c'), 'prop6'=>4.56 - ), + ), 'eventTime' => '2004-12-13T21:39:45.618-07:00' )); - $result=array_shift($this->container); - /** @var Request $request */ - $request=$result['request']; - $body=json_decode($request->getBody(), true); - - $this->assertEquals('my_event',$body['event']); - $this->assertEquals('user',$body['entityType']); - $this->assertEquals('uid',$body['entityId']); - $this->assertEquals(1,$body['properties']['prop1']); - $this->assertEquals('value2',$body['properties']['prop2']); - $this->assertEquals(array(1,2,3),$body['properties']['prop3']); - $this->assertEquals(true,$body['properties']['prop4']); - $this->assertEquals(array('a','b','c'),$body['properties']['prop5']); - $this->assertEquals(4.56,$body['properties']['prop6']); - $this->assertEquals('2004-12-13T21:39:45.618-07:00',$body['eventTime']); - $this->assertEquals('POST',$request->getMethod()); - $this->assertEquals('http://localhost:7070/events.json?accessKey=j4jIdbq59JsF2f4CXwwkIiVHNFnyNvWXqMqXxcIbQDqFRz5K0fe9e3QfqjKwvW3O',$request->getUri()); - } - - public function testGetEvent() { - $this->eventClient->getEvent('event_id'); - $result=array_shift($this->container); - /** @var Request $request */ - $request=$result['request']; - $body=json_decode($request->getBody(), true); - - $this->assertEquals('GET',$request->getMethod()); - $this->assertEquals('http://localhost:7070/events/event_id.json?accessKey=j4jIdbq59JsF2f4CXwwkIiVHNFnyNvWXqMqXxcIbQDqFRz5K0fe9e3QfqjKwvW3O', - $request->getUri()); - } - - - - + $result=array_shift($this->container); + /** @var Request $request */ + $request=$result['request']; + $body=json_decode($request->getBody(), true); + + $this->assertEquals('my_event', $body['event']); + $this->assertEquals('user', $body['entityType']); + $this->assertEquals('uid', $body['entityId']); + $this->assertEquals(1, $body['properties']['prop1']); + $this->assertEquals('value2', $body['properties']['prop2']); + $this->assertEquals(array(1,2,3), $body['properties']['prop3']); + $this->assertEquals(true, $body['properties']['prop4']); + $this->assertEquals(array('a','b','c'), $body['properties']['prop5']); + $this->assertEquals(4.56, $body['properties']['prop6']); + $this->assertEquals('2004-12-13T21:39:45.618-07:00', $body['eventTime']); + $this->assertEquals('POST', $request->getMethod()); + $this->assertEquals('http://localhost:7070/events.json?accessKey=j4jIdbq59JsF2f4CXwwkIiVHNFnyNvWXqMqXxcIbQDqFRz5K0fe9e3QfqjKwvW3O', $request->getUri()); + } + + public function testGetEvent() + { + $this->eventClient->getEvent('event_id'); + $result=array_shift($this->container); + /** @var Request $request */ + $request=$result['request']; + $body=json_decode($request->getBody(), true); + + $this->assertEquals('GET', $request->getMethod()); + $this->assertEquals( + 'http://localhost:7070/events/event_id.json?accessKey=j4jIdbq59JsF2f4CXwwkIiVHNFnyNvWXqMqXxcIbQDqFRz5K0fe9e3QfqjKwvW3O', + $request->getUri() + ); + } } -?> - diff --git a/tests/Unit/ExporterTest.php b/tests/Unit/ExporterTest.php index fb2377b..7f3690a 100644 --- a/tests/Unit/ExporterTest.php +++ b/tests/Unit/ExporterTest.php @@ -1,11 +1,26 @@ json = []; $this->data = []; } - public function jsonEncode($data) { + public function jsonEncode($data) + { $this->data[] = $data; return $this->traitJsonEncode($data); } - public function export($json) { + public function export($json) + { $this->json[] = $json; } } -class ExporterTest extends \PHPUnit_Framework_TestCase { +class ExporterTest extends \PHPUnit_Framework_TestCase +{ /** @var TestExporter $exporter */ private $exporter; - protected function setUp() { + protected function setUp() + { $this->exporter = new TestExporter(); } - public function testTimeIsNow() { + public function testTimeIsNow() + { $time = new \DateTime(); $this->exporter->createEvent('event', 'entity-type', 'entity-id'); @@ -56,7 +77,8 @@ public function testTimeIsNow() { $this->assertTrue(preg_match($pattern, $json) === 1, 'json'); } - public function testTimeIsString() { + public function testTimeIsString() + { $time = new \DateTime('2015-04-01'); $this->exporter->createEvent('event', 'entity-type', 'entity-id', null, null, null, '2015-04-01'); @@ -75,7 +97,8 @@ public function testTimeIsString() { $this->assertTrue(preg_match($pattern, $json) === 1, 'json'); } - public function testTimeIsDateTime() { + public function testTimeIsDateTime() + { $time = new \DateTime('2015-04-01'); $this->exporter->createEvent('event', 'entity-type', 'entity-id', null, null, null, $time); @@ -94,11 +117,19 @@ public function testTimeIsDateTime() { $this->assertTrue(preg_match($pattern, $json) === 1, 'json'); } - public function testOptionalFields() { + public function testOptionalFields() + { $time = new \DateTime('2015-04-01'); - $this->exporter->createEvent('event', 'entity-type', 'entity-id', - 'target-entity-type', 'target-entity-id', ['property' => true], $time); + $this->exporter->createEvent( + 'event', + 'entity-type', + 'entity-id', + 'target-entity-type', + 'target-entity-id', + ['property' => true], + $time + ); $this->assertEquals(1, count($this->exporter->data)); $data = $this->exporter->data[0]; @@ -116,5 +147,4 @@ public function testOptionalFields() { $pattern = '/^{"event":"event","entityType":"entity-type","entityId":"entity-id","eventTime":"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{4}","targetEntityType":"target-entity-type","targetEntityId":"target-entity-id","properties":{"property":true}}$/'; $this->assertTrue(preg_match($pattern, $json) === 1, 'json'); } - -} \ No newline at end of file +} diff --git a/tests/Unit/FileExporterTest.php b/tests/Unit/FileExporterTest.php index f23affa..f7f43cd 100644 --- a/tests/Unit/FileExporterTest.php +++ b/tests/Unit/FileExporterTest.php @@ -1,12 +1,26 @@ createEvent('event-1', 'entity-type-1', 'entity-id-1', - null, null, null, '2015-04-01'); - $exporter->createEvent('event-2', 'entity-type-2', 'entity-id-2', - 'target-entity-type-2', 'target-entity-id-2', ['property' => 'blue'], '2015-04-01'); + $exporter->createEvent( + 'event-1', + 'entity-type-1', + 'entity-id-1', + null, + null, + null, + '2015-04-01' + ); + $exporter->createEvent( + 'event-2', + 'entity-type-2', + 'entity-id-2', + 'target-entity-type-2', + 'target-entity-id-2', + ['property' => 'blue'], + '2015-04-01' + ); $exporter->close(); $exported = file_get_contents('temp.file'); @@ -37,4 +66,4 @@ public function testExporter() { $this->assertEquals($expected, $exported); } -} \ No newline at end of file +}