1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
<?php
declare(strict_types=1);
namespace WebThumbnailer\Utils;
use WebThumbnailer\TestCase;
/**
* Unit test DataUtils.
*/
class DataUtilsTest extends TestCase
{
public function testLoadJsonResource(): void
{
$rules = DataUtils::loadJson(FileUtils::RESOURCES_PATH . 'rules.json');
// Test a random nested value.
$this->assertEquals('medium', $rules['imgur_single']['options']['size']['default']);
}
public function testLoadJsonResourceNoFile(): void
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('JSON resource file not found or not readable.');
DataUtils::loadJson(FileUtils::RESOURCES_PATH . 'nope.json');
}
public function testLoadJsonResourceBadSyntax(): void
{
$this->expectException(\Exception::class);
$this->expectExceptionMessageRegExp('/An error occured while parsing JSON file: error code #/');
$path = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR;
DataUtils::loadJson($path . 'badsyntax.json');
}
}
|