Skip to content

Commit 089e80a

Browse files
committed
Add a new HTMLType
1 parent 087f0cf commit 089e80a

2 files changed

Lines changed: 40 additions & 3 deletions

File tree

src/core/etl/tests/Flow/ETL/Tests/Unit/Row/EntryFactoryTest.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ enum_schema,
3434
use function Flow\Types\DSL\{type_datetime, type_float, type_integer, type_list, type_map, type_string, type_structure};
3535
use Flow\ETL\Exception\{InvalidArgumentException, SchemaDefinitionNotFoundException};
3636
use Flow\ETL\Row\Entry\TimeEntry;
37-
use Flow\ETL\Row\EntryFactory;
37+
use Flow\ETL\Row\{Entry, EntryFactory};
3838
use Flow\ETL\Schema\Metadata;
3939
use Flow\ETL\Tests\Fixtures\Enum\BackedIntEnum;
4040
use Flow\ETL\Tests\FlowTestCase;
@@ -43,6 +43,24 @@ enum_schema,
4343

4444
final class EntryFactoryTest extends FlowTestCase
4545
{
46+
public static function provide_recognized_data() : \Generator
47+
{
48+
yield 'json' => [
49+
$json = '{"id":1}',
50+
json_entry('e', $json),
51+
];
52+
53+
yield 'xml' => [
54+
$xml = '<root><foo>1</foo><bar>2</bar><baz>3</baz></root>',
55+
xml_entry('e', $xml),
56+
];
57+
58+
yield 'uuid' => [
59+
$uuid = '00000000-0000-0000-0000-000000000000',
60+
uuid_entry('e', $uuid),
61+
];
62+
}
63+
4664
public static function provide_unrecognized_data() : \Generator
4765
{
4866
yield 'json alike' => [
@@ -360,6 +378,15 @@ public function test_object() : void
360378
(new EntryFactory())->create('e', new \ArrayIterator([1, 2]));
361379
}
362380

381+
#[DataProvider('provide_recognized_data')]
382+
public function test_recognized_data_set_same_as_provided(string $input, Entry $entry) : void
383+
{
384+
self::assertEquals(
385+
$entry,
386+
(new EntryFactory())->create('e', $input)
387+
);
388+
}
389+
363390
public function test_string() : void
364391
{
365392
self::assertEquals(

src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/AutoCastTransformerTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,22 @@
55
namespace Flow\ETL\Tests\Unit\Transformer;
66

77
use function Flow\ETL\DSL\{array_to_rows, flow_context};
8-
use Flow\ETL\Tests\FlowTestCase;
98
use Flow\ETL\Transformer\AutoCastTransformer;
109
use Flow\Types\Type\AutoCaster;
10+
use PHPUnit\Framework\TestCase;
1111

12-
final class AutoCastTransformerTest extends FlowTestCase
12+
final class AutoCastTransformerTest extends TestCase
1313
{
1414
public function test_transforming_row() : void
1515
{
1616
$transformer = new AutoCastTransformer(new AutoCaster());
1717

18+
$xml = new \DOMDocument();
19+
$xml->loadXML($xmlString = '<root><foo>bar</foo></root>');
20+
21+
$html = new \DOMDocument();
22+
$html->loadXML($htmlString = '<html><body><div><span>1</span></div></body></html>');
23+
1824
$rows = array_to_rows([
1925
[
2026
'integer' => '1',
@@ -24,6 +30,8 @@ public function test_transforming_row() : void
2430
'datetime' => '2021-01-01 00:00:00',
2531
'null' => 'null',
2632
'nil' => 'nil',
33+
'xml' => $xmlString,
34+
'html' => $htmlString,
2735
],
2836
]);
2937

@@ -37,6 +45,8 @@ public function test_transforming_row() : void
3745
'datetime' => new \DateTimeImmutable('2021-01-01 00:00:00'),
3846
'null' => null,
3947
'nil' => null,
48+
'xml' => $xml,
49+
'html' => $html,
4050
],
4151
],
4252
$transformer->transform($rows, flow_context())->toArray()

0 commit comments

Comments
 (0)