mirror of
https://github.com/Respect/Validation.git
synced 2026-03-18 08:09:51 +01:00
62 lines
1.5 KiB
PHP
62 lines
1.5 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Respect/Validation.
|
|
*
|
|
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
|
*
|
|
* For the full copyright and license information, please view the "LICENSE.md"
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
/**
|
|
* @group rule
|
|
* @covers Respect\Validation\Rules\Json
|
|
* @covers Respect\Validation\Exceptions\JsonException
|
|
*/
|
|
class JsonTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
protected $json;
|
|
|
|
protected function setUp()
|
|
{
|
|
$this->json = new Json();
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerForPass
|
|
*/
|
|
public function testValidJsonsShouldReturnTrue($input)
|
|
{
|
|
$this->assertTrue($this->json->__invoke($input));
|
|
$this->assertTrue($this->json->check($input));
|
|
$this->assertTrue($this->json->assert($input));
|
|
}
|
|
|
|
/**
|
|
* @expectedException Respect\Validation\Exceptions\JSonException
|
|
*/
|
|
public function testInvalidJsonsShouldThrowJsonException()
|
|
{
|
|
$this->assertFalse($this->json->__invoke('{foo:bar}'));
|
|
$this->assertFalse($this->json->assert('{foo:bar}'));
|
|
}
|
|
|
|
public function providerForPass()
|
|
{
|
|
return array(
|
|
array(''),
|
|
array('2'),
|
|
array('"abc"'),
|
|
array('[1,2,3]'),
|
|
array('["foo", "bar", "number", 1]'),
|
|
array('{"foo": "bar", "number":1}'),
|
|
array('[]'),
|
|
array('{}'),
|
|
array('false'),
|
|
array('null'),
|
|
);
|
|
}
|
|
}
|