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';
}
}
|