respect-validation/tests/unit/Rules/JsonTest.php

67 lines
1.5 KiB
PHP
Raw Normal View History

<?php
2015-06-08 16:47:14 +02:00
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
use stdClass;
/**
* @group rule
*
* @covers \Respect\Validation\Rules\Json
*
* @author Alexandre Gomes Gaigalas <alganet@gmail.com>
* @author Danilo Benevides <danilobenevides01@gmail.com>
* @author Emmerson Siqueira <emmersonsiqueira@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Nick Lombard <github@jigsoft.co.za>
*/
final class JsonTest extends RuleTestCase
{
/**
* {@inheritDoc}
*/
public static function providerForValidInput(): array
{
2015-10-18 07:09:10 +02:00
$json = new Json();
2015-10-18 07:09:10 +02:00
return [
[$json, '2'],
[$json, '"abc"'],
[$json, '[1,2,3]'],
[$json, '["foo", "bar", "number", 1]'],
[$json, '{"foo": "bar", "number":1}'],
[$json, '[]'],
[$json, '{}'],
[$json, 'false'],
[$json, 'null'],
];
}
2013-01-23 08:24:11 +01:00
/**
* {@inheritDoc}
*/
public static function providerForInvalidInput(): array
2015-10-07 05:54:14 +02:00
{
2015-10-18 07:09:10 +02:00
$json = new Json();
2015-10-07 05:54:14 +02:00
2015-10-18 03:44:47 +02:00
return [
2015-10-18 07:09:10 +02:00
[$json, false],
[$json, new stdClass()],
2015-10-18 07:09:10 +02:00
[$json, []],
[$json, ''],
[$json, 'a'],
[$json, 'xx'],
[$json, '{foo: bar}'],
[$json, '{foo: "baz"}'],
2015-10-18 03:44:47 +02:00
];
2013-01-23 08:24:11 +01:00
}
}