Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jubianchi committed Nov 9, 2014
1 parent 87ef165 commit 0e90716
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 7 deletions.
2 changes: 1 addition & 1 deletion classes/asserters/json.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,4 @@ protected static function isJson($value)
($decoded !== null || strtolower(trim($value)) === 'null')
);
}
}
}
76 changes: 76 additions & 0 deletions tests/resources/json/noarray.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//
// Hoa
//
//
// @license
//
// New BSD License
//
// Copyright © 2007-2014, Ivan Enderlin. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Hoa nor the names of its contributors may be
// used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Grammar \Hoa\Json\Grammar.
//
// Provide grammar for JSON. Please, see <http://json.org> or RFC4627.
//
// @author Ivan Enderlin <[email protected]>
// @copyright Copyright © 2007-2014 Ivan Enderlin.
// @license New BSD License
//


%skip space \s

%token true true
%token false false
%token null null
%token quote_ " -> string
%token string:escaped \\(["\\/bfnrt]|u[0-9a-fA-F]{4})
%token string:string [^"\\]+
%token string:_quote " -> default
%token brace_ {
%token _brace }
%token bracket_ \[
%token _bracket \]
%token colon :
%token comma ,
%token number \-?(0|[1-9]\d*)(\.\d+)?([eE][\+\-]?\d+)?

value:
<true> | <false> | <null> | string() | object() | number()

string:
::quote_::
<string>
::_quote::

number:
<number>

object:
::brace_:: pair() ( ::comma:: pair() )* ::_brace::

pair:
string() ::colon:: value()
23 changes: 21 additions & 2 deletions tests/units/classes/asserters/json.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testSetWith()
}
)
->isInstanceOf('mageekguy\atoum\asserter\exception')
->hasMessage(sprintf('%s is not a valid JSON string', $asserter->getTypeOf($value)))
->hasMessage(sprintf('%s is not a valid JSON string', $asserter))
;
}

Expand Down Expand Up @@ -89,4 +89,23 @@ protected function testValidatesJsonArrayGrammarDataProvider()
{
return $this->sampleMany($this->realdom->grammar(__DIR__ . '/../../../resources/json/array.pp'));
}
}

public function testNotValidatesJsonArrayGrammar($json)
{
$this
->assert($json)
->if($asserter = new testedClass())
->then
->object($asserter->setWith($json))->isIdenticalTo($asserter)
->exception(function() use ($asserter) {
$asserter->validates('{"title": "test", "type": "array"}');
}
)
;
}

protected function testNotValidatesJsonArrayGrammarDataProvider()
{
return $this->sampleMany($this->realdom->grammar(__DIR__ . '/../../../resources/json/noarray.pp'));
}
}
6 changes: 2 additions & 4 deletions tests/units/classes/extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ public function testSetTest()
->object($extension->setTest($test))->isIdenticalTo($extension)
->mock($manager)
->call('setHandler')->withArguments('json')->once()
->object($faker = $test->json)->isInstanceOf('mageekguy\atoum\jsonSchema\asserters\json')
->object($test->json)->isIdenticalTo($faker)
->object($test->json())->isIdenticalTo($faker)
->object($faker = $test->json('{}'))->isInstanceOf('mageekguy\atoum\jsonSchema\asserters\json')
;
}
}
}

0 comments on commit 0e90716

Please sign in to comment.