File: DataUtilsTest.php

package info (click to toggle)
php-arthurhoaro-web-thumbnailer 2.1.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 892 kB
  • sloc: php: 3,365; makefile: 19; sh: 9
file content (35 lines) | stat: -rw-r--r-- 1,113 bytes parent folder | download | duplicates (2)
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');
    }
}