From a1917a7f97da25dc8b9b244aea6df561357de16c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Mleczko?= Date: Sat, 20 Jul 2024 23:28:52 +0200 Subject: [PATCH 1/8] Add UniqueFactory for creating random string or int from given range --- docs/components/libs/snappy.md | 2 +- .../ElasticsearchExtractorTest.php | 10 +-- .../ElasticsearchLoaderTest.php | 8 +- .../MeilisearchExtractorTest.php | 6 +- .../MeilisearchPHP/MeilisearchLoaderTest.php | 8 +- .../Text/Tests/Integration/TextTest.php | 2 +- .../Unit/AzureBlobDestinationStreamTest.php | 4 +- .../etl/src/Flow/ETL/Config/ConfigBuilder.php | 2 +- src/core/etl/src/Flow/ETL/UniqueFactory.php | 22 +++++ .../Flow/ETL/Tests/Double/FakeExtractor.php | 2 +- .../Integration/Cache/PSRSimpleCacheTest.php | 0 .../DataFrame/PartitioningTest.php | 8 +- .../ETL/Tests/Unit/Hash/NativePHPHashTest.php | 8 +- .../etl/tests/Flow/ETL/Tests/Unit/RowTest.php | 4 +- .../OrderEntriesTransformerTest.php | 6 +- .../Flow/ETL/Tests/Unit/UniqueFactoryTest.php | 84 +++++++++++++++++++ .../Tests/Integration/MySqlBulkInsertTest.php | 6 +- .../Integration/PostgreSqlBulkInsertTest.php | 6 +- .../Integration/SqliteBulkInsertTest.php | 6 +- .../filesystem/src/Flow/Filesystem/Path.php | 2 +- .../Block/NativeLocalFileBlocksFactory.php | 2 +- .../Tests/Integration/IO/CompressionTest.php | 48 +++++------ .../Tests/Integration/IO/ListsWritingTest.php | 32 +++---- .../Tests/Integration/IO/MapsWritingTest.php | 16 ++-- .../Tests/Integration/IO/PaginationTest.php | 8 +- .../Integration/IO/SimpleTypesWritingTest.php | 54 ++++++------ .../Integration/IO/StructsWritingTest.php | 18 ++-- .../Tests/Integration/IO/WriterTest.php | 24 +++--- .../Integration/IO/WriterValidatorTest.php | 18 ++-- .../Data/RLEBitPackedHybridTest.php | 4 +- .../RowGroupBuilder/PagesBuilderTest.php | 2 +- .../Snappy/Tests/Integration/SnappyTest.php | 2 +- 32 files changed, 265 insertions(+), 159 deletions(-) create mode 100644 src/core/etl/src/Flow/ETL/UniqueFactory.php create mode 100644 src/core/etl/tests/Flow/ETL/Tests/Integration/Cache/PSRSimpleCacheTest.php create mode 100644 src/core/etl/tests/Flow/ETL/Tests/Unit/UniqueFactoryTest.php diff --git a/docs/components/libs/snappy.md b/docs/components/libs/snappy.md index 287665255..93cc5dd86 100644 --- a/docs/components/libs/snappy.md +++ b/docs/components/libs/snappy.md @@ -37,7 +37,7 @@ $faker = \Faker\Factory::create(); $texts = []; for ($i = 0; $i < 10_000; $i++) { - $textSize = \random_int(100, 5000); + $textSize = \Flow\ETL\UniqueFactory::int(100, 5000); $texts[] = $faker->text($textSize); } diff --git a/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchExtractorTest.php b/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchExtractorTest.php index 316b88f1a..b2772eb39 100644 --- a/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchExtractorTest.php +++ b/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchExtractorTest.php @@ -40,7 +40,7 @@ public function test_empty_extraction() : void new Row\Entry\StringEntry('id', \sha1((string) $i)), new Row\Entry\IntegerEntry('position', $i), new Row\Entry\StringEntry('name', 'id_' . $i), - new Row\Entry\BooleanEntry('active', (bool) \random_int(0, 1)) + new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\UniqueFactory::int(0, 1)) ), \range(1, 100) ), @@ -80,7 +80,7 @@ public function test_extraction_index_with_from_and_size() : void new Row\Entry\StringEntry('id', \sha1((string) $i)), new Row\Entry\IntegerEntry('position', $i), new Row\Entry\StringEntry('name', 'id_' . $i), - new Row\Entry\BooleanEntry('active', (bool) \random_int(0, 1)) + new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\UniqueFactory::int(0, 1)) ), \range(1, 2000) ), @@ -123,7 +123,7 @@ public function test_extraction_index_with_search_after() : void new Row\Entry\StringEntry('id', \sha1((string) $i)), new Row\Entry\IntegerEntry('position', $i), new Row\Entry\StringEntry('name', 'id_' . $i), - new Row\Entry\BooleanEntry('active', (bool) \random_int(0, 1)) + new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\UniqueFactory::int(0, 1)) ), \range(1, 2005) ), @@ -159,7 +159,7 @@ public function test_extraction_index_with_search_after_with_point_in_time() : v new Row\Entry\StringEntry('id', \sha1((string) $i)), new Row\Entry\IntegerEntry('position', $i), new Row\Entry\StringEntry('name', 'id_' . $i), - new Row\Entry\BooleanEntry('active', (bool) \random_int(0, 1)) + new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\UniqueFactory::int(0, 1)) ), \range(1, 2005) ), @@ -200,7 +200,7 @@ public function test_extraction_whole_index_with_point_in_time() : void new Row\Entry\StringEntry('id', \sha1((string) $i)), new Row\Entry\IntegerEntry('position', $i), new Row\Entry\StringEntry('name', 'id_' . $i), - new Row\Entry\BooleanEntry('active', (bool) \random_int(0, 1)) + new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\UniqueFactory::int(0, 1)) ), \range(1, 2005) ), diff --git a/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchLoaderTest.php b/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchLoaderTest.php index fd092199b..f766f121c 100644 --- a/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchLoaderTest.php +++ b/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchLoaderTest.php @@ -53,19 +53,19 @@ public function test_integration_with_entry_factory() : void $loader->load(new Rows( Row::create( - new Row\Entry\StringEntry('id', \sha1('id' . bin2hex(random_bytes(16)))), + new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\UniqueFactory::string(32))), new Row\Entry\StringEntry('name', 'Łukasz') ), Row::create( - new Row\Entry\StringEntry('id', \sha1('id' . bin2hex(random_bytes(16)))), + new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\UniqueFactory::string(32))), new Row\Entry\StringEntry('name', 'Norbert') ), Row::create( - new Row\Entry\StringEntry('id', \sha1('id' . bin2hex(random_bytes(16)))), + new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\UniqueFactory::string(32))), new Row\Entry\StringEntry('name', 'Dawid') ), Row::create( - new Row\Entry\StringEntry('id', \sha1('id' . bin2hex(random_bytes(16)))), + new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\UniqueFactory::string(32))), new Row\Entry\StringEntry('name', 'Tomek') ), ), new FlowContext(Config::default())); diff --git a/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchExtractorTest.php b/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchExtractorTest.php index e0590bc6e..dfde6d0ee 100644 --- a/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchExtractorTest.php +++ b/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchExtractorTest.php @@ -37,7 +37,7 @@ public function test_empty_extraction() : void new Row\Entry\StringEntry('id', \sha1((string) $i)), new Row\Entry\IntegerEntry('position', $i), new Row\Entry\StringEntry('name', 'id_' . $i), - new Row\Entry\BooleanEntry('active', (bool) \random_int(0, 1)) + new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\UniqueFactory::int(0, 1)) ), \range(1, 100) ), @@ -63,7 +63,7 @@ public function test_extraction_index_with_from_and_size() : void new Row\Entry\StringEntry('id', \sha1((string) $i)), new Row\Entry\IntegerEntry('position', $i), new Row\Entry\StringEntry('name', 'id_' . $i), - new Row\Entry\BooleanEntry('active', (bool) \random_int(0, 1)) + new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\UniqueFactory::int(0, 1)) ), // Default limit for Meilisearch is 1000 documents: https://www.meilisearch.com/docs/reference/api/settings#pagination \range(1, 999) @@ -102,7 +102,7 @@ public function test_extraction_index_with_sort() : void new Row\Entry\StringEntry('id', \sha1((string) $i)), new Row\Entry\IntegerEntry('position', $i), new Row\Entry\StringEntry('name', 'id_' . $i), - new Row\Entry\BooleanEntry('active', (bool) \random_int(0, 1)) + new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\UniqueFactory::int(0, 1)) ), // Default limit for Meilisearch is 1000 documents: https://www.meilisearch.com/docs/reference/api/settings#pagination \range(1, 999) diff --git a/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchLoaderTest.php b/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchLoaderTest.php index b7c69f85a..7d20ce830 100644 --- a/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchLoaderTest.php +++ b/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchLoaderTest.php @@ -43,19 +43,19 @@ public function test_integration_with_entry_factory() : void $loader = to_meilisearch_bulk_index($this->meilisearchContext->clientConfig(), self::INDEX_NAME); $loader->load(new Rows( Row::create( - new Row\Entry\StringEntry('id', \sha1('id' . bin2hex(random_bytes(16)))), + new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\UniqueFactory::string(32))), new Row\Entry\StringEntry('name', 'Łukasz') ), Row::create( - new Row\Entry\StringEntry('id', \sha1('id' . bin2hex(random_bytes(16)))), + new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\UniqueFactory::string(32))), new Row\Entry\StringEntry('name', 'Norbert') ), Row::create( - new Row\Entry\StringEntry('id', \sha1('id' . bin2hex(random_bytes(16)))), + new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\UniqueFactory::string(32))), new Row\Entry\StringEntry('name', 'Dawid') ), Row::create( - new Row\Entry\StringEntry('id', \sha1('id' . bin2hex(random_bytes(16)))), + new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\UniqueFactory::string(32))), new Row\Entry\StringEntry('name', 'Tomek') ), ), new FlowContext(Config::default())); diff --git a/src/adapter/etl-adapter-text/tests/Flow/ETL/Adapter/Text/Tests/Integration/TextTest.php b/src/adapter/etl-adapter-text/tests/Flow/ETL/Adapter/Text/Tests/Integration/TextTest.php index 4001741f4..b19334a1a 100644 --- a/src/adapter/etl-adapter-text/tests/Flow/ETL/Adapter/Text/Tests/Integration/TextTest.php +++ b/src/adapter/etl-adapter-text/tests/Flow/ETL/Adapter/Text/Tests/Integration/TextTest.php @@ -13,7 +13,7 @@ final class TextTest extends TestCase { public function test_loading_text_files() : void { - $path = __DIR__ . '/var/flow_php_etl_csv_loader' . bin2hex(random_bytes(16)) . '.csv'; + $path = __DIR__ . '/var/flow_php_etl_csv_loader' . \Flow\ETL\UniqueFactory::string(32) . '.csv'; (new Flow()) ->process( diff --git a/src/bridge/filesystem/azure/tests/Flow/Filesystem/Bridge/Azure/Tests/Unit/AzureBlobDestinationStreamTest.php b/src/bridge/filesystem/azure/tests/Flow/Filesystem/Bridge/Azure/Tests/Unit/AzureBlobDestinationStreamTest.php index e739b6a3a..077f7edcb 100644 --- a/src/bridge/filesystem/azure/tests/Flow/Filesystem/Bridge/Azure/Tests/Unit/AzureBlobDestinationStreamTest.php +++ b/src/bridge/filesystem/azure/tests/Flow/Filesystem/Bridge/Azure/Tests/Unit/AzureBlobDestinationStreamTest.php @@ -24,7 +24,7 @@ public function test_using_put_blob_with_content_when_data_is_larger_than_block_ $blockFactory->method('create') ->willReturnCallback( function () use ($blockSize) { - return new Block($id = \bin2hex(\random_bytes(16)), $blockSize, new Path(sys_get_temp_dir() . '/' . $id . '_block_01.txt')); + return new Block($id = \Flow\ETL\UniqueFactory::string(32), $blockSize, new Path(sys_get_temp_dir() . '/' . $id . '_block_01.txt')); } ); @@ -74,7 +74,7 @@ public function test_using_put_blob_with_content_when_data_is_smaller_than_block $blockFactory->method('create') ->willReturnCallback( function () use ($blockSize) { - return new Block($id = \bin2hex(\random_bytes(16)), $blockSize, new Path(sys_get_temp_dir() . '/' . $id . '_block_01.txt')); + return new Block($id = \Flow\ETL\UniqueFactory::string(32), $blockSize, new Path(sys_get_temp_dir() . '/' . $id . '_block_01.txt')); } ); $stream = AzureBlobDestinationStream::openBlank( diff --git a/src/core/etl/src/Flow/ETL/Config/ConfigBuilder.php b/src/core/etl/src/Flow/ETL/Config/ConfigBuilder.php index f09fc36b2..65828c38c 100644 --- a/src/core/etl/src/Flow/ETL/Config/ConfigBuilder.php +++ b/src/core/etl/src/Flow/ETL/Config/ConfigBuilder.php @@ -49,7 +49,7 @@ public function __construct() public function build() : Config { - $this->id ??= 'flow_php_' . bin2hex(random_bytes(16)); + $this->id ??= 'flow_php' . UniqueFactory::string(32); $entryFactory = new NativeEntryFactory(); $this->serializer ??= new Base64Serializer(new NativePHPSerializer()); diff --git a/src/core/etl/src/Flow/ETL/UniqueFactory.php b/src/core/etl/src/Flow/ETL/UniqueFactory.php new file mode 100644 index 000000000..33586d286 --- /dev/null +++ b/src/core/etl/src/Flow/ETL/UniqueFactory.php @@ -0,0 +1,22 @@ + $int */ + public static function string(int $int) : string + { + $bytes = (int) \ceil($int / 2); + $bytes >= 1 ?: $bytes = 1; + + return \mb_substr(\bin2hex(\random_bytes($bytes)), 0, \max(0, $int)); + } +} diff --git a/src/core/etl/tests/Flow/ETL/Tests/Double/FakeExtractor.php b/src/core/etl/tests/Flow/ETL/Tests/Double/FakeExtractor.php index be2ff2416..71c74e09c 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Double/FakeExtractor.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Double/FakeExtractor.php @@ -50,7 +50,7 @@ public function extract(FlowContext $context) : \Generator yield rows( row( int_entry('int', $id), - float_entry('float', \random_int(100, 100000) / 100), + float_entry('float', \Flow\ETL\UniqueFactory::int(100, 100000) / 100), bool_entry('bool', false), datetime_entry('datetime', new \DateTimeImmutable('now')), str_entry('null', null), diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Cache/PSRSimpleCacheTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Cache/PSRSimpleCacheTest.php new file mode 100644 index 000000000..e69de29bb diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/PartitioningTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/PartitioningTest.php index c523ced3a..aab8df5e2 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/PartitioningTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/PartitioningTest.php @@ -163,13 +163,13 @@ public function test_partition_by_partitions_order() : void function (int $i) : array { $data = []; - $maxItems = \random_int(2, 10); + $maxItems = \Flow\ETL\UniqueFactory::int(2, 10); for ($d = 0; $d < $maxItems; $d++) { $data[] = [ - 'id' => bin2hex(random_bytes(16)), - 'created_at' => (new \DateTimeImmutable('2020-01-01'))->add(new \DateInterval('P' . $i . 'D'))->setTime(\random_int(0, 23), \random_int(0, 59), \random_int(0, 59)), - 'value' => \random_int(1, 1000), + 'id' => \Flow\ETL\UniqueFactory::string(32), + 'created_at' => (new \DateTimeImmutable('2020-01-01'))->add(new \DateInterval('P' . $i . 'D'))->setTime(\Flow\ETL\UniqueFactory::int(0, 23), \Flow\ETL\UniqueFactory::int(0, 59), \Flow\ETL\UniqueFactory::int(0, 59)), + 'value' => \Flow\ETL\UniqueFactory::int(1, 1000), ]; } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Hash/NativePHPHashTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Hash/NativePHPHashTest.php index aa1bf3a24..487905570 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Hash/NativePHPHashTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Hash/NativePHPHashTest.php @@ -7,11 +7,11 @@ use Flow\ETL\Hash\NativePHPHash; use PHPUnit\Framework\TestCase; -class NativePHPHashTest extends TestCase +final class NativePHPHashTest extends TestCase { public static function test_hashing_xxh128_by_static_call() : void { - static::assertSame( + self::assertSame( '6c78e0e3bd51d358d01e758642b85fb8', NativePHPHash::xxh128('test'), ); @@ -19,7 +19,7 @@ public static function test_hashing_xxh128_by_static_call() : void public function test_hashing_string_using_xxh128_by_default() : void { - static::assertSame( + self::assertSame( '6c78e0e3bd51d358d01e758642b85fb8', (new NativePHPHash())->hash('test'), ); @@ -27,7 +27,7 @@ public function test_hashing_string_using_xxh128_by_default() : void public function test_support_sha512_hash() : void { - static::assertSame( + self::assertSame( 'ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff', (new NativePHPHash('sha512'))->hash('test') ); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/RowTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/RowTest.php index 17eff86d8..a2099c400 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/RowTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/RowTest.php @@ -78,8 +78,8 @@ public static function is_equal_data_provider() : \Generator public function test_getting_schema_from_row() : void { $row = row( - int_entry('id', \random_int(100, 100000)), - float_entry('price', \random_int(100, 100000) / 100), + int_entry('id', \Flow\ETL\UniqueFactory::int(100, 100000)), + float_entry('price', \Flow\ETL\UniqueFactory::int(100, 100000) / 100), bool_entry('deleted', false), datetime_entry('created-at', new \DateTimeImmutable('now')), str_entry('phase', null), diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/OrderEntriesTransformerTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/OrderEntriesTransformerTest.php index 7f53fa7e3..ae1cc8639 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/OrderEntriesTransformerTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/OrderEntriesTransformerTest.php @@ -46,8 +46,8 @@ public function test_ordering_entries_by_name_and_type() : void row( int_entry('int_a', 1), int_entry('int_b', 1), - float_entry('float_a', \random_int(100, 100000) / 100), - float_entry('float_b', \random_int(100, 100000) / 100), + float_entry('float_a', \Flow\ETL\UniqueFactory::int(100, 100000) / 100), + float_entry('float_b', \Flow\ETL\UniqueFactory::int(100, 100000) / 100), bool_entry('bool', false), bool_entry('bool_a', false), bool_entry('bool_c', false), @@ -141,7 +141,7 @@ public function test_ordering_entries_by_type() : void $rows = rows( row( int_entry('int', 1), - float_entry('float', \random_int(100, 100000) / 100), + float_entry('float', \Flow\ETL\UniqueFactory::int(100, 100000) / 100), bool_entry('bool', false), datetime_entry('datetime', new \DateTimeImmutable('now')), str_entry('null', null), diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/UniqueFactoryTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/UniqueFactoryTest.php new file mode 100644 index 000000000..7d3680837 --- /dev/null +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/UniqueFactoryTest.php @@ -0,0 +1,84 @@ + [2, 1], + ]; + } + + public static function valid_range_provider() : array + { + return [ + 'min equal to max' => [1, 1], + 'min less than max' => [1, 2], + 'min less than zero' => [-1, 1], + 'max and min less than zero' => [-1, -1], + ]; + } + + public function test_can_create_random_int_from_given_range() : void + { + self::assertSame(1, (UniqueFactory::int(1, 1))); + self::assertThat( + UniqueFactory::int(1, 2), + self::logicalOr( + self::equalTo(1), + self::equalTo(2) + ) + ); + } + + /** @dataProvider integers_provider */ + public function test_can_create_random_string_with_given_length(int $expectedLength) : void + { + self::assertSame($expectedLength, mb_strlen(UniqueFactory::string($expectedLength))); + } + + public function test_empty_string_on_length_below_1() : void + { + self::assertSame( + '', + UniqueFactory::string(0) + ); + self::assertSame( + '', + UniqueFactory::string(-1) + ); + } + + /** @dataProvider invalid_range_provider */ + public function test_fail_on_invalid_range(int $min, int $max) : void + { + self::expectException(\ValueError::class); + UniqueFactory::int($min, $max); + } + + /** @dataProvider valid_range_provider */ + public function test_return_random_int_on_valid_range(int $min, int $max) : void + { + self::assertThat( + UniqueFactory::int($min, $max), + self::logicalOr( + self::greaterThanOrEqual($min), + self::lessThanOrEqual($max) + ) + ); + } +} diff --git a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/MySqlBulkInsertTest.php b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/MySqlBulkInsertTest.php index 37918aab5..4c0551dca 100644 --- a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/MySqlBulkInsertTest.php +++ b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/MySqlBulkInsertTest.php @@ -33,9 +33,9 @@ public function test_inserts_multiple_rows_at_once() : void $this->databaseContext->connection(), $table, new BulkData([ - ['id' => $id1 = \bin2hex(\random_bytes(5)), 'age' => 20, 'name' => 'Name One', 'description' => 'Description One', 'active' => false, 'updated_at' => $date1 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], - ['id' => $id2 = \bin2hex(\random_bytes(5)), 'age' => 30, 'name' => 'Name Two', 'description' => null, 'active' => true, 'updated_at' => $date2 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], - ['id' => $id3 = \bin2hex(\random_bytes(5)), 'age' => 40, 'name' => 'Name Three', 'description' => 'Description Three', 'active' => false, 'updated_at' => $date3 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id1 = \Flow\ETL\UniqueFactory::string(10), 'age' => 20, 'name' => 'Name One', 'description' => 'Description One', 'active' => false, 'updated_at' => $date1 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id2 = \Flow\ETL\UniqueFactory::string(10), 'age' => 30, 'name' => 'Name Two', 'description' => null, 'active' => true, 'updated_at' => $date2 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id3 = \Flow\ETL\UniqueFactory::string(10), 'age' => 40, 'name' => 'Name Three', 'description' => 'Description Three', 'active' => false, 'updated_at' => $date3 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], ]) ); diff --git a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/PostgreSqlBulkInsertTest.php b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/PostgreSqlBulkInsertTest.php index a876ba6d7..a913b711a 100644 --- a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/PostgreSqlBulkInsertTest.php +++ b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/PostgreSqlBulkInsertTest.php @@ -35,9 +35,9 @@ public function test_inserts_multiple_rows_at_once() : void $this->databaseContext->connection(), $table, new BulkData([ - ['id' => $id1 = \bin2hex(\random_bytes(5)), 'age' => 20, 'name' => 'Name One', 'description' => 'Description One', 'active' => false, 'updated_at' => $date1->format(\DateTimeInterface::ATOM), 'tags' => \json_encode(['a', 'b', 'c'])], - ['id' => $id2 = \bin2hex(\random_bytes(5)), 'age' => 30, 'name' => 'Name Two', 'description' => null, 'active' => true, 'updated_at' => $date2 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], - ['id' => $id3 = \bin2hex(\random_bytes(5)), 'age' => 40, 'name' => 'Name Three', 'description' => 'Description Three', 'active' => false, 'updated_at' => $date3 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id1 = \Flow\ETL\UniqueFactory::string(10), 'age' => 20, 'name' => 'Name One', 'description' => 'Description One', 'active' => false, 'updated_at' => $date1->format(\DateTimeInterface::ATOM), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id2 = \Flow\ETL\UniqueFactory::string(10), 'age' => 30, 'name' => 'Name Two', 'description' => null, 'active' => true, 'updated_at' => $date2 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id3 = \Flow\ETL\UniqueFactory::string(10), 'age' => 40, 'name' => 'Name Three', 'description' => 'Description Three', 'active' => false, 'updated_at' => $date3 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], ]) ); diff --git a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/SqliteBulkInsertTest.php b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/SqliteBulkInsertTest.php index 0d7d14147..5ed70e983 100644 --- a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/SqliteBulkInsertTest.php +++ b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/SqliteBulkInsertTest.php @@ -33,9 +33,9 @@ public function test_inserts_multiple_rows_at_once() : void $this->databaseContext->connection(), $table, new BulkData([ - ['id' => $id1 = \bin2hex(\random_bytes(5)), 'age' => 20, 'name' => 'Name One', 'description' => 'Description One', 'active' => false, 'updated_at' => $date1 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], - ['id' => $id2 = \bin2hex(\random_bytes(5)), 'age' => 30, 'name' => 'Name Two', 'description' => null, 'active' => true, 'updated_at' => $date2 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], - ['id' => $id3 = \bin2hex(\random_bytes(5)), 'age' => 40, 'name' => 'Name Three', 'description' => 'Description Three', 'active' => false, 'updated_at' => $date3 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id1 = \Flow\ETL\UniqueFactory::string(10), 'age' => 20, 'name' => 'Name One', 'description' => 'Description One', 'active' => false, 'updated_at' => $date1 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id2 = \Flow\ETL\UniqueFactory::string(10), 'age' => 30, 'name' => 'Name Two', 'description' => null, 'active' => true, 'updated_at' => $date2 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id3 = \Flow\ETL\UniqueFactory::string(10), 'age' => 40, 'name' => 'Name Three', 'description' => 'Description Three', 'active' => false, 'updated_at' => $date3 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], ]) ); diff --git a/src/lib/filesystem/src/Flow/Filesystem/Path.php b/src/lib/filesystem/src/Flow/Filesystem/Path.php index a1a116398..1eb4297cd 100644 --- a/src/lib/filesystem/src/Flow/Filesystem/Path.php +++ b/src/lib/filesystem/src/Flow/Filesystem/Path.php @@ -280,7 +280,7 @@ public function randomize() : self $base = \trim(\mb_substr($this->path(), 0, \mb_strrpos($this->path(), $this->basename())), DIRECTORY_SEPARATOR); return new self( - $this->protocol->scheme() . $base . DIRECTORY_SEPARATOR . $this->filename . '_' . \bin2hex(\random_bytes(16)) . $extension, + $this->protocol->scheme() . $base . DIRECTORY_SEPARATOR . $this->filename . '_' . \Flow\ETL\UniqueFactory::string(32) . $extension, $this->options ); } diff --git a/src/lib/filesystem/src/Flow/Filesystem/Stream/Block/NativeLocalFileBlocksFactory.php b/src/lib/filesystem/src/Flow/Filesystem/Stream/Block/NativeLocalFileBlocksFactory.php index 44e25917c..373c97275 100644 --- a/src/lib/filesystem/src/Flow/Filesystem/Stream/Block/NativeLocalFileBlocksFactory.php +++ b/src/lib/filesystem/src/Flow/Filesystem/Stream/Block/NativeLocalFileBlocksFactory.php @@ -32,7 +32,7 @@ public function __construct(?string $blockLocation = null) public function create(int $size) : Block { - $id = \bin2hex(\random_bytes(16)); + $id = \Flow\ETL\UniqueFactory::string(32); return new Block($id, $size, new Path($this->blockLocation . DIRECTORY_SEPARATOR . $id)); } diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/CompressionTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/CompressionTest.php index 2de93d1bb..4622f82f8 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/CompressionTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/CompressionTest.php @@ -27,7 +27,7 @@ public function test_writing_and_reading_file_with_brotli_compression() : void self::markTestSkipped('The Brotli extension is not available'); } - $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(Compressions::BROTLI); @@ -51,11 +51,11 @@ public function test_writing_and_reading_file_with_brotli_compression() : void 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ), ], ], @@ -74,7 +74,7 @@ public function test_writing_and_reading_file_with_brotli_compression() : void public function test_writing_and_reading_file_with_gzip_compression() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(Compressions::GZIP); @@ -98,11 +98,11 @@ public function test_writing_and_reading_file_with_gzip_compression() : void 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ), ], ], @@ -126,7 +126,7 @@ public function test_writing_and_reading_file_with_lz4_compression() : void self::markTestSkipped('The lz4 extension is not available'); } - $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(Compressions::LZ4); @@ -150,11 +150,11 @@ public function test_writing_and_reading_file_with_lz4_compression() : void 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ), ], ], @@ -178,7 +178,7 @@ public function test_writing_and_reading_file_with_lz4_raw_compression() : void self::markTestSkipped('The lz4 extension is not available'); } - $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(Compressions::LZ4_RAW); @@ -202,11 +202,11 @@ public function test_writing_and_reading_file_with_lz4_raw_compression() : void 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ), ], ], @@ -230,7 +230,7 @@ public function test_writing_and_reading_file_with_snappy_compression() : void self::markTestSkipped('The snappy extension is not available'); } - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(Compressions::SNAPPY); @@ -254,11 +254,11 @@ public function test_writing_and_reading_file_with_snappy_compression() : void 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ), ], ], @@ -281,7 +281,7 @@ public function test_writing_and_reading_file_with_snappy_polyfill() : void self::markTestSkipped('The snappy extension is available'); } - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(Compressions::SNAPPY); @@ -305,11 +305,11 @@ public function test_writing_and_reading_file_with_snappy_polyfill() : void 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ), ], ], @@ -328,7 +328,7 @@ public function test_writing_and_reading_file_with_snappy_polyfill() : void public function test_writing_and_reading_file_with_uncompressed_compression() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(Compressions::UNCOMPRESSED); @@ -352,11 +352,11 @@ public function test_writing_and_reading_file_with_uncompressed_compression() : 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ), ], ], @@ -380,7 +380,7 @@ public function test_writing_and_reading_file_with_zstd_compression() : void self::markTestSkipped('The Zstd extension is not available'); } - $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(Compressions::ZSTD); @@ -404,11 +404,11 @@ public function test_writing_and_reading_file_with_zstd_compression() : void 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ), ], ], diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/ListsWritingTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/ListsWritingTest.php index e0b3307b0..bf5fe6365 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/ListsWritingTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/ListsWritingTest.php @@ -21,7 +21,7 @@ protected function setUp() : void public function test_writing_empty_lists_of_ints() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::list('list_of_ints', ListElement::int32())); @@ -44,7 +44,7 @@ public function test_writing_empty_lists_of_ints() : void public function test_writing_list_of_ints() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::list('list_of_ints', ListElement::int32())); @@ -53,7 +53,7 @@ public function test_writing_list_of_ints() : void $inputData = \array_merge(...\array_map(static function (int $i) use ($faker) : array { return [ [ - 'list_of_ints' => \array_map(static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), \range(1, \random_int(2, 10))), + 'list_of_ints' => \array_map(static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), \range(1, \Flow\ETL\UniqueFactory::int(2, 10))), ], ]; }, \range(1, 100))); @@ -68,7 +68,7 @@ public function test_writing_list_of_ints() : void public function test_writing_list_of_strings() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::list('list_of_strings', ListElement::string())); @@ -77,7 +77,7 @@ public function test_writing_list_of_strings() : void $inputData = \array_merge(...\array_map(static function (int $i) use ($faker) : array { return [ [ - 'list_of_strings' => \array_map(static fn ($i) => $faker->text(10), \range(1, \random_int(2, 10))), + 'list_of_strings' => \array_map(static fn ($i) => $faker->text(10), \range(1, \Flow\ETL\UniqueFactory::int(2, 10))), ], ]; }, \range(1, 100))); @@ -92,7 +92,7 @@ public function test_writing_list_of_strings() : void public function test_writing_list_of_structures() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with( @@ -111,7 +111,7 @@ public function test_writing_list_of_structures() : void 'list_of_structs' => \array_map(static fn ($i) => [ 'id' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'name' => $faker->text(10), - ], \range(1, \random_int(2, 10))), + ], \range(1, \Flow\ETL\UniqueFactory::int(2, 10))), ], ]; }, \range(1, 10))); @@ -126,7 +126,7 @@ public function test_writing_list_of_structures() : void public function test_writing_list_with_nullable_elements() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::list('list_of_ints', ListElement::int32())); @@ -136,7 +136,7 @@ public function test_writing_list_with_nullable_elements() : void return [ [ 'list_of_ints' => $i % 2 === 0 - ? \array_map(static fn ($a) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), \range(1, \random_int(2, 10))) + ? \array_map(static fn ($a) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), \range(1, \Flow\ETL\UniqueFactory::int(2, 10))) : null, ], ]; @@ -152,7 +152,7 @@ public function test_writing_list_with_nullable_elements() : void public function test_writing_list_with_nullable_list_values() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::list('list_of_ints', ListElement::int32())); @@ -162,7 +162,7 @@ public function test_writing_list_with_nullable_list_values() : void return [ [ 'list_of_ints' => $i % 2 === 0 - ? \array_map(static fn ($a) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), \range(1, \random_int(2, 2))) + ? \array_map(static fn ($a) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), \range(1, \Flow\ETL\UniqueFactory::int(2, 2))) : [null, null], ], ]; @@ -178,7 +178,7 @@ public function test_writing_list_with_nullable_list_values() : void public function test_writing_nullable_list_of_ints() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::list('list_of_ints', ListElement::int32())); @@ -188,7 +188,7 @@ public function test_writing_nullable_list_of_ints() : void return [ [ 'list_of_ints' => $i % 2 === 0 - ? \array_map(static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), \range(1, \random_int(2, 10))) + ? \array_map(static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), \range(1, \Flow\ETL\UniqueFactory::int(2, 10))) : null, ], ]; @@ -204,7 +204,7 @@ public function test_writing_nullable_list_of_ints() : void public function test_writing_nullable_list_of_structures() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with( @@ -227,7 +227,7 @@ public function test_writing_nullable_list_of_structures() : void ? \array_map(static fn ($i) => [ 'id' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'name' => $faker->text(10), - ], \range(1, \random_int(2, 10))) + ], \range(1, \Flow\ETL\UniqueFactory::int(2, 10))) : null, ], ]; @@ -243,7 +243,7 @@ public function test_writing_nullable_list_of_structures() : void public function test_writing_nullable_lists_of_ints() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::list('list_of_ints', ListElement::int32())); diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/MapsWritingTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/MapsWritingTest.php index 61564dafa..aa208ba0b 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/MapsWritingTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/MapsWritingTest.php @@ -21,7 +21,7 @@ protected function setUp() : void public function test_writing_empty_map_of_int_int() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::map('map_int_int', MapKey::int32(), MapValue::int32())); @@ -44,7 +44,7 @@ public function test_writing_empty_map_of_int_int() : void public function test_writing_map_of_int_int() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::map('map_int_int', MapKey::int32(), MapValue::int32())); @@ -56,7 +56,7 @@ public function test_writing_map_of_int_int() : void 'map_int_int' => \array_merge( ...\array_map( static fn ($i) => [$i => $faker->numberBetween(0, Consts::PHP_INT32_MAX)], - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ) ), ], @@ -73,7 +73,7 @@ public function test_writing_map_of_int_int() : void public function test_writing_map_of_int_int_with_all_maps_null() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::map('map_int_int', MapKey::int32(), MapValue::int32())); @@ -96,7 +96,7 @@ public function test_writing_map_of_int_int_with_all_maps_null() : void public function test_writing_map_of_int_string() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::map('map_int_string', MapKey::int32(), MapValue::string())); @@ -108,7 +108,7 @@ public function test_writing_map_of_int_string() : void 'map_int_string' => \array_merge( ...\array_map( static fn ($i) => [$i => $faker->text(10)], - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ) ), ], @@ -125,7 +125,7 @@ public function test_writing_map_of_int_string() : void public function test_writing_nullable_map_of_int_int() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::map('map_int_int', MapKey::int32(), MapValue::int32())); @@ -138,7 +138,7 @@ public function test_writing_nullable_map_of_int_int() : void ? \array_merge( ...\array_map( static fn ($i) => [$i => $faker->numberBetween(0, Consts::PHP_INT32_MAX)], - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ) ) : null, diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/PaginationTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/PaginationTest.php index 8799db67d..0faead760 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/PaginationTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/PaginationTest.php @@ -125,12 +125,12 @@ private function generateDataset(string $path) : void 'created_at' => new \DateTimeImmutable('2024-01-01 + ' . $i . ' days'), 'list_of_int' => \array_map( static fn (int $i) => $i, - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ), 'map_of_int_string' => \array_merge( ...\array_map( static fn (int $i) => [$i => 'value-' . $i], - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ) ), 'struct' => [ @@ -140,12 +140,12 @@ private function generateDataset(string $path) : void 'created_at' => new \DateTimeImmutable('2024-01-01 + ' . $i . ' days'), 'list_of_int' => \array_map( static fn (int $i) => $i, - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ), 'map_of_int_string' => \array_merge( ...\array_map( static fn (int $i) => [$i => 'value-' . $i], - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ) ), ], diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/SimpleTypesWritingTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/SimpleTypesWritingTest.php index 0d083bddd..063bc3633 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/SimpleTypesWritingTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/SimpleTypesWritingTest.php @@ -21,7 +21,7 @@ protected function setUp() : void public function test_writing_bool_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::boolean('boolean')); @@ -47,7 +47,7 @@ public function test_writing_bool_column() : void public function test_writing_bool_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::boolean('boolean')); @@ -55,7 +55,7 @@ public function test_writing_bool_nullable_column() : void $inputData = \array_merge(...\array_map(static function (int $i) : array { return [ [ - 'boolean' => $i % 2 == 0 ? (bool) \random_int(0, 1) : null, + 'boolean' => $i % 2 == 0 ? (bool) \Flow\ETL\UniqueFactory::int(0, 1) : null, ], ]; }, \range(1, 100))); @@ -73,7 +73,7 @@ public function test_writing_bool_nullable_column() : void public function test_writing_date_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::date('date')); @@ -101,7 +101,7 @@ public function test_writing_date_column() : void public function test_writing_date_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::date('date')); @@ -129,7 +129,7 @@ public function test_writing_date_nullable_column() : void public function test_writing_decimal_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::decimal('decimal')); @@ -157,7 +157,7 @@ public function test_writing_decimal_column() : void public function test_writing_decimal_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::decimal('decimal')); @@ -185,7 +185,7 @@ public function test_writing_decimal_nullable_column() : void public function test_writing_double_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::double('double')); @@ -213,7 +213,7 @@ public function test_writing_double_column() : void public function test_writing_double_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::double('double')); @@ -241,7 +241,7 @@ public function test_writing_double_nullable_column() : void public function test_writing_enum_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::enum('enum')); @@ -251,7 +251,7 @@ public function test_writing_enum_column() : void $inputData = \array_merge(...\array_map(static function (int $i) use ($enum) : array { return [ [ - 'enum' => $enum[\random_int(0, 3)], + 'enum' => $enum[\Flow\ETL\UniqueFactory::int(0, 3)], ], ]; }, \range(1, 100))); @@ -269,7 +269,7 @@ public function test_writing_enum_column() : void public function test_writing_float_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::float('float')); @@ -295,7 +295,7 @@ public function test_writing_float_column() : void public function test_writing_float_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::float('float')); @@ -321,7 +321,7 @@ public function test_writing_float_nullable_column() : void public function test_writing_int32_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::int32('int32')); @@ -349,7 +349,7 @@ public function test_writing_int32_column() : void public function test_writing_int32_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::int32('int32')); @@ -377,7 +377,7 @@ public function test_writing_int32_nullable_column() : void public function test_writing_int64() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::int64('int64')); @@ -404,7 +404,7 @@ public function test_writing_int64() : void public function test_writing_int64_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::int64('int64')); @@ -431,7 +431,7 @@ public function test_writing_int64_nullable_column() : void public function test_writing_json_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::json('json')); @@ -458,7 +458,7 @@ public function test_writing_json_column() : void public function test_writing_json_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::json('json')); @@ -487,7 +487,7 @@ public function test_writing_json_nullable_column() : void public function test_writing_string_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::string('string')); @@ -514,7 +514,7 @@ public function test_writing_string_column() : void public function test_writing_string_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::string('string')); @@ -541,7 +541,7 @@ public function test_writing_string_nullable_column() : void public function test_writing_time_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::time('time')); @@ -566,7 +566,7 @@ public function test_writing_time_column() : void public function test_writing_time_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::time('time')); @@ -591,7 +591,7 @@ public function test_writing_time_nullable_column() : void public function test_writing_timestamp_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::dateTime('dateTime')); @@ -618,7 +618,7 @@ public function test_writing_timestamp_column() : void public function test_writing_timestamp_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::dateTime('dateTime')); @@ -645,7 +645,7 @@ public function test_writing_timestamp_nullable_column() : void public function test_writing_uuid_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::uuid('uuid')); @@ -672,7 +672,7 @@ public function test_writing_uuid_column() : void public function test_writing_uuid_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::uuid('uuid')); diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/StructsWritingTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/StructsWritingTest.php index 5262f55cc..e59e9007a 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/StructsWritingTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/StructsWritingTest.php @@ -21,7 +21,7 @@ protected function setUp() : void public function test_writing_flat_nullable_structure() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::struct('struct', [ @@ -45,11 +45,11 @@ public function test_writing_flat_nullable_structure() : void 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ), ] : null, @@ -67,7 +67,7 @@ public function test_writing_flat_nullable_structure() : void public function test_writing_flat_structure() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::struct('struct', [ @@ -90,11 +90,11 @@ public function test_writing_flat_structure() : void 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ), ], ], @@ -111,7 +111,7 @@ public function test_writing_flat_structure() : void public function test_writing_flat_structure_with_nullable_elements() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::struct('struct', [ @@ -135,13 +135,13 @@ public function test_writing_flat_structure_with_nullable_elements() : void 'list_of_int' => $i % 2 === 0 ? \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ) : null, 'list_of_string' => $i % 2 === 0 ? \array_map( static fn ($i) => $faker->text(10), - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ) : null, ], diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/WriterTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/WriterTest.php index 2e0724e0a..0d130dc46 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/WriterTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/WriterTest.php @@ -36,7 +36,7 @@ public function test_created_by_metadata() : void { $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $schema = $this->createSchema(); $writer->open($path, $schema); @@ -51,7 +51,7 @@ public function test_opening_already_open_writer() : void { $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $schema = $this->createSchema(); @@ -80,7 +80,7 @@ public function test_writing_column_statistics() : void ->set(Option::WRITER_VERSION, 1) ); - $path = __DIR__ . '/var/test-writer-parquet-test-v2-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-v2-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $schema = Schema::with($column = FlatColumn::int32('int32')); @@ -109,7 +109,7 @@ public function test_writing_data_page_v2_statistics() : void ->set(Option::WRITER_VERSION, 2) ); - $path = __DIR__ . '/var/test-writer-parquet-test-v2-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-v2-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $schema = Schema::with($column = FlatColumn::int32('int32')); @@ -136,7 +136,7 @@ public function test_writing_in_batches_to_file() : void { $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $schema = $this->createSchema(); @@ -163,7 +163,7 @@ public function test_writing_in_batches_to_file_without_explicit_close() : void { $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $schema = $this->createSchema(); @@ -189,7 +189,7 @@ public function test_writing_in_batches_to_stream() : void { $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $schema = $this->createSchema(); @@ -227,7 +227,7 @@ public function test_writing_to_file() : void { $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $schema = $this->createSchema(); $row = $this->createRow(); @@ -249,7 +249,7 @@ public function test_writing_to_file_v2() : void ->set(Option::WRITER_VERSION, 2) ); - $path = __DIR__ . '/var/test-writer-parquet-test-v2-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-v2-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $schema = $this->createSchema(); $row = $this->createRow(); @@ -269,7 +269,7 @@ public function test_writing_to_stream() : void { $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $schema = $this->createSchema(); $row = $this->createRow(); @@ -298,11 +298,11 @@ private function createRow() : array 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \random_int(2, 10)) + \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) ), ], ]; diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/WriterValidatorTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/WriterValidatorTest.php index 449b77ed9..f0d32c9aa 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/WriterValidatorTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/WriterValidatorTest.php @@ -22,7 +22,7 @@ public function test_skipping_required_row() : void $this->expectExceptionMessage('Column "string" is required'); $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $schema = Schema::with( Schema\FlatColumn::int32('id'), @@ -37,7 +37,7 @@ public function test_writing_int_value_to_string_column() : void $this->expectExceptionMessage('Column "string" is not string, got "integer" instead'); $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $schema = Schema::with(Schema\FlatColumn::string('string')); @@ -49,7 +49,7 @@ public function test_writing_null_to_list_that_is_required() : void $this->expectExceptionMessage('Column "list" is required'); $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $schema = Schema::with(Schema\NestedColumn::list('list', Schema\ListElement::string())->makeRequired()); @@ -61,7 +61,7 @@ public function test_writing_null_to_list_with_element_is_required() : void $this->expectExceptionMessage('Column "list.list.element" is not string, got "NULL" instead'); $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $schema = Schema::with(Schema\NestedColumn::list('list', Schema\ListElement::string(required: true))); @@ -73,7 +73,7 @@ public function test_writing_null_to_map_with_value_required() : void $this->expectExceptionMessage('Column "map.key_value.value" is not string, got "NULL" instead'); $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $schema = Schema::with(Schema\NestedColumn::map('map', Schema\MapKey::string(), Schema\MapValue::string(required: true))); @@ -85,7 +85,7 @@ public function test_writing_null_to_required_map() : void $this->expectExceptionMessage('Column "map" is required'); $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $schema = Schema::with(Schema\NestedColumn::map('map', Schema\MapKey::string(), Schema\MapValue::string())->makeRequired()); @@ -97,7 +97,7 @@ public function test_writing_null_value_to_required_column() : void $this->expectExceptionMessage('Column "string" is required'); $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $schema = Schema::with(Schema\FlatColumn::string('string')->makeRequired()); @@ -107,7 +107,7 @@ public function test_writing_null_value_to_required_column() : void public function test_writing_row_with_missing_optional_columns() : void { $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $schema = Schema::with( Schema\FlatColumn::int32('id'), @@ -141,7 +141,7 @@ public function test_writing_row_with_missing_optional_columns() : void public function test_writing_row_with_missing_optional_columns_in_different_columns() : void { $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; + $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; $schema = Schema::with( Schema\FlatColumn::int32('id'), diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/ParquetFile/Data/RLEBitPackedHybridTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/ParquetFile/Data/RLEBitPackedHybridTest.php index 901a91f2c..f4b73b2fd 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/ParquetFile/Data/RLEBitPackedHybridTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/ParquetFile/Data/RLEBitPackedHybridTest.php @@ -230,10 +230,10 @@ public function test_with_dynamically_generated_values() : void { for ($iteration = 0; $iteration < 100; $iteration++) { $values = []; - $maxValues = \random_int(10, 1000); + $maxValues = \Flow\ETL\UniqueFactory::int(10, 1000); for ($i = 0; $i < $maxValues; $i++) { - $values[] = \random_int(0, 1000); + $values[] = \Flow\ETL\UniqueFactory::int(0, 1000); } $buffer = ''; diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/ParquetFile/RowGroupBuilder/PagesBuilderTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/ParquetFile/RowGroupBuilder/PagesBuilderTest.php index 249a12f72..714676bb4 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/ParquetFile/RowGroupBuilder/PagesBuilderTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/ParquetFile/RowGroupBuilder/PagesBuilderTest.php @@ -58,7 +58,7 @@ public function test_building_pages_for_enum_columns() : void 1 => 'GREEN', 2 => 'BLUE', ]; - $values = \array_map(static fn ($i) => $enum[\random_int(0, 2)], \range(0, 99)); + $values = \array_map(static fn ($i) => $enum[\Flow\ETL\UniqueFactory::int(0, 2)], \range(0, 99)); $statistics = new ColumnChunkStatistics($column); foreach ($values as $value) { diff --git a/src/lib/snappy/tests/Flow/Snappy/Tests/Integration/SnappyTest.php b/src/lib/snappy/tests/Flow/Snappy/Tests/Integration/SnappyTest.php index f91034de1..2273ade6a 100644 --- a/src/lib/snappy/tests/Flow/Snappy/Tests/Integration/SnappyTest.php +++ b/src/lib/snappy/tests/Flow/Snappy/Tests/Integration/SnappyTest.php @@ -71,7 +71,7 @@ public function test_snappy_compression_with_dynamically_generated_texts() : voi $snappy = new Snappy(); for ($iteration = 0; $iteration < 100; $iteration++) { - $string = Factory::create()->text(\random_int(10, 1000)); + $string = Factory::create()->text(\Flow\ETL\UniqueFactory::int(10, 1000)); self::assertSame( $string, From 96acd793dda7426db9b31ed6e186048dc0f7c6d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Mleczko?= Date: Mon, 22 Jul 2024 22:02:04 +0200 Subject: [PATCH 2/8] CS fixes Co-authored-by: Joseph Bielawski --- src/core/etl/src/Flow/ETL/UniqueFactory.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/etl/src/Flow/ETL/UniqueFactory.php b/src/core/etl/src/Flow/ETL/UniqueFactory.php index 33586d286..365318dcc 100644 --- a/src/core/etl/src/Flow/ETL/UniqueFactory.php +++ b/src/core/etl/src/Flow/ETL/UniqueFactory.php @@ -4,8 +4,12 @@ namespace Flow\ETL; -class UniqueFactory +final class UniqueFactory { + private function __construct() + { + } + public static function int(int $min, int $max) : int { return \random_int($min, $max); @@ -17,6 +21,6 @@ public static function string(int $int) : string $bytes = (int) \ceil($int / 2); $bytes >= 1 ?: $bytes = 1; - return \mb_substr(\bin2hex(\random_bytes($bytes)), 0, \max(0, $int)); + return \substr(\bin2hex(\random_bytes($bytes)), 0, \max(0, $int)); } } From 9937c456fc3a8ce862986ae3462697fe863fc21a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Mleczko?= Date: Wed, 31 Jul 2024 00:22:08 +0200 Subject: [PATCH 3/8] Rename to RandomGenerator, introduce interface --- .../ElasticsearchExtractorTest.php | 10 ++-- .../ElasticsearchLoaderTest.php | 8 +-- .../MeilisearchExtractorTest.php | 6 +-- .../MeilisearchPHP/MeilisearchLoaderTest.php | 8 +-- .../Text/Tests/Integration/TextTest.php | 2 +- .../Unit/AzureBlobDestinationStreamTest.php | 4 +- .../etl/src/Flow/ETL/Config/ConfigBuilder.php | 2 +- ....php => NativePHPRandomValueGenerator.php} | 2 +- .../etl/src/Flow/ETL/RandomValueGenerator.php | 13 +++++ .../Flow/ETL/Tests/Double/FakeExtractor.php | 2 +- .../DataFrame/PartitioningTest.php | 8 +-- ... => NativePHPRandomValueGeneratorTest.php} | 18 +++---- .../etl/tests/Flow/ETL/Tests/Unit/RowTest.php | 4 +- .../OrderEntriesTransformerTest.php | 6 +-- .../Tests/Integration/MySqlBulkInsertTest.php | 6 +-- .../Integration/PostgreSqlBulkInsertTest.php | 6 +-- .../Integration/SqliteBulkInsertTest.php | 6 +-- .../filesystem/src/Flow/Filesystem/Path.php | 2 +- .../Block/NativeLocalFileBlocksFactory.php | 2 +- .../Tests/Integration/IO/CompressionTest.php | 48 ++++++++--------- .../Tests/Integration/IO/ListsWritingTest.php | 32 +++++------ .../Tests/Integration/IO/MapsWritingTest.php | 16 +++--- .../Tests/Integration/IO/PaginationTest.php | 8 +-- .../Integration/IO/SimpleTypesWritingTest.php | 54 +++++++++---------- .../Integration/IO/StructsWritingTest.php | 18 +++---- .../Tests/Integration/IO/WriterTest.php | 24 ++++----- .../Integration/IO/WriterValidatorTest.php | 18 +++---- .../Data/RLEBitPackedHybridTest.php | 4 +- .../RowGroupBuilder/PagesBuilderTest.php | 2 +- .../Snappy/Tests/Integration/SnappyTest.php | 2 +- 30 files changed, 177 insertions(+), 164 deletions(-) rename src/core/etl/src/Flow/ETL/{UniqueFactory.php => NativePHPRandomValueGenerator.php} (86%) create mode 100644 src/core/etl/src/Flow/ETL/RandomValueGenerator.php rename src/core/etl/tests/Flow/ETL/Tests/Unit/{UniqueFactoryTest.php => NativePHPRandomValueGeneratorTest.php} (75%) diff --git a/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchExtractorTest.php b/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchExtractorTest.php index b2772eb39..badfd8892 100644 --- a/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchExtractorTest.php +++ b/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchExtractorTest.php @@ -40,7 +40,7 @@ public function test_empty_extraction() : void new Row\Entry\StringEntry('id', \sha1((string) $i)), new Row\Entry\IntegerEntry('position', $i), new Row\Entry\StringEntry('name', 'id_' . $i), - new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\UniqueFactory::int(0, 1)) + new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\NativePHPRandomValueGenerator::int(0, 1)) ), \range(1, 100) ), @@ -80,7 +80,7 @@ public function test_extraction_index_with_from_and_size() : void new Row\Entry\StringEntry('id', \sha1((string) $i)), new Row\Entry\IntegerEntry('position', $i), new Row\Entry\StringEntry('name', 'id_' . $i), - new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\UniqueFactory::int(0, 1)) + new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\NativePHPRandomValueGenerator::int(0, 1)) ), \range(1, 2000) ), @@ -123,7 +123,7 @@ public function test_extraction_index_with_search_after() : void new Row\Entry\StringEntry('id', \sha1((string) $i)), new Row\Entry\IntegerEntry('position', $i), new Row\Entry\StringEntry('name', 'id_' . $i), - new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\UniqueFactory::int(0, 1)) + new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\NativePHPRandomValueGenerator::int(0, 1)) ), \range(1, 2005) ), @@ -159,7 +159,7 @@ public function test_extraction_index_with_search_after_with_point_in_time() : v new Row\Entry\StringEntry('id', \sha1((string) $i)), new Row\Entry\IntegerEntry('position', $i), new Row\Entry\StringEntry('name', 'id_' . $i), - new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\UniqueFactory::int(0, 1)) + new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\NativePHPRandomValueGenerator::int(0, 1)) ), \range(1, 2005) ), @@ -200,7 +200,7 @@ public function test_extraction_whole_index_with_point_in_time() : void new Row\Entry\StringEntry('id', \sha1((string) $i)), new Row\Entry\IntegerEntry('position', $i), new Row\Entry\StringEntry('name', 'id_' . $i), - new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\UniqueFactory::int(0, 1)) + new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\NativePHPRandomValueGenerator::int(0, 1)) ), \range(1, 2005) ), diff --git a/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchLoaderTest.php b/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchLoaderTest.php index f766f121c..922c6bdd7 100644 --- a/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchLoaderTest.php +++ b/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchLoaderTest.php @@ -53,19 +53,19 @@ public function test_integration_with_entry_factory() : void $loader->load(new Rows( Row::create( - new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\UniqueFactory::string(32))), + new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\NativePHPRandomValueGenerator::string(32))), new Row\Entry\StringEntry('name', 'Łukasz') ), Row::create( - new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\UniqueFactory::string(32))), + new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\NativePHPRandomValueGenerator::string(32))), new Row\Entry\StringEntry('name', 'Norbert') ), Row::create( - new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\UniqueFactory::string(32))), + new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\NativePHPRandomValueGenerator::string(32))), new Row\Entry\StringEntry('name', 'Dawid') ), Row::create( - new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\UniqueFactory::string(32))), + new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\NativePHPRandomValueGenerator::string(32))), new Row\Entry\StringEntry('name', 'Tomek') ), ), new FlowContext(Config::default())); diff --git a/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchExtractorTest.php b/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchExtractorTest.php index dfde6d0ee..2c9d71be0 100644 --- a/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchExtractorTest.php +++ b/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchExtractorTest.php @@ -37,7 +37,7 @@ public function test_empty_extraction() : void new Row\Entry\StringEntry('id', \sha1((string) $i)), new Row\Entry\IntegerEntry('position', $i), new Row\Entry\StringEntry('name', 'id_' . $i), - new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\UniqueFactory::int(0, 1)) + new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\NativePHPRandomValueGenerator::int(0, 1)) ), \range(1, 100) ), @@ -63,7 +63,7 @@ public function test_extraction_index_with_from_and_size() : void new Row\Entry\StringEntry('id', \sha1((string) $i)), new Row\Entry\IntegerEntry('position', $i), new Row\Entry\StringEntry('name', 'id_' . $i), - new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\UniqueFactory::int(0, 1)) + new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\NativePHPRandomValueGenerator::int(0, 1)) ), // Default limit for Meilisearch is 1000 documents: https://www.meilisearch.com/docs/reference/api/settings#pagination \range(1, 999) @@ -102,7 +102,7 @@ public function test_extraction_index_with_sort() : void new Row\Entry\StringEntry('id', \sha1((string) $i)), new Row\Entry\IntegerEntry('position', $i), new Row\Entry\StringEntry('name', 'id_' . $i), - new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\UniqueFactory::int(0, 1)) + new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\NativePHPRandomValueGenerator::int(0, 1)) ), // Default limit for Meilisearch is 1000 documents: https://www.meilisearch.com/docs/reference/api/settings#pagination \range(1, 999) diff --git a/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchLoaderTest.php b/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchLoaderTest.php index 7d20ce830..62b648fe1 100644 --- a/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchLoaderTest.php +++ b/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchLoaderTest.php @@ -43,19 +43,19 @@ public function test_integration_with_entry_factory() : void $loader = to_meilisearch_bulk_index($this->meilisearchContext->clientConfig(), self::INDEX_NAME); $loader->load(new Rows( Row::create( - new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\UniqueFactory::string(32))), + new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\NativePHPRandomValueGenerator::string(32))), new Row\Entry\StringEntry('name', 'Łukasz') ), Row::create( - new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\UniqueFactory::string(32))), + new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\NativePHPRandomValueGenerator::string(32))), new Row\Entry\StringEntry('name', 'Norbert') ), Row::create( - new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\UniqueFactory::string(32))), + new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\NativePHPRandomValueGenerator::string(32))), new Row\Entry\StringEntry('name', 'Dawid') ), Row::create( - new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\UniqueFactory::string(32))), + new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\NativePHPRandomValueGenerator::string(32))), new Row\Entry\StringEntry('name', 'Tomek') ), ), new FlowContext(Config::default())); diff --git a/src/adapter/etl-adapter-text/tests/Flow/ETL/Adapter/Text/Tests/Integration/TextTest.php b/src/adapter/etl-adapter-text/tests/Flow/ETL/Adapter/Text/Tests/Integration/TextTest.php index b19334a1a..fbc2fc30d 100644 --- a/src/adapter/etl-adapter-text/tests/Flow/ETL/Adapter/Text/Tests/Integration/TextTest.php +++ b/src/adapter/etl-adapter-text/tests/Flow/ETL/Adapter/Text/Tests/Integration/TextTest.php @@ -13,7 +13,7 @@ final class TextTest extends TestCase { public function test_loading_text_files() : void { - $path = __DIR__ . '/var/flow_php_etl_csv_loader' . \Flow\ETL\UniqueFactory::string(32) . '.csv'; + $path = __DIR__ . '/var/flow_php_etl_csv_loader' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.csv'; (new Flow()) ->process( diff --git a/src/bridge/filesystem/azure/tests/Flow/Filesystem/Bridge/Azure/Tests/Unit/AzureBlobDestinationStreamTest.php b/src/bridge/filesystem/azure/tests/Flow/Filesystem/Bridge/Azure/Tests/Unit/AzureBlobDestinationStreamTest.php index 077f7edcb..7bd9c80a7 100644 --- a/src/bridge/filesystem/azure/tests/Flow/Filesystem/Bridge/Azure/Tests/Unit/AzureBlobDestinationStreamTest.php +++ b/src/bridge/filesystem/azure/tests/Flow/Filesystem/Bridge/Azure/Tests/Unit/AzureBlobDestinationStreamTest.php @@ -24,7 +24,7 @@ public function test_using_put_blob_with_content_when_data_is_larger_than_block_ $blockFactory->method('create') ->willReturnCallback( function () use ($blockSize) { - return new Block($id = \Flow\ETL\UniqueFactory::string(32), $blockSize, new Path(sys_get_temp_dir() . '/' . $id . '_block_01.txt')); + return new Block($id = \Flow\ETL\NativePHPRandomValueGenerator::string(32), $blockSize, new Path(sys_get_temp_dir() . '/' . $id . '_block_01.txt')); } ); @@ -74,7 +74,7 @@ public function test_using_put_blob_with_content_when_data_is_smaller_than_block $blockFactory->method('create') ->willReturnCallback( function () use ($blockSize) { - return new Block($id = \Flow\ETL\UniqueFactory::string(32), $blockSize, new Path(sys_get_temp_dir() . '/' . $id . '_block_01.txt')); + return new Block($id = \Flow\ETL\NativePHPRandomValueGenerator::string(32), $blockSize, new Path(sys_get_temp_dir() . '/' . $id . '_block_01.txt')); } ); $stream = AzureBlobDestinationStream::openBlank( diff --git a/src/core/etl/src/Flow/ETL/Config/ConfigBuilder.php b/src/core/etl/src/Flow/ETL/Config/ConfigBuilder.php index 65828c38c..34b3ae999 100644 --- a/src/core/etl/src/Flow/ETL/Config/ConfigBuilder.php +++ b/src/core/etl/src/Flow/ETL/Config/ConfigBuilder.php @@ -49,7 +49,7 @@ public function __construct() public function build() : Config { - $this->id ??= 'flow_php' . UniqueFactory::string(32); + $this->id ??= 'flow_php' . NativePHPRandomValueGenerator::string(32); $entryFactory = new NativeEntryFactory(); $this->serializer ??= new Base64Serializer(new NativePHPSerializer()); diff --git a/src/core/etl/src/Flow/ETL/UniqueFactory.php b/src/core/etl/src/Flow/ETL/NativePHPRandomValueGenerator.php similarity index 86% rename from src/core/etl/src/Flow/ETL/UniqueFactory.php rename to src/core/etl/src/Flow/ETL/NativePHPRandomValueGenerator.php index 365318dcc..0c1ca5b82 100644 --- a/src/core/etl/src/Flow/ETL/UniqueFactory.php +++ b/src/core/etl/src/Flow/ETL/NativePHPRandomValueGenerator.php @@ -4,7 +4,7 @@ namespace Flow\ETL; -final class UniqueFactory +final class NativePHPRandomValueGenerator implements RandomValueGenerator { private function __construct() { diff --git a/src/core/etl/src/Flow/ETL/RandomValueGenerator.php b/src/core/etl/src/Flow/ETL/RandomValueGenerator.php new file mode 100644 index 000000000..e4f3eedf8 --- /dev/null +++ b/src/core/etl/src/Flow/ETL/RandomValueGenerator.php @@ -0,0 +1,13 @@ + $int */ + public static function string(int $int) : string; +} diff --git a/src/core/etl/tests/Flow/ETL/Tests/Double/FakeExtractor.php b/src/core/etl/tests/Flow/ETL/Tests/Double/FakeExtractor.php index 71c74e09c..195026be5 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Double/FakeExtractor.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Double/FakeExtractor.php @@ -50,7 +50,7 @@ public function extract(FlowContext $context) : \Generator yield rows( row( int_entry('int', $id), - float_entry('float', \Flow\ETL\UniqueFactory::int(100, 100000) / 100), + float_entry('float', \Flow\ETL\NativePHPRandomValueGenerator::int(100, 100000) / 100), bool_entry('bool', false), datetime_entry('datetime', new \DateTimeImmutable('now')), str_entry('null', null), diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/PartitioningTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/PartitioningTest.php index aab8df5e2..06cfe8b71 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/PartitioningTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/PartitioningTest.php @@ -163,13 +163,13 @@ public function test_partition_by_partitions_order() : void function (int $i) : array { $data = []; - $maxItems = \Flow\ETL\UniqueFactory::int(2, 10); + $maxItems = \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10); for ($d = 0; $d < $maxItems; $d++) { $data[] = [ - 'id' => \Flow\ETL\UniqueFactory::string(32), - 'created_at' => (new \DateTimeImmutable('2020-01-01'))->add(new \DateInterval('P' . $i . 'D'))->setTime(\Flow\ETL\UniqueFactory::int(0, 23), \Flow\ETL\UniqueFactory::int(0, 59), \Flow\ETL\UniqueFactory::int(0, 59)), - 'value' => \Flow\ETL\UniqueFactory::int(1, 1000), + 'id' => \Flow\ETL\NativePHPRandomValueGenerator::string(32), + 'created_at' => (new \DateTimeImmutable('2020-01-01'))->add(new \DateInterval('P' . $i . 'D'))->setTime(\Flow\ETL\NativePHPRandomValueGenerator::int(0, 23), \Flow\ETL\NativePHPRandomValueGenerator::int(0, 59), \Flow\ETL\NativePHPRandomValueGenerator::int(0, 59)), + 'value' => \Flow\ETL\NativePHPRandomValueGenerator::int(1, 1000), ]; } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/UniqueFactoryTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/NativePHPRandomValueGeneratorTest.php similarity index 75% rename from src/core/etl/tests/Flow/ETL/Tests/Unit/UniqueFactoryTest.php rename to src/core/etl/tests/Flow/ETL/Tests/Unit/NativePHPRandomValueGeneratorTest.php index 7d3680837..99be62182 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/UniqueFactoryTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/NativePHPRandomValueGeneratorTest.php @@ -4,10 +4,10 @@ namespace Flow\ETL\Tests\Unit; -use Flow\ETL\UniqueFactory; +use Flow\ETL\NativePHPRandomValueGenerator; use PHPUnit\Framework\TestCase; -final class UniqueFactoryTest extends TestCase +final class NativePHPRandomValueGeneratorTest extends TestCase { public static function integers_provider() : \Generator { @@ -35,9 +35,9 @@ public static function valid_range_provider() : array public function test_can_create_random_int_from_given_range() : void { - self::assertSame(1, (UniqueFactory::int(1, 1))); + self::assertSame(1, (NativePHPRandomValueGenerator::int(1, 1))); self::assertThat( - UniqueFactory::int(1, 2), + NativePHPRandomValueGenerator::int(1, 2), self::logicalOr( self::equalTo(1), self::equalTo(2) @@ -48,18 +48,18 @@ public function test_can_create_random_int_from_given_range() : void /** @dataProvider integers_provider */ public function test_can_create_random_string_with_given_length(int $expectedLength) : void { - self::assertSame($expectedLength, mb_strlen(UniqueFactory::string($expectedLength))); + self::assertSame($expectedLength, mb_strlen(NativePHPRandomValueGenerator::string($expectedLength))); } public function test_empty_string_on_length_below_1() : void { self::assertSame( '', - UniqueFactory::string(0) + NativePHPRandomValueGenerator::string(0) ); self::assertSame( '', - UniqueFactory::string(-1) + NativePHPRandomValueGenerator::string(-1) ); } @@ -67,14 +67,14 @@ public function test_empty_string_on_length_below_1() : void public function test_fail_on_invalid_range(int $min, int $max) : void { self::expectException(\ValueError::class); - UniqueFactory::int($min, $max); + NativePHPRandomValueGenerator::int($min, $max); } /** @dataProvider valid_range_provider */ public function test_return_random_int_on_valid_range(int $min, int $max) : void { self::assertThat( - UniqueFactory::int($min, $max), + NativePHPRandomValueGenerator::int($min, $max), self::logicalOr( self::greaterThanOrEqual($min), self::lessThanOrEqual($max) diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/RowTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/RowTest.php index a2099c400..a416d609c 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/RowTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/RowTest.php @@ -78,8 +78,8 @@ public static function is_equal_data_provider() : \Generator public function test_getting_schema_from_row() : void { $row = row( - int_entry('id', \Flow\ETL\UniqueFactory::int(100, 100000)), - float_entry('price', \Flow\ETL\UniqueFactory::int(100, 100000) / 100), + int_entry('id', \Flow\ETL\NativePHPRandomValueGenerator::int(100, 100000)), + float_entry('price', \Flow\ETL\NativePHPRandomValueGenerator::int(100, 100000) / 100), bool_entry('deleted', false), datetime_entry('created-at', new \DateTimeImmutable('now')), str_entry('phase', null), diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/OrderEntriesTransformerTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/OrderEntriesTransformerTest.php index ae1cc8639..2e1adcfe3 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/OrderEntriesTransformerTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/OrderEntriesTransformerTest.php @@ -46,8 +46,8 @@ public function test_ordering_entries_by_name_and_type() : void row( int_entry('int_a', 1), int_entry('int_b', 1), - float_entry('float_a', \Flow\ETL\UniqueFactory::int(100, 100000) / 100), - float_entry('float_b', \Flow\ETL\UniqueFactory::int(100, 100000) / 100), + float_entry('float_a', \Flow\ETL\NativePHPRandomValueGenerator::int(100, 100000) / 100), + float_entry('float_b', \Flow\ETL\NativePHPRandomValueGenerator::int(100, 100000) / 100), bool_entry('bool', false), bool_entry('bool_a', false), bool_entry('bool_c', false), @@ -141,7 +141,7 @@ public function test_ordering_entries_by_type() : void $rows = rows( row( int_entry('int', 1), - float_entry('float', \Flow\ETL\UniqueFactory::int(100, 100000) / 100), + float_entry('float', \Flow\ETL\NativePHPRandomValueGenerator::int(100, 100000) / 100), bool_entry('bool', false), datetime_entry('datetime', new \DateTimeImmutable('now')), str_entry('null', null), diff --git a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/MySqlBulkInsertTest.php b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/MySqlBulkInsertTest.php index 4c0551dca..88780d4fd 100644 --- a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/MySqlBulkInsertTest.php +++ b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/MySqlBulkInsertTest.php @@ -33,9 +33,9 @@ public function test_inserts_multiple_rows_at_once() : void $this->databaseContext->connection(), $table, new BulkData([ - ['id' => $id1 = \Flow\ETL\UniqueFactory::string(10), 'age' => 20, 'name' => 'Name One', 'description' => 'Description One', 'active' => false, 'updated_at' => $date1 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], - ['id' => $id2 = \Flow\ETL\UniqueFactory::string(10), 'age' => 30, 'name' => 'Name Two', 'description' => null, 'active' => true, 'updated_at' => $date2 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], - ['id' => $id3 = \Flow\ETL\UniqueFactory::string(10), 'age' => 40, 'name' => 'Name Three', 'description' => 'Description Three', 'active' => false, 'updated_at' => $date3 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id1 = \Flow\ETL\NativePHPRandomValueGenerator::string(10), 'age' => 20, 'name' => 'Name One', 'description' => 'Description One', 'active' => false, 'updated_at' => $date1 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id2 = \Flow\ETL\NativePHPRandomValueGenerator::string(10), 'age' => 30, 'name' => 'Name Two', 'description' => null, 'active' => true, 'updated_at' => $date2 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id3 = \Flow\ETL\NativePHPRandomValueGenerator::string(10), 'age' => 40, 'name' => 'Name Three', 'description' => 'Description Three', 'active' => false, 'updated_at' => $date3 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], ]) ); diff --git a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/PostgreSqlBulkInsertTest.php b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/PostgreSqlBulkInsertTest.php index a913b711a..ea6645dde 100644 --- a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/PostgreSqlBulkInsertTest.php +++ b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/PostgreSqlBulkInsertTest.php @@ -35,9 +35,9 @@ public function test_inserts_multiple_rows_at_once() : void $this->databaseContext->connection(), $table, new BulkData([ - ['id' => $id1 = \Flow\ETL\UniqueFactory::string(10), 'age' => 20, 'name' => 'Name One', 'description' => 'Description One', 'active' => false, 'updated_at' => $date1->format(\DateTimeInterface::ATOM), 'tags' => \json_encode(['a', 'b', 'c'])], - ['id' => $id2 = \Flow\ETL\UniqueFactory::string(10), 'age' => 30, 'name' => 'Name Two', 'description' => null, 'active' => true, 'updated_at' => $date2 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], - ['id' => $id3 = \Flow\ETL\UniqueFactory::string(10), 'age' => 40, 'name' => 'Name Three', 'description' => 'Description Three', 'active' => false, 'updated_at' => $date3 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id1 = \Flow\ETL\NativePHPRandomValueGenerator::string(10), 'age' => 20, 'name' => 'Name One', 'description' => 'Description One', 'active' => false, 'updated_at' => $date1->format(\DateTimeInterface::ATOM), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id2 = \Flow\ETL\NativePHPRandomValueGenerator::string(10), 'age' => 30, 'name' => 'Name Two', 'description' => null, 'active' => true, 'updated_at' => $date2 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id3 = \Flow\ETL\NativePHPRandomValueGenerator::string(10), 'age' => 40, 'name' => 'Name Three', 'description' => 'Description Three', 'active' => false, 'updated_at' => $date3 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], ]) ); diff --git a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/SqliteBulkInsertTest.php b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/SqliteBulkInsertTest.php index 5ed70e983..7404efc2c 100644 --- a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/SqliteBulkInsertTest.php +++ b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/SqliteBulkInsertTest.php @@ -33,9 +33,9 @@ public function test_inserts_multiple_rows_at_once() : void $this->databaseContext->connection(), $table, new BulkData([ - ['id' => $id1 = \Flow\ETL\UniqueFactory::string(10), 'age' => 20, 'name' => 'Name One', 'description' => 'Description One', 'active' => false, 'updated_at' => $date1 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], - ['id' => $id2 = \Flow\ETL\UniqueFactory::string(10), 'age' => 30, 'name' => 'Name Two', 'description' => null, 'active' => true, 'updated_at' => $date2 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], - ['id' => $id3 = \Flow\ETL\UniqueFactory::string(10), 'age' => 40, 'name' => 'Name Three', 'description' => 'Description Three', 'active' => false, 'updated_at' => $date3 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id1 = \Flow\ETL\NativePHPRandomValueGenerator::string(10), 'age' => 20, 'name' => 'Name One', 'description' => 'Description One', 'active' => false, 'updated_at' => $date1 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id2 = \Flow\ETL\NativePHPRandomValueGenerator::string(10), 'age' => 30, 'name' => 'Name Two', 'description' => null, 'active' => true, 'updated_at' => $date2 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id3 = \Flow\ETL\NativePHPRandomValueGenerator::string(10), 'age' => 40, 'name' => 'Name Three', 'description' => 'Description Three', 'active' => false, 'updated_at' => $date3 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], ]) ); diff --git a/src/lib/filesystem/src/Flow/Filesystem/Path.php b/src/lib/filesystem/src/Flow/Filesystem/Path.php index 1eb4297cd..5c7248acf 100644 --- a/src/lib/filesystem/src/Flow/Filesystem/Path.php +++ b/src/lib/filesystem/src/Flow/Filesystem/Path.php @@ -280,7 +280,7 @@ public function randomize() : self $base = \trim(\mb_substr($this->path(), 0, \mb_strrpos($this->path(), $this->basename())), DIRECTORY_SEPARATOR); return new self( - $this->protocol->scheme() . $base . DIRECTORY_SEPARATOR . $this->filename . '_' . \Flow\ETL\UniqueFactory::string(32) . $extension, + $this->protocol->scheme() . $base . DIRECTORY_SEPARATOR . $this->filename . '_' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . $extension, $this->options ); } diff --git a/src/lib/filesystem/src/Flow/Filesystem/Stream/Block/NativeLocalFileBlocksFactory.php b/src/lib/filesystem/src/Flow/Filesystem/Stream/Block/NativeLocalFileBlocksFactory.php index 373c97275..1e38e6ec3 100644 --- a/src/lib/filesystem/src/Flow/Filesystem/Stream/Block/NativeLocalFileBlocksFactory.php +++ b/src/lib/filesystem/src/Flow/Filesystem/Stream/Block/NativeLocalFileBlocksFactory.php @@ -32,7 +32,7 @@ public function __construct(?string $blockLocation = null) public function create(int $size) : Block { - $id = \Flow\ETL\UniqueFactory::string(32); + $id = \Flow\ETL\NativePHPRandomValueGenerator::string(32); return new Block($id, $size, new Path($this->blockLocation . DIRECTORY_SEPARATOR . $id)); } diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/CompressionTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/CompressionTest.php index 4622f82f8..394618d81 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/CompressionTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/CompressionTest.php @@ -27,7 +27,7 @@ public function test_writing_and_reading_file_with_brotli_compression() : void self::markTestSkipped('The Brotli extension is not available'); } - $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(Compressions::BROTLI); @@ -51,11 +51,11 @@ public function test_writing_and_reading_file_with_brotli_compression() : void 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ), ], ], @@ -74,7 +74,7 @@ public function test_writing_and_reading_file_with_brotli_compression() : void public function test_writing_and_reading_file_with_gzip_compression() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(Compressions::GZIP); @@ -98,11 +98,11 @@ public function test_writing_and_reading_file_with_gzip_compression() : void 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ), ], ], @@ -126,7 +126,7 @@ public function test_writing_and_reading_file_with_lz4_compression() : void self::markTestSkipped('The lz4 extension is not available'); } - $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(Compressions::LZ4); @@ -150,11 +150,11 @@ public function test_writing_and_reading_file_with_lz4_compression() : void 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ), ], ], @@ -178,7 +178,7 @@ public function test_writing_and_reading_file_with_lz4_raw_compression() : void self::markTestSkipped('The lz4 extension is not available'); } - $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(Compressions::LZ4_RAW); @@ -202,11 +202,11 @@ public function test_writing_and_reading_file_with_lz4_raw_compression() : void 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ), ], ], @@ -230,7 +230,7 @@ public function test_writing_and_reading_file_with_snappy_compression() : void self::markTestSkipped('The snappy extension is not available'); } - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(Compressions::SNAPPY); @@ -254,11 +254,11 @@ public function test_writing_and_reading_file_with_snappy_compression() : void 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ), ], ], @@ -281,7 +281,7 @@ public function test_writing_and_reading_file_with_snappy_polyfill() : void self::markTestSkipped('The snappy extension is available'); } - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(Compressions::SNAPPY); @@ -305,11 +305,11 @@ public function test_writing_and_reading_file_with_snappy_polyfill() : void 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ), ], ], @@ -328,7 +328,7 @@ public function test_writing_and_reading_file_with_snappy_polyfill() : void public function test_writing_and_reading_file_with_uncompressed_compression() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(Compressions::UNCOMPRESSED); @@ -352,11 +352,11 @@ public function test_writing_and_reading_file_with_uncompressed_compression() : 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ), ], ], @@ -380,7 +380,7 @@ public function test_writing_and_reading_file_with_zstd_compression() : void self::markTestSkipped('The Zstd extension is not available'); } - $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(Compressions::ZSTD); @@ -404,11 +404,11 @@ public function test_writing_and_reading_file_with_zstd_compression() : void 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ), ], ], diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/ListsWritingTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/ListsWritingTest.php index bf5fe6365..ac5b58abc 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/ListsWritingTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/ListsWritingTest.php @@ -21,7 +21,7 @@ protected function setUp() : void public function test_writing_empty_lists_of_ints() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::list('list_of_ints', ListElement::int32())); @@ -44,7 +44,7 @@ public function test_writing_empty_lists_of_ints() : void public function test_writing_list_of_ints() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::list('list_of_ints', ListElement::int32())); @@ -53,7 +53,7 @@ public function test_writing_list_of_ints() : void $inputData = \array_merge(...\array_map(static function (int $i) use ($faker) : array { return [ [ - 'list_of_ints' => \array_map(static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), \range(1, \Flow\ETL\UniqueFactory::int(2, 10))), + 'list_of_ints' => \array_map(static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10))), ], ]; }, \range(1, 100))); @@ -68,7 +68,7 @@ public function test_writing_list_of_ints() : void public function test_writing_list_of_strings() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::list('list_of_strings', ListElement::string())); @@ -77,7 +77,7 @@ public function test_writing_list_of_strings() : void $inputData = \array_merge(...\array_map(static function (int $i) use ($faker) : array { return [ [ - 'list_of_strings' => \array_map(static fn ($i) => $faker->text(10), \range(1, \Flow\ETL\UniqueFactory::int(2, 10))), + 'list_of_strings' => \array_map(static fn ($i) => $faker->text(10), \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10))), ], ]; }, \range(1, 100))); @@ -92,7 +92,7 @@ public function test_writing_list_of_strings() : void public function test_writing_list_of_structures() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with( @@ -111,7 +111,7 @@ public function test_writing_list_of_structures() : void 'list_of_structs' => \array_map(static fn ($i) => [ 'id' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'name' => $faker->text(10), - ], \range(1, \Flow\ETL\UniqueFactory::int(2, 10))), + ], \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10))), ], ]; }, \range(1, 10))); @@ -126,7 +126,7 @@ public function test_writing_list_of_structures() : void public function test_writing_list_with_nullable_elements() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::list('list_of_ints', ListElement::int32())); @@ -136,7 +136,7 @@ public function test_writing_list_with_nullable_elements() : void return [ [ 'list_of_ints' => $i % 2 === 0 - ? \array_map(static fn ($a) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), \range(1, \Flow\ETL\UniqueFactory::int(2, 10))) + ? \array_map(static fn ($a) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10))) : null, ], ]; @@ -152,7 +152,7 @@ public function test_writing_list_with_nullable_elements() : void public function test_writing_list_with_nullable_list_values() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::list('list_of_ints', ListElement::int32())); @@ -162,7 +162,7 @@ public function test_writing_list_with_nullable_list_values() : void return [ [ 'list_of_ints' => $i % 2 === 0 - ? \array_map(static fn ($a) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), \range(1, \Flow\ETL\UniqueFactory::int(2, 2))) + ? \array_map(static fn ($a) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 2))) : [null, null], ], ]; @@ -178,7 +178,7 @@ public function test_writing_list_with_nullable_list_values() : void public function test_writing_nullable_list_of_ints() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::list('list_of_ints', ListElement::int32())); @@ -188,7 +188,7 @@ public function test_writing_nullable_list_of_ints() : void return [ [ 'list_of_ints' => $i % 2 === 0 - ? \array_map(static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), \range(1, \Flow\ETL\UniqueFactory::int(2, 10))) + ? \array_map(static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10))) : null, ], ]; @@ -204,7 +204,7 @@ public function test_writing_nullable_list_of_ints() : void public function test_writing_nullable_list_of_structures() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with( @@ -227,7 +227,7 @@ public function test_writing_nullable_list_of_structures() : void ? \array_map(static fn ($i) => [ 'id' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'name' => $faker->text(10), - ], \range(1, \Flow\ETL\UniqueFactory::int(2, 10))) + ], \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10))) : null, ], ]; @@ -243,7 +243,7 @@ public function test_writing_nullable_list_of_structures() : void public function test_writing_nullable_lists_of_ints() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::list('list_of_ints', ListElement::int32())); diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/MapsWritingTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/MapsWritingTest.php index aa208ba0b..70182b1c0 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/MapsWritingTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/MapsWritingTest.php @@ -21,7 +21,7 @@ protected function setUp() : void public function test_writing_empty_map_of_int_int() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::map('map_int_int', MapKey::int32(), MapValue::int32())); @@ -44,7 +44,7 @@ public function test_writing_empty_map_of_int_int() : void public function test_writing_map_of_int_int() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::map('map_int_int', MapKey::int32(), MapValue::int32())); @@ -56,7 +56,7 @@ public function test_writing_map_of_int_int() : void 'map_int_int' => \array_merge( ...\array_map( static fn ($i) => [$i => $faker->numberBetween(0, Consts::PHP_INT32_MAX)], - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ) ), ], @@ -73,7 +73,7 @@ public function test_writing_map_of_int_int() : void public function test_writing_map_of_int_int_with_all_maps_null() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::map('map_int_int', MapKey::int32(), MapValue::int32())); @@ -96,7 +96,7 @@ public function test_writing_map_of_int_int_with_all_maps_null() : void public function test_writing_map_of_int_string() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::map('map_int_string', MapKey::int32(), MapValue::string())); @@ -108,7 +108,7 @@ public function test_writing_map_of_int_string() : void 'map_int_string' => \array_merge( ...\array_map( static fn ($i) => [$i => $faker->text(10)], - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ) ), ], @@ -125,7 +125,7 @@ public function test_writing_map_of_int_string() : void public function test_writing_nullable_map_of_int_int() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::map('map_int_int', MapKey::int32(), MapValue::int32())); @@ -138,7 +138,7 @@ public function test_writing_nullable_map_of_int_int() : void ? \array_merge( ...\array_map( static fn ($i) => [$i => $faker->numberBetween(0, Consts::PHP_INT32_MAX)], - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ) ) : null, diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/PaginationTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/PaginationTest.php index 0faead760..da69dcbaa 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/PaginationTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/PaginationTest.php @@ -125,12 +125,12 @@ private function generateDataset(string $path) : void 'created_at' => new \DateTimeImmutable('2024-01-01 + ' . $i . ' days'), 'list_of_int' => \array_map( static fn (int $i) => $i, - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ), 'map_of_int_string' => \array_merge( ...\array_map( static fn (int $i) => [$i => 'value-' . $i], - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ) ), 'struct' => [ @@ -140,12 +140,12 @@ private function generateDataset(string $path) : void 'created_at' => new \DateTimeImmutable('2024-01-01 + ' . $i . ' days'), 'list_of_int' => \array_map( static fn (int $i) => $i, - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ), 'map_of_int_string' => \array_merge( ...\array_map( static fn (int $i) => [$i => 'value-' . $i], - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ) ), ], diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/SimpleTypesWritingTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/SimpleTypesWritingTest.php index 063bc3633..27efa5813 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/SimpleTypesWritingTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/SimpleTypesWritingTest.php @@ -21,7 +21,7 @@ protected function setUp() : void public function test_writing_bool_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::boolean('boolean')); @@ -47,7 +47,7 @@ public function test_writing_bool_column() : void public function test_writing_bool_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::boolean('boolean')); @@ -55,7 +55,7 @@ public function test_writing_bool_nullable_column() : void $inputData = \array_merge(...\array_map(static function (int $i) : array { return [ [ - 'boolean' => $i % 2 == 0 ? (bool) \Flow\ETL\UniqueFactory::int(0, 1) : null, + 'boolean' => $i % 2 == 0 ? (bool) \Flow\ETL\NativePHPRandomValueGenerator::int(0, 1) : null, ], ]; }, \range(1, 100))); @@ -73,7 +73,7 @@ public function test_writing_bool_nullable_column() : void public function test_writing_date_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::date('date')); @@ -101,7 +101,7 @@ public function test_writing_date_column() : void public function test_writing_date_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::date('date')); @@ -129,7 +129,7 @@ public function test_writing_date_nullable_column() : void public function test_writing_decimal_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::decimal('decimal')); @@ -157,7 +157,7 @@ public function test_writing_decimal_column() : void public function test_writing_decimal_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::decimal('decimal')); @@ -185,7 +185,7 @@ public function test_writing_decimal_nullable_column() : void public function test_writing_double_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::double('double')); @@ -213,7 +213,7 @@ public function test_writing_double_column() : void public function test_writing_double_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::double('double')); @@ -241,7 +241,7 @@ public function test_writing_double_nullable_column() : void public function test_writing_enum_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::enum('enum')); @@ -251,7 +251,7 @@ public function test_writing_enum_column() : void $inputData = \array_merge(...\array_map(static function (int $i) use ($enum) : array { return [ [ - 'enum' => $enum[\Flow\ETL\UniqueFactory::int(0, 3)], + 'enum' => $enum[\Flow\ETL\NativePHPRandomValueGenerator::int(0, 3)], ], ]; }, \range(1, 100))); @@ -269,7 +269,7 @@ public function test_writing_enum_column() : void public function test_writing_float_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::float('float')); @@ -295,7 +295,7 @@ public function test_writing_float_column() : void public function test_writing_float_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::float('float')); @@ -321,7 +321,7 @@ public function test_writing_float_nullable_column() : void public function test_writing_int32_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::int32('int32')); @@ -349,7 +349,7 @@ public function test_writing_int32_column() : void public function test_writing_int32_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::int32('int32')); @@ -377,7 +377,7 @@ public function test_writing_int32_nullable_column() : void public function test_writing_int64() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::int64('int64')); @@ -404,7 +404,7 @@ public function test_writing_int64() : void public function test_writing_int64_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::int64('int64')); @@ -431,7 +431,7 @@ public function test_writing_int64_nullable_column() : void public function test_writing_json_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::json('json')); @@ -458,7 +458,7 @@ public function test_writing_json_column() : void public function test_writing_json_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::json('json')); @@ -487,7 +487,7 @@ public function test_writing_json_nullable_column() : void public function test_writing_string_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::string('string')); @@ -514,7 +514,7 @@ public function test_writing_string_column() : void public function test_writing_string_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::string('string')); @@ -541,7 +541,7 @@ public function test_writing_string_nullable_column() : void public function test_writing_time_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::time('time')); @@ -566,7 +566,7 @@ public function test_writing_time_column() : void public function test_writing_time_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::time('time')); @@ -591,7 +591,7 @@ public function test_writing_time_nullable_column() : void public function test_writing_timestamp_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::dateTime('dateTime')); @@ -618,7 +618,7 @@ public function test_writing_timestamp_column() : void public function test_writing_timestamp_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::dateTime('dateTime')); @@ -645,7 +645,7 @@ public function test_writing_timestamp_nullable_column() : void public function test_writing_uuid_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::uuid('uuid')); @@ -672,7 +672,7 @@ public function test_writing_uuid_column() : void public function test_writing_uuid_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::uuid('uuid')); diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/StructsWritingTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/StructsWritingTest.php index e59e9007a..ef7390118 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/StructsWritingTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/StructsWritingTest.php @@ -21,7 +21,7 @@ protected function setUp() : void public function test_writing_flat_nullable_structure() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::struct('struct', [ @@ -45,11 +45,11 @@ public function test_writing_flat_nullable_structure() : void 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ), ] : null, @@ -67,7 +67,7 @@ public function test_writing_flat_nullable_structure() : void public function test_writing_flat_structure() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::struct('struct', [ @@ -90,11 +90,11 @@ public function test_writing_flat_structure() : void 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ), ], ], @@ -111,7 +111,7 @@ public function test_writing_flat_structure() : void public function test_writing_flat_structure_with_nullable_elements() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::struct('struct', [ @@ -135,13 +135,13 @@ public function test_writing_flat_structure_with_nullable_elements() : void 'list_of_int' => $i % 2 === 0 ? \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ) : null, 'list_of_string' => $i % 2 === 0 ? \array_map( static fn ($i) => $faker->text(10), - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ) : null, ], diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/WriterTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/WriterTest.php index 0d130dc46..4d83f0085 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/WriterTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/WriterTest.php @@ -36,7 +36,7 @@ public function test_created_by_metadata() : void { $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $schema = $this->createSchema(); $writer->open($path, $schema); @@ -51,7 +51,7 @@ public function test_opening_already_open_writer() : void { $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $schema = $this->createSchema(); @@ -80,7 +80,7 @@ public function test_writing_column_statistics() : void ->set(Option::WRITER_VERSION, 1) ); - $path = __DIR__ . '/var/test-writer-parquet-test-v2-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-v2-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $schema = Schema::with($column = FlatColumn::int32('int32')); @@ -109,7 +109,7 @@ public function test_writing_data_page_v2_statistics() : void ->set(Option::WRITER_VERSION, 2) ); - $path = __DIR__ . '/var/test-writer-parquet-test-v2-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-v2-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $schema = Schema::with($column = FlatColumn::int32('int32')); @@ -136,7 +136,7 @@ public function test_writing_in_batches_to_file() : void { $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $schema = $this->createSchema(); @@ -163,7 +163,7 @@ public function test_writing_in_batches_to_file_without_explicit_close() : void { $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $schema = $this->createSchema(); @@ -189,7 +189,7 @@ public function test_writing_in_batches_to_stream() : void { $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $schema = $this->createSchema(); @@ -227,7 +227,7 @@ public function test_writing_to_file() : void { $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $schema = $this->createSchema(); $row = $this->createRow(); @@ -249,7 +249,7 @@ public function test_writing_to_file_v2() : void ->set(Option::WRITER_VERSION, 2) ); - $path = __DIR__ . '/var/test-writer-parquet-test-v2-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-v2-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $schema = $this->createSchema(); $row = $this->createRow(); @@ -269,7 +269,7 @@ public function test_writing_to_stream() : void { $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $schema = $this->createSchema(); $row = $this->createRow(); @@ -298,11 +298,11 @@ private function createRow() : array 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \Flow\ETL\UniqueFactory::int(2, 10)) + \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) ), ], ]; diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/WriterValidatorTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/WriterValidatorTest.php index f0d32c9aa..0ac701b1d 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/WriterValidatorTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/WriterValidatorTest.php @@ -22,7 +22,7 @@ public function test_skipping_required_row() : void $this->expectExceptionMessage('Column "string" is required'); $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $schema = Schema::with( Schema\FlatColumn::int32('id'), @@ -37,7 +37,7 @@ public function test_writing_int_value_to_string_column() : void $this->expectExceptionMessage('Column "string" is not string, got "integer" instead'); $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $schema = Schema::with(Schema\FlatColumn::string('string')); @@ -49,7 +49,7 @@ public function test_writing_null_to_list_that_is_required() : void $this->expectExceptionMessage('Column "list" is required'); $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $schema = Schema::with(Schema\NestedColumn::list('list', Schema\ListElement::string())->makeRequired()); @@ -61,7 +61,7 @@ public function test_writing_null_to_list_with_element_is_required() : void $this->expectExceptionMessage('Column "list.list.element" is not string, got "NULL" instead'); $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $schema = Schema::with(Schema\NestedColumn::list('list', Schema\ListElement::string(required: true))); @@ -73,7 +73,7 @@ public function test_writing_null_to_map_with_value_required() : void $this->expectExceptionMessage('Column "map.key_value.value" is not string, got "NULL" instead'); $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $schema = Schema::with(Schema\NestedColumn::map('map', Schema\MapKey::string(), Schema\MapValue::string(required: true))); @@ -85,7 +85,7 @@ public function test_writing_null_to_required_map() : void $this->expectExceptionMessage('Column "map" is required'); $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $schema = Schema::with(Schema\NestedColumn::map('map', Schema\MapKey::string(), Schema\MapValue::string())->makeRequired()); @@ -97,7 +97,7 @@ public function test_writing_null_value_to_required_column() : void $this->expectExceptionMessage('Column "string" is required'); $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $schema = Schema::with(Schema\FlatColumn::string('string')->makeRequired()); @@ -107,7 +107,7 @@ public function test_writing_null_value_to_required_column() : void public function test_writing_row_with_missing_optional_columns() : void { $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $schema = Schema::with( Schema\FlatColumn::int32('id'), @@ -141,7 +141,7 @@ public function test_writing_row_with_missing_optional_columns() : void public function test_writing_row_with_missing_optional_columns_in_different_columns() : void { $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\UniqueFactory::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; $schema = Schema::with( Schema\FlatColumn::int32('id'), diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/ParquetFile/Data/RLEBitPackedHybridTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/ParquetFile/Data/RLEBitPackedHybridTest.php index f4b73b2fd..63b631db1 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/ParquetFile/Data/RLEBitPackedHybridTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/ParquetFile/Data/RLEBitPackedHybridTest.php @@ -230,10 +230,10 @@ public function test_with_dynamically_generated_values() : void { for ($iteration = 0; $iteration < 100; $iteration++) { $values = []; - $maxValues = \Flow\ETL\UniqueFactory::int(10, 1000); + $maxValues = \Flow\ETL\NativePHPRandomValueGenerator::int(10, 1000); for ($i = 0; $i < $maxValues; $i++) { - $values[] = \Flow\ETL\UniqueFactory::int(0, 1000); + $values[] = \Flow\ETL\NativePHPRandomValueGenerator::int(0, 1000); } $buffer = ''; diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/ParquetFile/RowGroupBuilder/PagesBuilderTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/ParquetFile/RowGroupBuilder/PagesBuilderTest.php index 714676bb4..2cf3fb2d6 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/ParquetFile/RowGroupBuilder/PagesBuilderTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/ParquetFile/RowGroupBuilder/PagesBuilderTest.php @@ -58,7 +58,7 @@ public function test_building_pages_for_enum_columns() : void 1 => 'GREEN', 2 => 'BLUE', ]; - $values = \array_map(static fn ($i) => $enum[\Flow\ETL\UniqueFactory::int(0, 2)], \range(0, 99)); + $values = \array_map(static fn ($i) => $enum[\Flow\ETL\NativePHPRandomValueGenerator::int(0, 2)], \range(0, 99)); $statistics = new ColumnChunkStatistics($column); foreach ($values as $value) { diff --git a/src/lib/snappy/tests/Flow/Snappy/Tests/Integration/SnappyTest.php b/src/lib/snappy/tests/Flow/Snappy/Tests/Integration/SnappyTest.php index 2273ade6a..1d4abf2bb 100644 --- a/src/lib/snappy/tests/Flow/Snappy/Tests/Integration/SnappyTest.php +++ b/src/lib/snappy/tests/Flow/Snappy/Tests/Integration/SnappyTest.php @@ -71,7 +71,7 @@ public function test_snappy_compression_with_dynamically_generated_texts() : voi $snappy = new Snappy(); for ($iteration = 0; $iteration < 100; $iteration++) { - $string = Factory::create()->text(\Flow\ETL\UniqueFactory::int(10, 1000)); + $string = Factory::create()->text(\Flow\ETL\NativePHPRandomValueGenerator::int(10, 1000)); self::assertSame( $string, From 510021351cb7ff064de3f24347e6da1cf9859a1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Mleczko?= Date: Wed, 31 Jul 2024 01:12:53 +0200 Subject: [PATCH 4/8] Fix missing import after move --- src/core/etl/src/Flow/ETL/Config/ConfigBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/etl/src/Flow/ETL/Config/ConfigBuilder.php b/src/core/etl/src/Flow/ETL/Config/ConfigBuilder.php index 34b3ae999..2192ad50f 100644 --- a/src/core/etl/src/Flow/ETL/Config/ConfigBuilder.php +++ b/src/core/etl/src/Flow/ETL/Config/ConfigBuilder.php @@ -13,7 +13,7 @@ use Flow\ETL\PHP\Type\Caster; use Flow\ETL\Pipeline\Optimizer; use Flow\ETL\Row\Factory\NativeEntryFactory; -use Flow\ETL\{Cache, Config}; +use Flow\ETL\{Cache, Config, NativePHPRandomValueGenerator}; use Flow\Filesystem\{Filesystem, FilesystemTable}; use Flow\Serializer\{Base64Serializer, NativePHPSerializer, Serializer}; From a29c36702daa74b6943aa5f77b8d8024bc07e2dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Mleczko?= Date: Wed, 31 Jul 2024 01:33:49 +0200 Subject: [PATCH 5/8] Use functions instead of static calls for tests requiring randomness --- .../ElasticsearchExtractorTest.php | 12 ++-- .../ElasticsearchLoaderTest.php | 9 +-- .../MeilisearchExtractorTest.php | 6 +- .../MeilisearchPHP/MeilisearchLoaderTest.php | 8 +-- .../Text/Tests/Integration/TextTest.php | 2 +- .../Unit/AzureBlobDestinationStreamTest.php | 4 +- .../etl/src/Flow/ETL/Config/ConfigBuilder.php | 7 ++- src/core/etl/src/Flow/ETL/DSL/functions.php | 11 ++++ .../ETL/NativePHPRandomValueGenerator.php | 9 +-- .../etl/src/Flow/ETL/RandomValueGenerator.php | 5 +- .../Flow/ETL/Tests/Double/FakeExtractor.php | 3 +- .../DataFrame/PartitioningTest.php | 9 +-- .../NativePHPRandomValueGeneratorTest.php | 14 ++--- .../etl/tests/Flow/ETL/Tests/Unit/RowTest.php | 24 +++++++- .../OrderEntriesTransformerTest.php | 7 ++- .../Tests/Unit/Base64SerializerTest.php | 2 +- .../Tests/Unit/CompressingSerializerTest.php | 2 +- .../Tests/Unit/NativePHPSerializerTest.php | 2 +- .../Tests/Integration/MySqlBulkInsertTest.php | 6 +- .../Integration/PostgreSqlBulkInsertTest.php | 6 +- .../Integration/SqliteBulkInsertTest.php | 6 +- .../filesystem/src/Flow/Filesystem/Path.php | 2 +- .../Block/NativeLocalFileBlocksFactory.php | 2 +- .../Tests/Integration/IO/CompressionTest.php | 49 +++++++++-------- .../Tests/Integration/IO/ListsWritingTest.php | 33 +++++------ .../Tests/Integration/IO/MapsWritingTest.php | 17 +++--- .../Tests/Integration/IO/PaginationTest.php | 9 +-- .../Integration/IO/SimpleTypesWritingTest.php | 55 ++++++++++--------- .../Integration/IO/StructsWritingTest.php | 19 ++++--- .../Tests/Integration/IO/WriterTest.php | 25 +++++---- .../Integration/IO/WriterValidatorTest.php | 18 +++--- .../Data/RLEBitPackedHybridTest.php | 5 +- .../RowGroupBuilder/PagesBuilderTest.php | 2 +- .../Snappy/Tests/Integration/SnappyTest.php | 3 +- 34 files changed, 216 insertions(+), 177 deletions(-) diff --git a/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchExtractorTest.php b/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchExtractorTest.php index badfd8892..358846776 100644 --- a/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchExtractorTest.php +++ b/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchExtractorTest.php @@ -5,7 +5,7 @@ namespace Flow\ETL\Adapter\Elasticsearch\Tests\Integration\ElasticsearchPHP; use function Flow\ETL\Adapter\Elasticsearch\{es_hits_to_rows, from_es, to_es_bulk_index}; -use function Flow\ETL\DSL\df; +use function Flow\ETL\DSL\{df, generate_random_int}; use Flow\ETL\Adapter\Elasticsearch\ElasticsearchPHP\DocumentDataSource; use Flow\ETL\Adapter\Elasticsearch\EntryIdFactory\EntryIdFactory; use Flow\ETL\Adapter\Elasticsearch\Tests\Integration\TestCase; @@ -40,7 +40,7 @@ public function test_empty_extraction() : void new Row\Entry\StringEntry('id', \sha1((string) $i)), new Row\Entry\IntegerEntry('position', $i), new Row\Entry\StringEntry('name', 'id_' . $i), - new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\NativePHPRandomValueGenerator::int(0, 1)) + new Row\Entry\BooleanEntry('active', (bool) generate_random_int(0, 1)) ), \range(1, 100) ), @@ -80,7 +80,7 @@ public function test_extraction_index_with_from_and_size() : void new Row\Entry\StringEntry('id', \sha1((string) $i)), new Row\Entry\IntegerEntry('position', $i), new Row\Entry\StringEntry('name', 'id_' . $i), - new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\NativePHPRandomValueGenerator::int(0, 1)) + new Row\Entry\BooleanEntry('active', (bool) generate_random_int(0, 1)) ), \range(1, 2000) ), @@ -123,7 +123,7 @@ public function test_extraction_index_with_search_after() : void new Row\Entry\StringEntry('id', \sha1((string) $i)), new Row\Entry\IntegerEntry('position', $i), new Row\Entry\StringEntry('name', 'id_' . $i), - new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\NativePHPRandomValueGenerator::int(0, 1)) + new Row\Entry\BooleanEntry('active', (bool) generate_random_int(0, 1)) ), \range(1, 2005) ), @@ -159,7 +159,7 @@ public function test_extraction_index_with_search_after_with_point_in_time() : v new Row\Entry\StringEntry('id', \sha1((string) $i)), new Row\Entry\IntegerEntry('position', $i), new Row\Entry\StringEntry('name', 'id_' . $i), - new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\NativePHPRandomValueGenerator::int(0, 1)) + new Row\Entry\BooleanEntry('active', (bool) generate_random_int(0, 1)) ), \range(1, 2005) ), @@ -200,7 +200,7 @@ public function test_extraction_whole_index_with_point_in_time() : void new Row\Entry\StringEntry('id', \sha1((string) $i)), new Row\Entry\IntegerEntry('position', $i), new Row\Entry\StringEntry('name', 'id_' . $i), - new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\NativePHPRandomValueGenerator::int(0, 1)) + new Row\Entry\BooleanEntry('active', (bool) generate_random_int(0, 1)) ), \range(1, 2005) ), diff --git a/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchLoaderTest.php b/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchLoaderTest.php index 922c6bdd7..f040c083d 100644 --- a/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchLoaderTest.php +++ b/src/adapter/etl-adapter-elasticsearch/tests/Flow/ETL/Adapter/Elasticsearch/Tests/Integration/ElasticsearchPHP/ElasticsearchLoaderTest.php @@ -5,6 +5,7 @@ namespace Flow\ETL\Adapter\Elasticsearch\Tests\Integration\ElasticsearchPHP; use function Flow\ETL\Adapter\Elasticsearch\{to_es_bulk_index, to_es_bulk_update}; +use function Flow\ETL\DSL\generate_random_string; use Flow\ETL\Adapter\Elasticsearch\EntryIdFactory\{EntryIdFactory, HashIdFactory}; use Flow\ETL\Adapter\Elasticsearch\Tests\Integration\TestCase; use Flow\ETL\{Config, FlowContext, Row, Rows}; @@ -53,19 +54,19 @@ public function test_integration_with_entry_factory() : void $loader->load(new Rows( Row::create( - new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\NativePHPRandomValueGenerator::string(32))), + new Row\Entry\StringEntry('id', \sha1('id' . generate_random_string())), new Row\Entry\StringEntry('name', 'Łukasz') ), Row::create( - new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\NativePHPRandomValueGenerator::string(32))), + new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\DSL\generate_random_string())), new Row\Entry\StringEntry('name', 'Norbert') ), Row::create( - new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\NativePHPRandomValueGenerator::string(32))), + new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\DSL\generate_random_string())), new Row\Entry\StringEntry('name', 'Dawid') ), Row::create( - new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\NativePHPRandomValueGenerator::string(32))), + new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\DSL\generate_random_string())), new Row\Entry\StringEntry('name', 'Tomek') ), ), new FlowContext(Config::default())); diff --git a/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchExtractorTest.php b/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchExtractorTest.php index 2c9d71be0..ce4987c83 100644 --- a/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchExtractorTest.php +++ b/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchExtractorTest.php @@ -37,7 +37,7 @@ public function test_empty_extraction() : void new Row\Entry\StringEntry('id', \sha1((string) $i)), new Row\Entry\IntegerEntry('position', $i), new Row\Entry\StringEntry('name', 'id_' . $i), - new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\NativePHPRandomValueGenerator::int(0, 1)) + new Row\Entry\BooleanEntry('active', (bool) generate_random_int(0, 1)) ), \range(1, 100) ), @@ -63,7 +63,7 @@ public function test_extraction_index_with_from_and_size() : void new Row\Entry\StringEntry('id', \sha1((string) $i)), new Row\Entry\IntegerEntry('position', $i), new Row\Entry\StringEntry('name', 'id_' . $i), - new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\NativePHPRandomValueGenerator::int(0, 1)) + new Row\Entry\BooleanEntry('active', (bool) generate_random_int(0, 1)) ), // Default limit for Meilisearch is 1000 documents: https://www.meilisearch.com/docs/reference/api/settings#pagination \range(1, 999) @@ -102,7 +102,7 @@ public function test_extraction_index_with_sort() : void new Row\Entry\StringEntry('id', \sha1((string) $i)), new Row\Entry\IntegerEntry('position', $i), new Row\Entry\StringEntry('name', 'id_' . $i), - new Row\Entry\BooleanEntry('active', (bool) \Flow\ETL\NativePHPRandomValueGenerator::int(0, 1)) + new Row\Entry\BooleanEntry('active', (bool) generate_random_int(0, 1)) ), // Default limit for Meilisearch is 1000 documents: https://www.meilisearch.com/docs/reference/api/settings#pagination \range(1, 999) diff --git a/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchLoaderTest.php b/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchLoaderTest.php index 62b648fe1..fbb5c78e9 100644 --- a/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchLoaderTest.php +++ b/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchLoaderTest.php @@ -43,19 +43,19 @@ public function test_integration_with_entry_factory() : void $loader = to_meilisearch_bulk_index($this->meilisearchContext->clientConfig(), self::INDEX_NAME); $loader->load(new Rows( Row::create( - new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\NativePHPRandomValueGenerator::string(32))), + new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\DSL\generate_random_string())), new Row\Entry\StringEntry('name', 'Łukasz') ), Row::create( - new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\NativePHPRandomValueGenerator::string(32))), + new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\DSL\generate_random_string())), new Row\Entry\StringEntry('name', 'Norbert') ), Row::create( - new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\NativePHPRandomValueGenerator::string(32))), + new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\DSL\generate_random_string())), new Row\Entry\StringEntry('name', 'Dawid') ), Row::create( - new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\NativePHPRandomValueGenerator::string(32))), + new Row\Entry\StringEntry('id', \sha1('id' . \Flow\ETL\DSL\generate_random_string())), new Row\Entry\StringEntry('name', 'Tomek') ), ), new FlowContext(Config::default())); diff --git a/src/adapter/etl-adapter-text/tests/Flow/ETL/Adapter/Text/Tests/Integration/TextTest.php b/src/adapter/etl-adapter-text/tests/Flow/ETL/Adapter/Text/Tests/Integration/TextTest.php index fbc2fc30d..7d473c428 100644 --- a/src/adapter/etl-adapter-text/tests/Flow/ETL/Adapter/Text/Tests/Integration/TextTest.php +++ b/src/adapter/etl-adapter-text/tests/Flow/ETL/Adapter/Text/Tests/Integration/TextTest.php @@ -13,7 +13,7 @@ final class TextTest extends TestCase { public function test_loading_text_files() : void { - $path = __DIR__ . '/var/flow_php_etl_csv_loader' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.csv'; + $path = __DIR__ . '/var/flow_php_etl_csv_loader' . \Flow\ETL\DSL\generate_random_string() . '.csv'; (new Flow()) ->process( diff --git a/src/bridge/filesystem/azure/tests/Flow/Filesystem/Bridge/Azure/Tests/Unit/AzureBlobDestinationStreamTest.php b/src/bridge/filesystem/azure/tests/Flow/Filesystem/Bridge/Azure/Tests/Unit/AzureBlobDestinationStreamTest.php index 7bd9c80a7..9953ade00 100644 --- a/src/bridge/filesystem/azure/tests/Flow/Filesystem/Bridge/Azure/Tests/Unit/AzureBlobDestinationStreamTest.php +++ b/src/bridge/filesystem/azure/tests/Flow/Filesystem/Bridge/Azure/Tests/Unit/AzureBlobDestinationStreamTest.php @@ -24,7 +24,7 @@ public function test_using_put_blob_with_content_when_data_is_larger_than_block_ $blockFactory->method('create') ->willReturnCallback( function () use ($blockSize) { - return new Block($id = \Flow\ETL\NativePHPRandomValueGenerator::string(32), $blockSize, new Path(sys_get_temp_dir() . '/' . $id . '_block_01.txt')); + return new Block($id = \Flow\ETL\DSL\generate_random_string(), $blockSize, new Path(sys_get_temp_dir() . '/' . $id . '_block_01.txt')); } ); @@ -74,7 +74,7 @@ public function test_using_put_blob_with_content_when_data_is_smaller_than_block $blockFactory->method('create') ->willReturnCallback( function () use ($blockSize) { - return new Block($id = \Flow\ETL\NativePHPRandomValueGenerator::string(32), $blockSize, new Path(sys_get_temp_dir() . '/' . $id . '_block_01.txt')); + return new Block($id = \Flow\ETL\DSL\generate_random_string(), $blockSize, new Path(sys_get_temp_dir() . '/' . $id . '_block_01.txt')); } ); $stream = AzureBlobDestinationStream::openBlank( diff --git a/src/core/etl/src/Flow/ETL/Config/ConfigBuilder.php b/src/core/etl/src/Flow/ETL/Config/ConfigBuilder.php index 2192ad50f..b9a5385d6 100644 --- a/src/core/etl/src/Flow/ETL/Config/ConfigBuilder.php +++ b/src/core/etl/src/Flow/ETL/Config/ConfigBuilder.php @@ -13,7 +13,7 @@ use Flow\ETL\PHP\Type\Caster; use Flow\ETL\Pipeline\Optimizer; use Flow\ETL\Row\Factory\NativeEntryFactory; -use Flow\ETL\{Cache, Config, NativePHPRandomValueGenerator}; +use Flow\ETL\{Cache, Config, NativePHPRandomValueGenerator, RandomValueGenerator}; use Flow\Filesystem\{Filesystem, FilesystemTable}; use Flow\Serializer\{Base64Serializer, NativePHPSerializer, Serializer}; @@ -33,6 +33,8 @@ final class ConfigBuilder private bool $putInputIntoRows; + private RandomValueGenerator $randomValueGenerator; + private ?Serializer $serializer; public function __construct() @@ -45,11 +47,12 @@ public function __construct() $this->caster = null; $this->cache = new CacheConfigBuilder(); $this->sort = new SortConfigBuilder(); + $this->randomValueGenerator = new NativePHPRandomValueGenerator(); } public function build() : Config { - $this->id ??= 'flow_php' . NativePHPRandomValueGenerator::string(32); + $this->id ??= 'flow_php' . $this->randomValueGenerator->string(32); $entryFactory = new NativeEntryFactory(); $this->serializer ??= new Base64Serializer(new NativePHPSerializer()); diff --git a/src/core/etl/src/Flow/ETL/DSL/functions.php b/src/core/etl/src/Flow/ETL/DSL/functions.php index 003aea8d5..42d49777d 100644 --- a/src/core/etl/src/Flow/ETL/DSL/functions.php +++ b/src/core/etl/src/Flow/ETL/DSL/functions.php @@ -50,6 +50,7 @@ Join\Comparison\Identical, Join\Expression, Loader, + NativePHPRandomValueGenerator, Pipeline, Row, Rows, @@ -1209,3 +1210,13 @@ function is_type(array $types, mixed $value) : bool return false; } + +function generate_random_string(int $length = 32, NativePHPRandomValueGenerator $generator = new NativePHPRandomValueGenerator()) : string +{ + return $generator->string($length); +} + +function generate_random_int(int $start = PHP_INT_MIN, int $end = PHP_INT_MAX, NativePHPRandomValueGenerator $generator = new NativePHPRandomValueGenerator()) : int +{ + return $generator->int($start, $end); +} diff --git a/src/core/etl/src/Flow/ETL/NativePHPRandomValueGenerator.php b/src/core/etl/src/Flow/ETL/NativePHPRandomValueGenerator.php index 0c1ca5b82..50f809331 100644 --- a/src/core/etl/src/Flow/ETL/NativePHPRandomValueGenerator.php +++ b/src/core/etl/src/Flow/ETL/NativePHPRandomValueGenerator.php @@ -6,17 +6,12 @@ final class NativePHPRandomValueGenerator implements RandomValueGenerator { - private function __construct() - { - } - - public static function int(int $min, int $max) : int + public function int(int $min, int $max) : int { return \random_int($min, $max); } - /** @param int<1, max> $int */ - public static function string(int $int) : string + public function string(int $int) : string { $bytes = (int) \ceil($int / 2); $bytes >= 1 ?: $bytes = 1; diff --git a/src/core/etl/src/Flow/ETL/RandomValueGenerator.php b/src/core/etl/src/Flow/ETL/RandomValueGenerator.php index e4f3eedf8..9769bfc4b 100644 --- a/src/core/etl/src/Flow/ETL/RandomValueGenerator.php +++ b/src/core/etl/src/Flow/ETL/RandomValueGenerator.php @@ -6,8 +6,7 @@ interface RandomValueGenerator { - public static function int(int $min, int $max) : int; + public function int(int $min, int $max) : int; - /** @param int<1, max> $int */ - public static function string(int $int) : string; + public function string(int $int) : string; } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Double/FakeExtractor.php b/src/core/etl/tests/Flow/ETL/Tests/Double/FakeExtractor.php index 195026be5..004390fab 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Double/FakeExtractor.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Double/FakeExtractor.php @@ -9,6 +9,7 @@ datetime_entry, enum_entry, float_entry, + generate_random_int, int_entry, json_entry, list_entry, @@ -50,7 +51,7 @@ public function extract(FlowContext $context) : \Generator yield rows( row( int_entry('int', $id), - float_entry('float', \Flow\ETL\NativePHPRandomValueGenerator::int(100, 100000) / 100), + float_entry('float', generate_random_int(100, 100000) / 100), bool_entry('bool', false), datetime_entry('datetime', new \DateTimeImmutable('now')), str_entry('null', null), diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/PartitioningTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/PartitioningTest.php index 06cfe8b71..edf166a27 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/PartitioningTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/DataFrame/PartitioningTest.php @@ -10,6 +10,7 @@ from_array, from_path_partitions, from_rows, + generate_random_int, int_entry, lit, overwrite, @@ -163,13 +164,13 @@ public function test_partition_by_partitions_order() : void function (int $i) : array { $data = []; - $maxItems = \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10); + $maxItems = generate_random_int(2, 10); for ($d = 0; $d < $maxItems; $d++) { $data[] = [ - 'id' => \Flow\ETL\NativePHPRandomValueGenerator::string(32), - 'created_at' => (new \DateTimeImmutable('2020-01-01'))->add(new \DateInterval('P' . $i . 'D'))->setTime(\Flow\ETL\NativePHPRandomValueGenerator::int(0, 23), \Flow\ETL\NativePHPRandomValueGenerator::int(0, 59), \Flow\ETL\NativePHPRandomValueGenerator::int(0, 59)), - 'value' => \Flow\ETL\NativePHPRandomValueGenerator::int(1, 1000), + 'id' => \Flow\ETL\DSL\generate_random_string(), + 'created_at' => (new \DateTimeImmutable('2020-01-01'))->add(new \DateInterval('P' . $i . 'D'))->setTime(generate_random_int(0, 23), generate_random_int(0, 59), generate_random_int(0, 59)), + 'value' => generate_random_int(1, 1000), ]; } diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/NativePHPRandomValueGeneratorTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/NativePHPRandomValueGeneratorTest.php index 99be62182..9b8276592 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/NativePHPRandomValueGeneratorTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/NativePHPRandomValueGeneratorTest.php @@ -35,9 +35,9 @@ public static function valid_range_provider() : array public function test_can_create_random_int_from_given_range() : void { - self::assertSame(1, (NativePHPRandomValueGenerator::int(1, 1))); + self::assertSame(1, ((new NativePHPRandomValueGenerator())->int(1, 1))); self::assertThat( - NativePHPRandomValueGenerator::int(1, 2), + (new NativePHPRandomValueGenerator())->int(1, 2), self::logicalOr( self::equalTo(1), self::equalTo(2) @@ -48,18 +48,18 @@ public function test_can_create_random_int_from_given_range() : void /** @dataProvider integers_provider */ public function test_can_create_random_string_with_given_length(int $expectedLength) : void { - self::assertSame($expectedLength, mb_strlen(NativePHPRandomValueGenerator::string($expectedLength))); + self::assertSame($expectedLength, mb_strlen((new NativePHPRandomValueGenerator())->string($expectedLength))); } public function test_empty_string_on_length_below_1() : void { self::assertSame( '', - NativePHPRandomValueGenerator::string(0) + (new NativePHPRandomValueGenerator())->string(0) ); self::assertSame( '', - NativePHPRandomValueGenerator::string(-1) + (new NativePHPRandomValueGenerator())->string(-1) ); } @@ -67,14 +67,14 @@ public function test_empty_string_on_length_below_1() : void public function test_fail_on_invalid_range(int $min, int $max) : void { self::expectException(\ValueError::class); - NativePHPRandomValueGenerator::int($min, $max); + (new NativePHPRandomValueGenerator())->int($min, $max); } /** @dataProvider valid_range_provider */ public function test_return_random_int_on_valid_range(int $min, int $max) : void { self::assertThat( - NativePHPRandomValueGenerator::int($min, $max), + (new NativePHPRandomValueGenerator())->int($min, $max), self::logicalOr( self::greaterThanOrEqual($min), self::lessThanOrEqual($max) diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/RowTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/RowTest.php index a416d609c..00288ac63 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/RowTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/RowTest.php @@ -4,7 +4,25 @@ namespace Flow\ETL\Tests\Unit; -use function Flow\ETL\DSL\{array_entry, bool_entry, datetime_entry, float_entry, int_entry, list_entry, map_entry, object_entry, row, str_entry, struct_element, struct_entry, struct_type, type_int, type_list, type_map, type_object, type_string}; +use function Flow\ETL\DSL\{array_entry, + bool_entry, + datetime_entry, + float_entry, + generate_random_int, + int_entry, + list_entry, + map_entry, + object_entry, + row, + str_entry, + struct_element, + struct_entry, + struct_type, + type_int, + type_list, + type_map, + type_object, + type_string}; use Flow\ETL\PHP\Type\Logical\List\ListElement; use Flow\ETL\PHP\Type\Logical\Map\{MapKey, MapValue}; use Flow\ETL\PHP\Type\Logical\Structure\StructureElement; @@ -78,8 +96,8 @@ public static function is_equal_data_provider() : \Generator public function test_getting_schema_from_row() : void { $row = row( - int_entry('id', \Flow\ETL\NativePHPRandomValueGenerator::int(100, 100000)), - float_entry('price', \Flow\ETL\NativePHPRandomValueGenerator::int(100, 100000) / 100), + int_entry('id', generate_random_int(100, 100000)), + float_entry('price', generate_random_int(100, 100000) / 100), bool_entry('deleted', false), datetime_entry('created-at', new \DateTimeImmutable('now')), str_entry('phase', null), diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/OrderEntriesTransformerTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/OrderEntriesTransformerTest.php index 2e1adcfe3..12f51c6c5 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/OrderEntriesTransformerTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Transformer/OrderEntriesTransformerTest.php @@ -16,6 +16,7 @@ enum_entry, float_entry, flow_context, + generate_random_int, int_entry, json_entry, list_entry, @@ -46,8 +47,8 @@ public function test_ordering_entries_by_name_and_type() : void row( int_entry('int_a', 1), int_entry('int_b', 1), - float_entry('float_a', \Flow\ETL\NativePHPRandomValueGenerator::int(100, 100000) / 100), - float_entry('float_b', \Flow\ETL\NativePHPRandomValueGenerator::int(100, 100000) / 100), + float_entry('float_a', generate_random_int(100, 100000) / 100), + float_entry('float_b', generate_random_int(100, 100000) / 100), bool_entry('bool', false), bool_entry('bool_a', false), bool_entry('bool_c', false), @@ -141,7 +142,7 @@ public function test_ordering_entries_by_type() : void $rows = rows( row( int_entry('int', 1), - float_entry('float', \Flow\ETL\NativePHPRandomValueGenerator::int(100, 100000) / 100), + float_entry('float', generate_random_int(100, 100000) / 100), bool_entry('bool', false), datetime_entry('datetime', new \DateTimeImmutable('now')), str_entry('null', null), diff --git a/src/core/etl/tests/Flow/Serializer/Tests/Unit/Base64SerializerTest.php b/src/core/etl/tests/Flow/Serializer/Tests/Unit/Base64SerializerTest.php index 14fd68aaf..13cf7ba8b 100644 --- a/src/core/etl/tests/Flow/Serializer/Tests/Unit/Base64SerializerTest.php +++ b/src/core/etl/tests/Flow/Serializer/Tests/Unit/Base64SerializerTest.php @@ -40,7 +40,7 @@ public function test_serializing_rows() : void $serialized = $serializer->serialize($rows); - $unserialized = $serializer->unserialize($serialized, Rows::class); + $unserialized = $serializer->unserialize($serialized, [Rows::class]); self::assertEquals( $rows, diff --git a/src/core/etl/tests/Flow/Serializer/Tests/Unit/CompressingSerializerTest.php b/src/core/etl/tests/Flow/Serializer/Tests/Unit/CompressingSerializerTest.php index c40ef90d5..2194def77 100644 --- a/src/core/etl/tests/Flow/Serializer/Tests/Unit/CompressingSerializerTest.php +++ b/src/core/etl/tests/Flow/Serializer/Tests/Unit/CompressingSerializerTest.php @@ -47,7 +47,7 @@ public function test_serializing_rows() : void $serialized = $serializer->serialize($rows); - $unserialized = $serializer->unserialize($serialized, Rows::class); + $unserialized = $serializer->unserialize($serialized, [Rows::class]); self::assertEquals( $rows, diff --git a/src/core/etl/tests/Flow/Serializer/Tests/Unit/NativePHPSerializerTest.php b/src/core/etl/tests/Flow/Serializer/Tests/Unit/NativePHPSerializerTest.php index 2f3c64632..d3a49900a 100644 --- a/src/core/etl/tests/Flow/Serializer/Tests/Unit/NativePHPSerializerTest.php +++ b/src/core/etl/tests/Flow/Serializer/Tests/Unit/NativePHPSerializerTest.php @@ -42,7 +42,7 @@ public function test_serializing_rows() : void self::assertEquals( $rows, - $serializer->unserialize($serialized, Rows::class) + $serializer->unserialize($serialized, [Rows::class]) ); } } diff --git a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/MySqlBulkInsertTest.php b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/MySqlBulkInsertTest.php index 88780d4fd..3160a0f64 100644 --- a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/MySqlBulkInsertTest.php +++ b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/MySqlBulkInsertTest.php @@ -33,9 +33,9 @@ public function test_inserts_multiple_rows_at_once() : void $this->databaseContext->connection(), $table, new BulkData([ - ['id' => $id1 = \Flow\ETL\NativePHPRandomValueGenerator::string(10), 'age' => 20, 'name' => 'Name One', 'description' => 'Description One', 'active' => false, 'updated_at' => $date1 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], - ['id' => $id2 = \Flow\ETL\NativePHPRandomValueGenerator::string(10), 'age' => 30, 'name' => 'Name Two', 'description' => null, 'active' => true, 'updated_at' => $date2 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], - ['id' => $id3 = \Flow\ETL\NativePHPRandomValueGenerator::string(10), 'age' => 40, 'name' => 'Name Three', 'description' => 'Description Three', 'active' => false, 'updated_at' => $date3 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id1 = \Flow\ETL\DSL\generate_random_string(10), 'age' => 20, 'name' => 'Name One', 'description' => 'Description One', 'active' => false, 'updated_at' => $date1 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id2 = \Flow\ETL\DSL\generate_random_string(10), 'age' => 30, 'name' => 'Name Two', 'description' => null, 'active' => true, 'updated_at' => $date2 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id3 = \Flow\ETL\DSL\generate_random_string(10), 'age' => 40, 'name' => 'Name Three', 'description' => 'Description Three', 'active' => false, 'updated_at' => $date3 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], ]) ); diff --git a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/PostgreSqlBulkInsertTest.php b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/PostgreSqlBulkInsertTest.php index ea6645dde..79faac34a 100644 --- a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/PostgreSqlBulkInsertTest.php +++ b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/PostgreSqlBulkInsertTest.php @@ -35,9 +35,9 @@ public function test_inserts_multiple_rows_at_once() : void $this->databaseContext->connection(), $table, new BulkData([ - ['id' => $id1 = \Flow\ETL\NativePHPRandomValueGenerator::string(10), 'age' => 20, 'name' => 'Name One', 'description' => 'Description One', 'active' => false, 'updated_at' => $date1->format(\DateTimeInterface::ATOM), 'tags' => \json_encode(['a', 'b', 'c'])], - ['id' => $id2 = \Flow\ETL\NativePHPRandomValueGenerator::string(10), 'age' => 30, 'name' => 'Name Two', 'description' => null, 'active' => true, 'updated_at' => $date2 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], - ['id' => $id3 = \Flow\ETL\NativePHPRandomValueGenerator::string(10), 'age' => 40, 'name' => 'Name Three', 'description' => 'Description Three', 'active' => false, 'updated_at' => $date3 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id1 = \Flow\ETL\DSL\generate_random_string(10), 'age' => 20, 'name' => 'Name One', 'description' => 'Description One', 'active' => false, 'updated_at' => $date1->format(\DateTimeInterface::ATOM), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id2 = \Flow\ETL\DSL\generate_random_string(10), 'age' => 30, 'name' => 'Name Two', 'description' => null, 'active' => true, 'updated_at' => $date2 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id3 = \Flow\ETL\DSL\generate_random_string(10), 'age' => 40, 'name' => 'Name Three', 'description' => 'Description Three', 'active' => false, 'updated_at' => $date3 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], ]) ); diff --git a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/SqliteBulkInsertTest.php b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/SqliteBulkInsertTest.php index 7404efc2c..6428e95e5 100644 --- a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/SqliteBulkInsertTest.php +++ b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/SqliteBulkInsertTest.php @@ -33,9 +33,9 @@ public function test_inserts_multiple_rows_at_once() : void $this->databaseContext->connection(), $table, new BulkData([ - ['id' => $id1 = \Flow\ETL\NativePHPRandomValueGenerator::string(10), 'age' => 20, 'name' => 'Name One', 'description' => 'Description One', 'active' => false, 'updated_at' => $date1 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], - ['id' => $id2 = \Flow\ETL\NativePHPRandomValueGenerator::string(10), 'age' => 30, 'name' => 'Name Two', 'description' => null, 'active' => true, 'updated_at' => $date2 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], - ['id' => $id3 = \Flow\ETL\NativePHPRandomValueGenerator::string(10), 'age' => 40, 'name' => 'Name Three', 'description' => 'Description Three', 'active' => false, 'updated_at' => $date3 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id1 = \Flow\ETL\DSL\generate_random_string(10), 'age' => 20, 'name' => 'Name One', 'description' => 'Description One', 'active' => false, 'updated_at' => $date1 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id2 = \Flow\ETL\DSL\generate_random_string(10), 'age' => 30, 'name' => 'Name Two', 'description' => null, 'active' => true, 'updated_at' => $date2 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id3 = \Flow\ETL\DSL\generate_random_string(10), 'age' => 40, 'name' => 'Name Three', 'description' => 'Description Three', 'active' => false, 'updated_at' => $date3 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], ]) ); diff --git a/src/lib/filesystem/src/Flow/Filesystem/Path.php b/src/lib/filesystem/src/Flow/Filesystem/Path.php index 5c7248acf..e338e06dd 100644 --- a/src/lib/filesystem/src/Flow/Filesystem/Path.php +++ b/src/lib/filesystem/src/Flow/Filesystem/Path.php @@ -280,7 +280,7 @@ public function randomize() : self $base = \trim(\mb_substr($this->path(), 0, \mb_strrpos($this->path(), $this->basename())), DIRECTORY_SEPARATOR); return new self( - $this->protocol->scheme() . $base . DIRECTORY_SEPARATOR . $this->filename . '_' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . $extension, + $this->protocol->scheme() . $base . DIRECTORY_SEPARATOR . $this->filename . '_' . \Flow\ETL\DSL\generate_random_string() . $extension, $this->options ); } diff --git a/src/lib/filesystem/src/Flow/Filesystem/Stream/Block/NativeLocalFileBlocksFactory.php b/src/lib/filesystem/src/Flow/Filesystem/Stream/Block/NativeLocalFileBlocksFactory.php index 1e38e6ec3..53ee08711 100644 --- a/src/lib/filesystem/src/Flow/Filesystem/Stream/Block/NativeLocalFileBlocksFactory.php +++ b/src/lib/filesystem/src/Flow/Filesystem/Stream/Block/NativeLocalFileBlocksFactory.php @@ -32,7 +32,7 @@ public function __construct(?string $blockLocation = null) public function create(int $size) : Block { - $id = \Flow\ETL\NativePHPRandomValueGenerator::string(32); + $id = \Flow\ETL\DSL\generate_random_string(); return new Block($id, $size, new Path($this->blockLocation . DIRECTORY_SEPARATOR . $id)); } diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/CompressionTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/CompressionTest.php index 394618d81..0596aa2f8 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/CompressionTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/CompressionTest.php @@ -4,6 +4,7 @@ namespace Flow\Parquet\Tests\Integration\IO; +use function Flow\ETL\DSL\generate_random_int; use Faker\Factory; use Flow\Parquet\ParquetFile\Schema\{FlatColumn, ListElement, NestedColumn}; use Flow\Parquet\ParquetFile\{Compressions, Schema}; @@ -27,7 +28,7 @@ public function test_writing_and_reading_file_with_brotli_compression() : void self::markTestSkipped('The Brotli extension is not available'); } - $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(Compressions::BROTLI); @@ -51,11 +52,11 @@ public function test_writing_and_reading_file_with_brotli_compression() : void 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ), ], ], @@ -74,7 +75,7 @@ public function test_writing_and_reading_file_with_brotli_compression() : void public function test_writing_and_reading_file_with_gzip_compression() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(Compressions::GZIP); @@ -98,11 +99,11 @@ public function test_writing_and_reading_file_with_gzip_compression() : void 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ), ], ], @@ -126,7 +127,7 @@ public function test_writing_and_reading_file_with_lz4_compression() : void self::markTestSkipped('The lz4 extension is not available'); } - $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(Compressions::LZ4); @@ -150,11 +151,11 @@ public function test_writing_and_reading_file_with_lz4_compression() : void 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ), ], ], @@ -178,7 +179,7 @@ public function test_writing_and_reading_file_with_lz4_raw_compression() : void self::markTestSkipped('The lz4 extension is not available'); } - $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(Compressions::LZ4_RAW); @@ -202,11 +203,11 @@ public function test_writing_and_reading_file_with_lz4_raw_compression() : void 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ), ], ], @@ -230,7 +231,7 @@ public function test_writing_and_reading_file_with_snappy_compression() : void self::markTestSkipped('The snappy extension is not available'); } - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(Compressions::SNAPPY); @@ -254,11 +255,11 @@ public function test_writing_and_reading_file_with_snappy_compression() : void 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ), ], ], @@ -281,7 +282,7 @@ public function test_writing_and_reading_file_with_snappy_polyfill() : void self::markTestSkipped('The snappy extension is available'); } - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(Compressions::SNAPPY); @@ -305,11 +306,11 @@ public function test_writing_and_reading_file_with_snappy_polyfill() : void 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ), ], ], @@ -328,7 +329,7 @@ public function test_writing_and_reading_file_with_snappy_polyfill() : void public function test_writing_and_reading_file_with_uncompressed_compression() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(Compressions::UNCOMPRESSED); @@ -352,11 +353,11 @@ public function test_writing_and_reading_file_with_uncompressed_compression() : 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ), ], ], @@ -380,7 +381,7 @@ public function test_writing_and_reading_file_with_zstd_compression() : void self::markTestSkipped('The Zstd extension is not available'); } - $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(Compressions::ZSTD); @@ -404,11 +405,11 @@ public function test_writing_and_reading_file_with_zstd_compression() : void 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ), ], ], diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/ListsWritingTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/ListsWritingTest.php index ac5b58abc..b72c6da23 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/ListsWritingTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/ListsWritingTest.php @@ -4,6 +4,7 @@ namespace Flow\Parquet\Tests\Integration\IO; +use function Flow\ETL\DSL\generate_random_int; use Faker\Factory; use Flow\Parquet\ParquetFile\Schema; use Flow\Parquet\ParquetFile\Schema\{FlatColumn, ListElement, NestedColumn}; @@ -21,7 +22,7 @@ protected function setUp() : void public function test_writing_empty_lists_of_ints() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::list('list_of_ints', ListElement::int32())); @@ -44,7 +45,7 @@ public function test_writing_empty_lists_of_ints() : void public function test_writing_list_of_ints() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::list('list_of_ints', ListElement::int32())); @@ -53,7 +54,7 @@ public function test_writing_list_of_ints() : void $inputData = \array_merge(...\array_map(static function (int $i) use ($faker) : array { return [ [ - 'list_of_ints' => \array_map(static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10))), + 'list_of_ints' => \array_map(static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), \range(1, generate_random_int(2, 10))), ], ]; }, \range(1, 100))); @@ -68,7 +69,7 @@ public function test_writing_list_of_ints() : void public function test_writing_list_of_strings() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::list('list_of_strings', ListElement::string())); @@ -77,7 +78,7 @@ public function test_writing_list_of_strings() : void $inputData = \array_merge(...\array_map(static function (int $i) use ($faker) : array { return [ [ - 'list_of_strings' => \array_map(static fn ($i) => $faker->text(10), \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10))), + 'list_of_strings' => \array_map(static fn ($i) => $faker->text(10), \range(1, generate_random_int(2, 10))), ], ]; }, \range(1, 100))); @@ -92,7 +93,7 @@ public function test_writing_list_of_strings() : void public function test_writing_list_of_structures() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with( @@ -111,7 +112,7 @@ public function test_writing_list_of_structures() : void 'list_of_structs' => \array_map(static fn ($i) => [ 'id' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'name' => $faker->text(10), - ], \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10))), + ], \range(1, generate_random_int(2, 10))), ], ]; }, \range(1, 10))); @@ -126,7 +127,7 @@ public function test_writing_list_of_structures() : void public function test_writing_list_with_nullable_elements() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::list('list_of_ints', ListElement::int32())); @@ -136,7 +137,7 @@ public function test_writing_list_with_nullable_elements() : void return [ [ 'list_of_ints' => $i % 2 === 0 - ? \array_map(static fn ($a) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10))) + ? \array_map(static fn ($a) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), \range(1, generate_random_int(2, 10))) : null, ], ]; @@ -152,7 +153,7 @@ public function test_writing_list_with_nullable_elements() : void public function test_writing_list_with_nullable_list_values() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::list('list_of_ints', ListElement::int32())); @@ -162,7 +163,7 @@ public function test_writing_list_with_nullable_list_values() : void return [ [ 'list_of_ints' => $i % 2 === 0 - ? \array_map(static fn ($a) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 2))) + ? \array_map(static fn ($a) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), \range(1, generate_random_int(2, 2))) : [null, null], ], ]; @@ -178,7 +179,7 @@ public function test_writing_list_with_nullable_list_values() : void public function test_writing_nullable_list_of_ints() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::list('list_of_ints', ListElement::int32())); @@ -188,7 +189,7 @@ public function test_writing_nullable_list_of_ints() : void return [ [ 'list_of_ints' => $i % 2 === 0 - ? \array_map(static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10))) + ? \array_map(static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), \range(1, generate_random_int(2, 10))) : null, ], ]; @@ -204,7 +205,7 @@ public function test_writing_nullable_list_of_ints() : void public function test_writing_nullable_list_of_structures() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with( @@ -227,7 +228,7 @@ public function test_writing_nullable_list_of_structures() : void ? \array_map(static fn ($i) => [ 'id' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'name' => $faker->text(10), - ], \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10))) + ], \range(1, generate_random_int(2, 10))) : null, ], ]; @@ -243,7 +244,7 @@ public function test_writing_nullable_list_of_structures() : void public function test_writing_nullable_lists_of_ints() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::list('list_of_ints', ListElement::int32())); diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/MapsWritingTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/MapsWritingTest.php index 70182b1c0..a27da3f52 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/MapsWritingTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/MapsWritingTest.php @@ -4,6 +4,7 @@ namespace Flow\Parquet\Tests\Integration\IO; +use function Flow\ETL\DSL\generate_random_int; use Faker\Factory; use Flow\Parquet\ParquetFile\Schema; use Flow\Parquet\ParquetFile\Schema\{MapKey, MapValue, NestedColumn}; @@ -21,7 +22,7 @@ protected function setUp() : void public function test_writing_empty_map_of_int_int() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::map('map_int_int', MapKey::int32(), MapValue::int32())); @@ -44,7 +45,7 @@ public function test_writing_empty_map_of_int_int() : void public function test_writing_map_of_int_int() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::map('map_int_int', MapKey::int32(), MapValue::int32())); @@ -56,7 +57,7 @@ public function test_writing_map_of_int_int() : void 'map_int_int' => \array_merge( ...\array_map( static fn ($i) => [$i => $faker->numberBetween(0, Consts::PHP_INT32_MAX)], - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ) ), ], @@ -73,7 +74,7 @@ public function test_writing_map_of_int_int() : void public function test_writing_map_of_int_int_with_all_maps_null() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::map('map_int_int', MapKey::int32(), MapValue::int32())); @@ -96,7 +97,7 @@ public function test_writing_map_of_int_int_with_all_maps_null() : void public function test_writing_map_of_int_string() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::map('map_int_string', MapKey::int32(), MapValue::string())); @@ -108,7 +109,7 @@ public function test_writing_map_of_int_string() : void 'map_int_string' => \array_merge( ...\array_map( static fn ($i) => [$i => $faker->text(10)], - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ) ), ], @@ -125,7 +126,7 @@ public function test_writing_map_of_int_string() : void public function test_writing_nullable_map_of_int_int() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::map('map_int_int', MapKey::int32(), MapValue::int32())); @@ -138,7 +139,7 @@ public function test_writing_nullable_map_of_int_int() : void ? \array_merge( ...\array_map( static fn ($i) => [$i => $faker->numberBetween(0, Consts::PHP_INT32_MAX)], - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ) ) : null, diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/PaginationTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/PaginationTest.php index da69dcbaa..d7790609e 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/PaginationTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/PaginationTest.php @@ -4,6 +4,7 @@ namespace Flow\Parquet\Tests\Integration\IO; +use function Flow\ETL\DSL\generate_random_int; use Flow\Parquet\Exception\InvalidArgumentException; use Flow\Parquet\ParquetFile\Schema; use Flow\Parquet\ParquetFile\Schema\{FlatColumn, NestedColumn}; @@ -125,12 +126,12 @@ private function generateDataset(string $path) : void 'created_at' => new \DateTimeImmutable('2024-01-01 + ' . $i . ' days'), 'list_of_int' => \array_map( static fn (int $i) => $i, - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ), 'map_of_int_string' => \array_merge( ...\array_map( static fn (int $i) => [$i => 'value-' . $i], - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ) ), 'struct' => [ @@ -140,12 +141,12 @@ private function generateDataset(string $path) : void 'created_at' => new \DateTimeImmutable('2024-01-01 + ' . $i . ' days'), 'list_of_int' => \array_map( static fn (int $i) => $i, - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ), 'map_of_int_string' => \array_merge( ...\array_map( static fn (int $i) => [$i => 'value-' . $i], - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ) ), ], diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/SimpleTypesWritingTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/SimpleTypesWritingTest.php index 27efa5813..1a6277017 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/SimpleTypesWritingTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/SimpleTypesWritingTest.php @@ -4,6 +4,7 @@ namespace Flow\Parquet\Tests\Integration\IO; +use function Flow\ETL\DSL\generate_random_int; use Faker\Factory; use Flow\Parquet\ParquetFile\Schema; use Flow\Parquet\ParquetFile\Schema\FlatColumn; @@ -21,7 +22,7 @@ protected function setUp() : void public function test_writing_bool_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::boolean('boolean')); @@ -47,7 +48,7 @@ public function test_writing_bool_column() : void public function test_writing_bool_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::boolean('boolean')); @@ -55,7 +56,7 @@ public function test_writing_bool_nullable_column() : void $inputData = \array_merge(...\array_map(static function (int $i) : array { return [ [ - 'boolean' => $i % 2 == 0 ? (bool) \Flow\ETL\NativePHPRandomValueGenerator::int(0, 1) : null, + 'boolean' => $i % 2 == 0 ? (bool) generate_random_int(0, 1) : null, ], ]; }, \range(1, 100))); @@ -73,7 +74,7 @@ public function test_writing_bool_nullable_column() : void public function test_writing_date_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::date('date')); @@ -101,7 +102,7 @@ public function test_writing_date_column() : void public function test_writing_date_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::date('date')); @@ -129,7 +130,7 @@ public function test_writing_date_nullable_column() : void public function test_writing_decimal_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::decimal('decimal')); @@ -157,7 +158,7 @@ public function test_writing_decimal_column() : void public function test_writing_decimal_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::decimal('decimal')); @@ -185,7 +186,7 @@ public function test_writing_decimal_nullable_column() : void public function test_writing_double_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::double('double')); @@ -213,7 +214,7 @@ public function test_writing_double_column() : void public function test_writing_double_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::double('double')); @@ -241,7 +242,7 @@ public function test_writing_double_nullable_column() : void public function test_writing_enum_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::enum('enum')); @@ -251,7 +252,7 @@ public function test_writing_enum_column() : void $inputData = \array_merge(...\array_map(static function (int $i) use ($enum) : array { return [ [ - 'enum' => $enum[\Flow\ETL\NativePHPRandomValueGenerator::int(0, 3)], + 'enum' => $enum[generate_random_int(0, 3)], ], ]; }, \range(1, 100))); @@ -269,7 +270,7 @@ public function test_writing_enum_column() : void public function test_writing_float_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::float('float')); @@ -295,7 +296,7 @@ public function test_writing_float_column() : void public function test_writing_float_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::float('float')); @@ -321,7 +322,7 @@ public function test_writing_float_nullable_column() : void public function test_writing_int32_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::int32('int32')); @@ -349,7 +350,7 @@ public function test_writing_int32_column() : void public function test_writing_int32_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::int32('int32')); @@ -377,7 +378,7 @@ public function test_writing_int32_nullable_column() : void public function test_writing_int64() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::int64('int64')); @@ -404,7 +405,7 @@ public function test_writing_int64() : void public function test_writing_int64_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::int64('int64')); @@ -431,7 +432,7 @@ public function test_writing_int64_nullable_column() : void public function test_writing_json_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::json('json')); @@ -458,7 +459,7 @@ public function test_writing_json_column() : void public function test_writing_json_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::json('json')); @@ -487,7 +488,7 @@ public function test_writing_json_nullable_column() : void public function test_writing_string_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::string('string')); @@ -514,7 +515,7 @@ public function test_writing_string_column() : void public function test_writing_string_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::string('string')); @@ -541,7 +542,7 @@ public function test_writing_string_nullable_column() : void public function test_writing_time_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::time('time')); @@ -566,7 +567,7 @@ public function test_writing_time_column() : void public function test_writing_time_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::time('time')); @@ -591,7 +592,7 @@ public function test_writing_time_nullable_column() : void public function test_writing_timestamp_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::dateTime('dateTime')); @@ -618,7 +619,7 @@ public function test_writing_timestamp_column() : void public function test_writing_timestamp_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::dateTime('dateTime')); @@ -645,7 +646,7 @@ public function test_writing_timestamp_nullable_column() : void public function test_writing_uuid_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::uuid('uuid')); @@ -672,7 +673,7 @@ public function test_writing_uuid_column() : void public function test_writing_uuid_nullable_column() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::uuid('uuid')); diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/StructsWritingTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/StructsWritingTest.php index ef7390118..8610aaeb2 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/StructsWritingTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/StructsWritingTest.php @@ -4,6 +4,7 @@ namespace Flow\Parquet\Tests\Integration\IO; +use function Flow\ETL\DSL\generate_random_int; use Faker\Factory; use Flow\Parquet\ParquetFile\Schema; use Flow\Parquet\ParquetFile\Schema\{FlatColumn, ListElement, NestedColumn}; @@ -21,7 +22,7 @@ protected function setUp() : void public function test_writing_flat_nullable_structure() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::struct('struct', [ @@ -45,11 +46,11 @@ public function test_writing_flat_nullable_structure() : void 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ), ] : null, @@ -67,7 +68,7 @@ public function test_writing_flat_nullable_structure() : void public function test_writing_flat_structure() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::struct('struct', [ @@ -90,11 +91,11 @@ public function test_writing_flat_structure() : void 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ), ], ], @@ -111,7 +112,7 @@ public function test_writing_flat_structure() : void public function test_writing_flat_structure_with_nullable_elements() : void { - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::struct('struct', [ @@ -135,13 +136,13 @@ public function test_writing_flat_structure_with_nullable_elements() : void 'list_of_int' => $i % 2 === 0 ? \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ) : null, 'list_of_string' => $i % 2 === 0 ? \array_map( static fn ($i) => $faker->text(10), - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ) : null, ], diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/WriterTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/WriterTest.php index 4d83f0085..9d060dbac 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/WriterTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/WriterTest.php @@ -4,6 +4,7 @@ namespace Flow\Parquet\Tests\Integration\IO; +use function Flow\ETL\DSL\generate_random_int; use Composer\InstalledVersions; use Faker\Factory; use Flow\Filesystem\Stream\NativeLocalDestinationStream; @@ -36,7 +37,7 @@ public function test_created_by_metadata() : void { $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $schema = $this->createSchema(); $writer->open($path, $schema); @@ -51,7 +52,7 @@ public function test_opening_already_open_writer() : void { $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $schema = $this->createSchema(); @@ -80,7 +81,7 @@ public function test_writing_column_statistics() : void ->set(Option::WRITER_VERSION, 1) ); - $path = __DIR__ . '/var/test-writer-parquet-test-v2-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-v2-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $schema = Schema::with($column = FlatColumn::int32('int32')); @@ -109,7 +110,7 @@ public function test_writing_data_page_v2_statistics() : void ->set(Option::WRITER_VERSION, 2) ); - $path = __DIR__ . '/var/test-writer-parquet-test-v2-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-v2-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $schema = Schema::with($column = FlatColumn::int32('int32')); @@ -136,7 +137,7 @@ public function test_writing_in_batches_to_file() : void { $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $schema = $this->createSchema(); @@ -163,7 +164,7 @@ public function test_writing_in_batches_to_file_without_explicit_close() : void { $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $schema = $this->createSchema(); @@ -189,7 +190,7 @@ public function test_writing_in_batches_to_stream() : void { $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $schema = $this->createSchema(); @@ -227,7 +228,7 @@ public function test_writing_to_file() : void { $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $schema = $this->createSchema(); $row = $this->createRow(); @@ -249,7 +250,7 @@ public function test_writing_to_file_v2() : void ->set(Option::WRITER_VERSION, 2) ); - $path = __DIR__ . '/var/test-writer-parquet-test-v2-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-v2-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $schema = $this->createSchema(); $row = $this->createRow(); @@ -269,7 +270,7 @@ public function test_writing_to_stream() : void { $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $schema = $this->createSchema(); $row = $this->createRow(); @@ -298,11 +299,11 @@ private function createRow() : array 'int32' => $faker->numberBetween(0, Consts::PHP_INT32_MAX), 'list_of_int' => \array_map( static fn ($i) => $faker->numberBetween(0, Consts::PHP_INT32_MAX), - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \Flow\ETL\NativePHPRandomValueGenerator::int(2, 10)) + \range(1, generate_random_int(2, 10)) ), ], ]; diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/WriterValidatorTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/WriterValidatorTest.php index 0ac701b1d..3459ef858 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/WriterValidatorTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/IO/WriterValidatorTest.php @@ -22,7 +22,7 @@ public function test_skipping_required_row() : void $this->expectExceptionMessage('Column "string" is required'); $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $schema = Schema::with( Schema\FlatColumn::int32('id'), @@ -37,7 +37,7 @@ public function test_writing_int_value_to_string_column() : void $this->expectExceptionMessage('Column "string" is not string, got "integer" instead'); $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $schema = Schema::with(Schema\FlatColumn::string('string')); @@ -49,7 +49,7 @@ public function test_writing_null_to_list_that_is_required() : void $this->expectExceptionMessage('Column "list" is required'); $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $schema = Schema::with(Schema\NestedColumn::list('list', Schema\ListElement::string())->makeRequired()); @@ -61,7 +61,7 @@ public function test_writing_null_to_list_with_element_is_required() : void $this->expectExceptionMessage('Column "list.list.element" is not string, got "NULL" instead'); $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $schema = Schema::with(Schema\NestedColumn::list('list', Schema\ListElement::string(required: true))); @@ -73,7 +73,7 @@ public function test_writing_null_to_map_with_value_required() : void $this->expectExceptionMessage('Column "map.key_value.value" is not string, got "NULL" instead'); $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $schema = Schema::with(Schema\NestedColumn::map('map', Schema\MapKey::string(), Schema\MapValue::string(required: true))); @@ -85,7 +85,7 @@ public function test_writing_null_to_required_map() : void $this->expectExceptionMessage('Column "map" is required'); $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $schema = Schema::with(Schema\NestedColumn::map('map', Schema\MapKey::string(), Schema\MapValue::string())->makeRequired()); @@ -97,7 +97,7 @@ public function test_writing_null_value_to_required_column() : void $this->expectExceptionMessage('Column "string" is required'); $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $schema = Schema::with(Schema\FlatColumn::string('string')->makeRequired()); @@ -107,7 +107,7 @@ public function test_writing_null_value_to_required_column() : void public function test_writing_row_with_missing_optional_columns() : void { $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $schema = Schema::with( Schema\FlatColumn::int32('id'), @@ -141,7 +141,7 @@ public function test_writing_row_with_missing_optional_columns() : void public function test_writing_row_with_missing_optional_columns_in_different_columns() : void { $writer = new Writer(); - $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\NativePHPRandomValueGenerator::string(32) . '.parquet'; + $path = __DIR__ . '/var/test-writer-validator-parquet-test-' . \Flow\ETL\DSL\generate_random_string() . '.parquet'; $schema = Schema::with( Schema\FlatColumn::int32('id'), diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/ParquetFile/Data/RLEBitPackedHybridTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/ParquetFile/Data/RLEBitPackedHybridTest.php index 63b631db1..c5a6332c9 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/ParquetFile/Data/RLEBitPackedHybridTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/ParquetFile/Data/RLEBitPackedHybridTest.php @@ -4,6 +4,7 @@ namespace Flow\Parquet\Tests\Integration\ParquetFile\Data; +use function Flow\ETL\DSL\generate_random_int; use Flow\Parquet\BinaryReader\BinaryBufferReader; use Flow\Parquet\BinaryWriter\BinaryBufferWriter; use Flow\Parquet\ParquetFile\Data\{BitWidth, RLEBitPackedHybrid}; @@ -230,10 +231,10 @@ public function test_with_dynamically_generated_values() : void { for ($iteration = 0; $iteration < 100; $iteration++) { $values = []; - $maxValues = \Flow\ETL\NativePHPRandomValueGenerator::int(10, 1000); + $maxValues = generate_random_int(10, 1000); for ($i = 0; $i < $maxValues; $i++) { - $values[] = \Flow\ETL\NativePHPRandomValueGenerator::int(0, 1000); + $values[] = generate_random_int(0, 1000); } $buffer = ''; diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/ParquetFile/RowGroupBuilder/PagesBuilderTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/ParquetFile/RowGroupBuilder/PagesBuilderTest.php index 2cf3fb2d6..19027a4fe 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/ParquetFile/RowGroupBuilder/PagesBuilderTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/ParquetFile/RowGroupBuilder/PagesBuilderTest.php @@ -58,7 +58,7 @@ public function test_building_pages_for_enum_columns() : void 1 => 'GREEN', 2 => 'BLUE', ]; - $values = \array_map(static fn ($i) => $enum[\Flow\ETL\NativePHPRandomValueGenerator::int(0, 2)], \range(0, 99)); + $values = \array_map(static fn ($i) => $enum[generate_random_int(0, 2)], \range(0, 99)); $statistics = new ColumnChunkStatistics($column); foreach ($values as $value) { diff --git a/src/lib/snappy/tests/Flow/Snappy/Tests/Integration/SnappyTest.php b/src/lib/snappy/tests/Flow/Snappy/Tests/Integration/SnappyTest.php index 1d4abf2bb..168950245 100644 --- a/src/lib/snappy/tests/Flow/Snappy/Tests/Integration/SnappyTest.php +++ b/src/lib/snappy/tests/Flow/Snappy/Tests/Integration/SnappyTest.php @@ -4,6 +4,7 @@ namespace Flow\Snappy\Tests\Integration; +use function Flow\ETL\DSL\generate_random_int; use Faker\Factory; use Flow\Snappy\Snappy; use PHPUnit\Framework\TestCase; @@ -71,7 +72,7 @@ public function test_snappy_compression_with_dynamically_generated_texts() : voi $snappy = new Snappy(); for ($iteration = 0; $iteration < 100; $iteration++) { - $string = Factory::create()->text(\Flow\ETL\NativePHPRandomValueGenerator::int(10, 1000)); + $string = Factory::create()->text(generate_random_int(10, 1000)); self::assertSame( $string, From 995bbd9086265f04119467032e3f3b9ceaca512e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Mleczko?= Date: Wed, 31 Jul 2024 01:44:45 +0200 Subject: [PATCH 6/8] Delete src/core/etl/tests/Flow/ETL/Tests/Integration/Cache/PSRSimpleCacheTest.php --- .../tests/Flow/ETL/Tests/Integration/Cache/PSRSimpleCacheTest.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/core/etl/tests/Flow/ETL/Tests/Integration/Cache/PSRSimpleCacheTest.php diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Cache/PSRSimpleCacheTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Cache/PSRSimpleCacheTest.php deleted file mode 100644 index e69de29bb..000000000 From 5278f2143f6ff848d307237f5d5e5887ce9d3752 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Mleczko?= Date: Wed, 31 Jul 2024 01:33:49 +0200 Subject: [PATCH 7/8] Use functions instead of static calls for tests requiring randomness --- .../Integration/MeilisearchPHP/MeilisearchExtractorTest.php | 1 + .../Integration/ParquetFile/RowGroupBuilder/PagesBuilderTest.php | 1 + 2 files changed, 2 insertions(+) diff --git a/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchExtractorTest.php b/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchExtractorTest.php index ce4987c83..d15b30ef0 100644 --- a/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchExtractorTest.php +++ b/src/adapter/etl-adapter-meilisearch/tests/Flow/ETL/Adapter/Meilisearch/Tests/Integration/MeilisearchPHP/MeilisearchExtractorTest.php @@ -5,6 +5,7 @@ namespace Flow\ETL\Adapter\Meilisearch\Tests\Integration\MeilisearchPHP; use function Flow\ETL\Adapter\Meilisearch\{from_meilisearch, meilisearch_hits_to_rows, to_meilisearch_bulk_index}; +use function Flow\ETL\DSL\generate_random_int; use Flow\ETL\Adapter\Meilisearch\Tests\Context\MeilisearchContext; use Flow\ETL\{Config, Flow, FlowContext, Row, Rows}; use PHPUnit\Framework\TestCase; diff --git a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/ParquetFile/RowGroupBuilder/PagesBuilderTest.php b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/ParquetFile/RowGroupBuilder/PagesBuilderTest.php index 19027a4fe..97ceece50 100644 --- a/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/ParquetFile/RowGroupBuilder/PagesBuilderTest.php +++ b/src/lib/parquet/tests/Flow/Parquet/Tests/Integration/ParquetFile/RowGroupBuilder/PagesBuilderTest.php @@ -4,6 +4,7 @@ namespace Flow\Parquet\Tests\Integration\ParquetFile\RowGroupBuilder; +use function Flow\ETL\DSL\generate_random_int; use Faker\Factory; use Flow\Parquet\Data\DataConverter; use Flow\Parquet\ParquetFile\Page\Header\{DataPageHeader, DictionaryPageHeader, Type}; From c484a21296dda1a7a50c4917a4117a1e984b4b2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Mleczko?= Date: Wed, 31 Jul 2024 02:17:40 +0200 Subject: [PATCH 8/8] Add scalar function for random string --- src/core/etl/src/Flow/ETL/DSL/functions.php | 68 ++++++++++++++++++- .../src/Flow/ETL/Function/RandomString.php | 25 +++++++ 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 src/core/etl/src/Flow/ETL/Function/RandomString.php diff --git a/src/core/etl/src/Flow/ETL/DSL/functions.php b/src/core/etl/src/Flow/ETL/DSL/functions.php index 42d49777d..0fea6d5cb 100644 --- a/src/core/etl/src/Flow/ETL/DSL/functions.php +++ b/src/core/etl/src/Flow/ETL/DSL/functions.php @@ -14,7 +14,65 @@ use Flow\ETL\Function\ArraySort\Sort; use Flow\ETL\Function\Between\Boundary; use Flow\ETL\Function\StyleConverter\StringStyles; -use Flow\ETL\Function\{All, Any, ArrayExists, ArrayGet, ArrayGetCollection, ArrayKeyRename, ArrayKeysStyleConvert, ArrayMerge, ArrayMergeCollection, ArrayReverse, ArraySort, ArrayUnpack, Average, Between, CallMethod, Capitalize, Cast, Collect, CollectUnique, Combine, Concat, Count, DateTimeFormat, DenseRank, Exists, First, Hash, Last, ListFunctions, Literal, Max, Min, Not, Now, NumberFormat, Optional, PregMatch, PregMatchAll, PregReplace, Rank, Round, RowNumber, Sanitize, ScalarFunction, Size, Split, Sprintf, StructureFunctions, Sum, ToDate, ToDateTime, ToLower, ToMoney, ToTimeZone, ToUpper, Ulid, Uuid, When}; +use Flow\ETL\Function\{All, + Any, + ArrayExists, + ArrayGet, + ArrayGetCollection, + ArrayKeyRename, + ArrayKeysStyleConvert, + ArrayMerge, + ArrayMergeCollection, + ArrayReverse, + ArraySort, + ArrayUnpack, + Average, + Between, + CallMethod, + Capitalize, + Cast, + Collect, + CollectUnique, + Combine, + Concat, + Count, + DateTimeFormat, + DenseRank, + Exists, + First, + Hash, + Last, + ListFunctions, + Literal, + Max, + Min, + Not, + Now, + NumberFormat, + Optional, + PregMatch, + PregMatchAll, + PregReplace, + RandomString, + Rank, + Round, + RowNumber, + Sanitize, + ScalarFunction, + Size, + Split, + Sprintf, + StructureFunctions, + Sum, + ToDate, + ToDateTime, + ToLower, + ToMoney, + ToTimeZone, + ToUpper, + Ulid, + Uuid, + When}; use Flow\ETL\Loader\StreamLoader\Output; use Flow\ETL\Loader\{CallbackLoader, MemoryLoader, StreamLoader, TransformerLoader}; use Flow\ETL\Memory\Memory; @@ -52,6 +110,7 @@ Loader, NativePHPRandomValueGenerator, Pipeline, + RandomValueGenerator, Row, Rows, Transformer, @@ -1220,3 +1279,10 @@ function generate_random_int(int $start = PHP_INT_MIN, int $end = PHP_INT_MAX, N { return $generator->int($start, $end); } + +function random_string( + int|ScalarFunction $length, + RandomValueGenerator $generator = new NativePHPRandomValueGenerator() +) : RandomString { + return new RandomString($length, $generator); +} diff --git a/src/core/etl/src/Flow/ETL/Function/RandomString.php b/src/core/etl/src/Flow/ETL/Function/RandomString.php new file mode 100644 index 000000000..b427e14da --- /dev/null +++ b/src/core/etl/src/Flow/ETL/Function/RandomString.php @@ -0,0 +1,25 @@ +length = $length; + $this->generator = $generator; + } + + public function eval(Row $row) : string + { + return $this->generator->string(is_int($this->length) ? $this->length : $this->length->eval($row)); + } +}