Skip to content

Commit

Permalink
Fix when rules are string but invalid JSON
Browse files Browse the repository at this point in the history
Fix arguments of rand-integer  to allow strings
  • Loading branch information
nohponex committed Jan 20, 2016
1 parent fd84f49 commit 2c202c6
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/Globals.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand All @@ -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)
{
Expand Down
6 changes: 3 additions & 3 deletions src/TestParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Testphase.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0
* @author Xenofon Spafaridis <nohponex@gmail.com>
* @version 1.0.0-dev
* @version 1.0.1
*/
class Testphase
{
Expand Down
3 changes: 3 additions & 0 deletions src/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
];
Expand Down

0 comments on commit 2c202c6

Please sign in to comment.