Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing example for Xml insert #1474

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,51 @@ public function test_inserts_new_rows_or_updates_already_existed_based_on_primar
);
}

public function test_inserts_xml_entry() : void
{
$this->pgsqlDatabaseContext->createTable((new Table(
$table = 'flow_doctrine_bulk_test',
[
new Column('id', Type::getType(Types::INTEGER), ['notnull' => true]),
new Column('name', Type::getType(Types::STRING), ['notnull' => true, 'length' => 255]),
new Column('description', Type::getType(Types::STRING), ['notnull' => true, 'length' => 255]),
],
))
->setPrimaryKey(['id']));

$loader = to_dbal_table_insert($this->connectionParams(), $table);

$documentA = new \DOMDocument();
$documentA->loadXml('Description One');

$documentB = new \DOMDocument();
$documentB->loadXml('Description Two');

$documentC = new \DOMDocument();
$documentC->loadXml('<b>Description Three</b>');

(data_frame())
->read(
from_array([
['id' => 1, 'name' => 'Name One', 'description' => $documentA],
['id' => 2, 'name' => 'Name Two', 'description' => $documentB],
['id' => 3, 'name' => 'Name Three', 'description' => $documentC],
]),
)
->load($loader)
->run();

self::assertEquals(3, $this->pgsqlDatabaseContext->tableCount($table));
self::assertEquals(
[
['id' => 1, 'name' => 'Name One', 'description' => 'Description One'],
['id' => 2, 'name' => 'Name Two', 'description' => 'Description Two'],
['id' => 3, 'name' => 'Name Three', 'description' => '<b>Description Three</b>'],
],
$this->pgsqlDatabaseContext->selectAll($table)
);
}

public function test_update_multiple_rows_at_once() : void
{
$this->pgsqlDatabaseContext->createTable((new Table(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,34 @@
use function Flow\ETL\DSL\{average, df, from_array, overwrite, ref};
use function Flow\ETL\DSL\{config, flow_context, rows};
use function Flow\Filesystem\DSL\path;

use Flow\ETL\Adapter\JSON\JsonLoader;
use Flow\ETL\Tests\Double\FakeExtractor;
use Flow\ETL\{Tests\FlowTestCase};

final class JsonTest extends FlowTestCase
{
public function test_domdocument_json_file() : void
{
$domDocument = new \DOMDocument();
$domDocument->loadXml('<b>red</b>');

df()
->read(from_array([
['id' => 1, 'descriptionHtml' => $domDocument, 'size' => 'small'],
]))
->saveMode(overwrite())
->write(to_json($path = __DIR__ . '/var/test_domdocument.json'))
->run();

self::assertStringContainsString(
<<<'JSON'
[{"id":1,"descriptionHtml":"<b>red<\/b>","size":"small"}]
JSON,
\file_get_contents($path)
);
}

public function test_json_loader() : void
{
$path = __DIR__ . '/var/test_json_loader.json';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,37 @@

namespace Flow\ETL\Tests\Integration\Function;

use function Flow\ETL\DSL\{df, from_rows, ref, row, rows, xml_element_entry, xml_entry};
use function Flow\ETL\DSL\{df, from_rows, ref, row, rows, type_string, xml_element_entry, xml_entry};

use Flow\ETL\Tests\FlowTestCase;

final class DOMElementValueTest extends FlowTestCase
{
public function test_dom_element_cast_as_string() : void
{
$document = new \DOMDocument();
$document->loadXml('<b>User Name 01</b>');

$rows = df()
->read(from_rows(
rows(
row(
xml_entry('html_raw', $document)
)
)
))
->withEntry('html', ref('html_raw')->cast(type_string()))
->drop('html_raw')
->fetch();

self::assertSame(
[
['html' => '<b>User Name 01</b>'],
],
$rows->toArray()
);
}

public function test_dom_element_value() : void
{
$rows = df()
Expand Down Expand Up @@ -53,6 +79,31 @@ public function test_dom_element_value_from_dom_document() : void
);
}

public function test_dom_element_value_on_dom_document() : void
{
$document = new \DOMDocument();
$document->loadXml('<b>User Name 01</b>');

$rows = df()
->read(from_rows(
rows(
row(
xml_entry('html_raw', $document)
)
)
))
->withEntry('html', ref('html_raw')->domElementValue())
->drop('html_raw')
->fetch();

self::assertSame(
[
['html' => '<b>User Name 01</b>'],
],
$rows->toArray()
);
}

public function test_dom_element_value_on_xpath_result() : void
{
$rows = df()
Expand Down
Loading