From 2c202c63753861394765ec3c75b4f87808390a60 Mon Sep 17 00:00:00 2001 From: Xenofon Spafaridis Date: Wed, 20 Jan 2016 14:25:35 +0200 Subject: [PATCH] Fix when rules are string but invalid JSON Fix arguments of rand-integer to allow strings --- README.md | 1 + src/Globals.php | 6 +++++- src/TestParser.php | 6 +++--- src/Testphase.php | 2 +- src/Util.php | 3 +++ 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2ec69a6..507f177 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ API testing environment build for phramework and RESTful APIs [![Coverage Status](https://coveralls.io/repos/phramework/testphase/badge.svg?branch=master&service=github)](https://coveralls.io/github/phramework/testphase?branch=master) [![Build Status](https://travis-ci.org/phramework/testphase.svg?branch=master)](https://travis-ci.org/phramework/testphase) +[![StyleCI](https://styleci.io/repos/46678784/shield)](https://styleci.io/repos/46678784) ## Usage Require package using composer diff --git a/src/Globals.php b/src/Globals.php index d2dd0ab..8079a81 100644 --- a/src/Globals.php +++ b/src/Globals.php @@ -58,7 +58,10 @@ protected static function initializeGlobals() static::$globals->{'rand-integer'} = function ($max = null) { if ($max === null) { $max = getrandmax(); + } else { + $max = intval($max); } + return rand(0, $max); }; @@ -76,7 +79,8 @@ protected static function initializeGlobals() /** * Check if global variable exists * @param string $key - * @throws Exception + * @throws \Exception + * @return boolean */ public static function exists($key) { diff --git a/src/TestParser.php b/src/TestParser.php index 6d3d832..0514ff4 100644 --- a/src/TestParser.php +++ b/src/TestParser.php @@ -302,10 +302,10 @@ public function createTest() //Add rule objects to validate body foreach ($contentsParsed->response->ruleObjects as $key => $ruleObject) { if (is_string($ruleObject)) { - $ruleObject = json_decode($ruleObject); + $testphase->expectObject(ObjectValidator::createFromJSON($ruleObject)); + } else { + $testphase->expectObject(ObjectValidator::createFromObject($ruleObject)); } - - $testphase->expectObject(ObjectValidator::createFromObject($ruleObject)); } //push test diff --git a/src/Testphase.php b/src/Testphase.php index 5402f52..a121cae 100644 --- a/src/Testphase.php +++ b/src/Testphase.php @@ -21,7 +21,7 @@ /** * @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0 * @author Xenofon Spafaridis - * @version 1.0.0-dev + * @version 1.0.1 */ class Testphase { diff --git a/src/Util.php b/src/Util.php index dc85084..8865e52 100644 --- a/src/Util.php +++ b/src/Util.php @@ -47,6 +47,9 @@ public static function isJSON($string) */ public static function readableRandomString($length = 8) { + + $length = intval($length); + $consonants = [ 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z' ];