File: CoerceTest.php

package info (click to toggle)
php-league-html-to-markdown 5.1.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 468 kB
  • sloc: php: 1,641; makefile: 20; xml: 15; sh: 5
file content (54 lines) | stat: -rw-r--r-- 1,270 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
47
48
49
50
51
52
53
54
<?php

declare(strict_types=1);

namespace League\HTMLToMarkdown\Test;

use League\HTMLToMarkdown\Coerce;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

final class CoerceTest extends TestCase
{
    /**
     * @param mixed $val
     */
    #[DataProvider('provideStringTestCases')]
    public function testToString($val, string $expected): void
    {
        $this->assertSame($expected, Coerce::toString($val));
    }

    public static function provideStringTestCases(): \Generator
    {
        yield ['foo', 'foo'];
        yield [1, '1'];
        yield [1.1, '1.1'];
        yield [true, '1'];
        yield [false, ''];
        yield [null, ''];
    }

    /**
     * @param mixed $val
     */
    #[DataProvider('provideInvalidStringTestCases')]
    public function testToStringThrowsOnUncoercableValue($val): void
    {
        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessage('Cannot coerce this value to string');

        Coerce::toString($val);
    }

    public static function provideInvalidStringTestCases(): \Generator
    {
        yield [new \stdClass()];
        yield [STDOUT];
    }

    public function __toString(): string
    {
        return 'some object';
    }
}