File: JsonValidationExceptionTest.php

package info (click to toggle)
composer 2.9.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,528 kB
  • sloc: php: 83,030; makefile: 59; xml: 39
file content (46 lines) | stat: -rw-r--r-- 1,329 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
36
37
38
39
40
41
42
43
44
45
46
<?php declare(strict_types=1);

/*
 * This file is part of Composer.
 *
 * (c) Nils Adermann <naderman@naderman.de>
 *     Jordi Boggiano <j.boggiano@seld.be>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Composer\Test\Json;

use Composer\Json\JsonValidationException;
use Composer\Test\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;

class JsonValidationExceptionTest extends TestCase
{
    /**
     * @param string[] $errors
     * @param string[] $expectedErrors
     */
    #[DataProvider('errorProvider')]
    public function testGetErrors(string $message, array $errors, string $expectedMessage, array $expectedErrors): void
    {
        $object = new JsonValidationException($message, $errors);
        self::assertSame($expectedMessage, $object->getMessage());
        self::assertSame($expectedErrors, $object->getErrors());
    }

    public function testGetErrorsWhenNoErrorsProvided(): void
    {
        $object = new JsonValidationException('test message');
        self::assertEquals([], $object->getErrors());
    }

    public static function errorProvider(): array
    {
        return [
            ['test message', [], 'test message', []],
            ['', ['foo'], '', ['foo']],
        ];
    }
}