|
5 | 5 | namespace Flow\ETL\Adapter\Doctrine\Tests\Integration; |
6 | 6 |
|
7 | 7 | use function Flow\ETL\Adapter\Doctrine\from_dbal_limit_offset; |
8 | | -use Flow\ETL\Adapter\Doctrine\Table; |
| 8 | +use function Flow\ETL\DSL\{data_frame, flow_context, from_array}; |
| 9 | +use Doctrine\DBAL\Schema\Column; |
| 10 | +use Doctrine\DBAL\Types\{TextType, Type, Types}; |
| 11 | +use Flow\ETL\Adapter\Doctrine\{DbalLoader, DbalTypesDetector, Order, OrderBy, Table, TypesMap}; |
9 | 12 | use Flow\ETL\Adapter\Doctrine\Tests\IntegrationTestCase; |
| 13 | +use Flow\ETL\{Config, Rows}; |
| 14 | +use Flow\Types\Type\Native\{IntegerType, StringType}; |
10 | 15 |
|
11 | 16 | final class DbalLimitOffsetExtractorTest extends IntegrationTestCase |
12 | 17 | { |
13 | | - public function test_creating_limit_offset_extractor_for_table_without_oder_by() : void |
| 18 | + public function test_creating_limit_offset_extractor_for_table() : void |
| 19 | + { |
| 20 | + $this->pgsqlDatabaseContext->createTable((new \Doctrine\DBAL\Schema\Table( |
| 21 | + $table = 'flow_doctrine_order_by_test', |
| 22 | + [ |
| 23 | + new Column('id', Type::getType(Types::INTEGER), ['notnull' => true]), |
| 24 | + new Column('code', Type::getType(Types::INTEGER), ['notnull' => true]), |
| 25 | + ], |
| 26 | + )) |
| 27 | + ->setPrimaryKey(['id'])); |
| 28 | + |
| 29 | + $customTypesMap = new TypesMap([ |
| 30 | + StringType::class => TextType::class, |
| 31 | + IntegerType::class => \Doctrine\DBAL\Types\IntegerType::class, |
| 32 | + ]); |
| 33 | + |
| 34 | + $customConverter = new DbalTypesDetector($customTypesMap); |
| 35 | + |
| 36 | + $loader = (new DbalLoader($table, $this->postgresqlConnectionParams())) |
| 37 | + ->withTypesDetector($customConverter); |
| 38 | + |
| 39 | + (data_frame()) |
| 40 | + ->read(from_array([ |
| 41 | + ['id' => 1, 'code' => 100], |
| 42 | + ['id' => 2, 'code' => 100], |
| 43 | + ['id' => 3, 'code' => 200], |
| 44 | + ])) |
| 45 | + ->load($loader) |
| 46 | + ->run(); |
| 47 | + |
| 48 | + $extractor = from_dbal_limit_offset( |
| 49 | + $this->pgsqlDatabaseContext->connection(), |
| 50 | + new Table('flow_doctrine_order_by_test', ['id', 'code']), |
| 51 | + [ |
| 52 | + new OrderBy('code', Order::DESC), |
| 53 | + new OrderBy('id', Order::ASC), |
| 54 | + ] |
| 55 | + ); |
| 56 | + |
| 57 | + self::assertSame( |
| 58 | + [ |
| 59 | + [ |
| 60 | + [ |
| 61 | + 'id' => 3, |
| 62 | + 'code' => 200, |
| 63 | + ], |
| 64 | + ], |
| 65 | + [ |
| 66 | + [ |
| 67 | + 'id' => 1, |
| 68 | + 'code' => 100, |
| 69 | + ], |
| 70 | + ], |
| 71 | + [ |
| 72 | + [ |
| 73 | + 'id' => 2, |
| 74 | + 'code' => 100, |
| 75 | + ], |
| 76 | + ], |
| 77 | + ], |
| 78 | + \array_map( |
| 79 | + static fn (Rows $r) => $r->toArray(), |
| 80 | + \iterator_to_array($extractor->extract(flow_context(Config::builder()->putInputIntoRows()->build()))) |
| 81 | + ) |
| 82 | + ); |
| 83 | + } |
| 84 | + |
| 85 | + public function test_creating_limit_offset_extractor_for_table_without_order_by() : void |
14 | 86 | { |
15 | 87 | $this->expectExceptionMessage('There must be at least one column to order by, zero given'); |
16 | 88 |
|
|
0 commit comments