From 63ef619075eac28cd9087266a1573dba63fc65c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Mleczko?= Date: Wed, 31 Jul 2024 08:08:57 +0200 Subject: [PATCH] Add UniqueFactory for creating random string or int from given range (#1128) * Add UniqueFactory for creating random string or int from given range * CS fixes Co-authored-by: Joseph Bielawski * Rename to RandomGenerator, introduce interface * Fix missing import after move * Use functions instead of static calls for tests requiring randomness * Delete src/core/etl/tests/Flow/ETL/Tests/Integration/Cache/PSRSimpleCacheTest.php * Use functions instead of static calls for tests requiring randomness * Add scalar function for random string --------- Co-authored-by: Joseph Bielawski --- docs/components/libs/snappy.md | 2 +- .../ElasticsearchExtractorTest.php | 12 +-- .../ElasticsearchLoaderTest.php | 9 +- .../MeilisearchExtractorTest.php | 7 +- .../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 | 79 ++++++++++++++++- .../src/Flow/ETL/Function/RandomString.php | 25 ++++++ .../ETL/NativePHPRandomValueGenerator.php | 21 +++++ .../etl/src/Flow/ETL/RandomValueGenerator.php | 12 +++ .../Flow/ETL/Tests/Double/FakeExtractor.php | 3 +- .../DataFrame/PartitioningTest.php | 9 +- .../ETL/Tests/Unit/Hash/NativePHPHashTest.php | 8 +- .../NativePHPRandomValueGeneratorTest.php | 84 +++++++++++++++++++ .../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 | 3 +- .../Snappy/Tests/Integration/SnappyTest.php | 3 +- 37 files changed, 421 insertions(+), 166 deletions(-) create mode 100644 src/core/etl/src/Flow/ETL/Function/RandomString.php create mode 100644 src/core/etl/src/Flow/ETL/NativePHPRandomValueGenerator.php create mode 100644 src/core/etl/src/Flow/ETL/RandomValueGenerator.php create mode 100644 src/core/etl/tests/Flow/ETL/Tests/Unit/NativePHPRandomValueGeneratorTest.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..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) \random_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) \random_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) \random_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) \random_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) \random_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 fd092199b..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' . bin2hex(random_bytes(16)))), + 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' . bin2hex(random_bytes(16)))), + 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' . bin2hex(random_bytes(16)))), + 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' . bin2hex(random_bytes(16)))), + 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 e0590bc6e..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; @@ -37,7 +38,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) generate_random_int(0, 1)) ), \range(1, 100) ), @@ -63,7 +64,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) 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 +103,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) 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 b7c69f85a..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' . bin2hex(random_bytes(16)))), + 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' . bin2hex(random_bytes(16)))), + 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' . bin2hex(random_bytes(16)))), + 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' . bin2hex(random_bytes(16)))), + 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 4001741f4..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' . bin2hex(random_bytes(16)) . '.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 e739b6a3a..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 = \bin2hex(\random_bytes(16)), $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 = \bin2hex(\random_bytes(16)), $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 f09fc36b2..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}; +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_' . bin2hex(random_bytes(16)); + $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..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; @@ -50,7 +108,9 @@ Join\Comparison\Identical, Join\Expression, Loader, + NativePHPRandomValueGenerator, Pipeline, + RandomValueGenerator, Row, Rows, Transformer, @@ -1209,3 +1269,20 @@ 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); +} + +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)); + } +} diff --git a/src/core/etl/src/Flow/ETL/NativePHPRandomValueGenerator.php b/src/core/etl/src/Flow/ETL/NativePHPRandomValueGenerator.php new file mode 100644 index 000000000..50f809331 --- /dev/null +++ b/src/core/etl/src/Flow/ETL/NativePHPRandomValueGenerator.php @@ -0,0 +1,21 @@ += 1 ?: $bytes = 1; + + return \substr(\bin2hex(\random_bytes($bytes)), 0, \max(0, $int)); + } +} 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..9769bfc4b --- /dev/null +++ b/src/core/etl/src/Flow/ETL/RandomValueGenerator.php @@ -0,0 +1,12 @@ + 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\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/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/NativePHPRandomValueGeneratorTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/NativePHPRandomValueGeneratorTest.php new file mode 100644 index 000000000..9b8276592 --- /dev/null +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/NativePHPRandomValueGeneratorTest.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, ((new NativePHPRandomValueGenerator())->int(1, 1))); + self::assertThat( + (new NativePHPRandomValueGenerator())->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((new NativePHPRandomValueGenerator())->string($expectedLength))); + } + + public function test_empty_string_on_length_below_1() : void + { + self::assertSame( + '', + (new NativePHPRandomValueGenerator())->string(0) + ); + self::assertSame( + '', + (new NativePHPRandomValueGenerator())->string(-1) + ); + } + + /** @dataProvider invalid_range_provider */ + public function test_fail_on_invalid_range(int $min, int $max) : void + { + self::expectException(\ValueError::class); + (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( + (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 17eff86d8..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', \random_int(100, 100000)), - float_entry('price', \random_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 7f53fa7e3..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', \random_int(100, 100000) / 100), - float_entry('float_b', \random_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', \random_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 37918aab5..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 = \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\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 a876ba6d7..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 = \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\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 0d7d14147..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 = \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\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 a1a116398..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 . '_' . \bin2hex(\random_bytes(16)) . $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 44e25917c..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 = \bin2hex(\random_bytes(16)); + $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 2de93d1bb..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-' . bin2hex(random_bytes(16)) . '.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, \random_int(2, 10)) + \range(1, generate_random_int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \random_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-' . bin2hex(random_bytes(16)) . '.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, \random_int(2, 10)) + \range(1, generate_random_int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \random_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-' . bin2hex(random_bytes(16)) . '.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, \random_int(2, 10)) + \range(1, generate_random_int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \random_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-' . bin2hex(random_bytes(16)) . '.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, \random_int(2, 10)) + \range(1, generate_random_int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \random_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-' . bin2hex(random_bytes(16)) . '.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, \random_int(2, 10)) + \range(1, generate_random_int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \random_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-' . bin2hex(random_bytes(16)) . '.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, \random_int(2, 10)) + \range(1, generate_random_int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \random_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-' . bin2hex(random_bytes(16)) . '.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, \random_int(2, 10)) + \range(1, generate_random_int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \random_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-' . bin2hex(random_bytes(16)) . '.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, \random_int(2, 10)) + \range(1, generate_random_int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \random_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 e0b3307b0..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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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, \random_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-' . bin2hex(random_bytes(16)) . '.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, \random_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-' . bin2hex(random_bytes(16)) . '.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, \random_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-' . bin2hex(random_bytes(16)) . '.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, \random_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-' . bin2hex(random_bytes(16)) . '.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, \random_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-' . bin2hex(random_bytes(16)) . '.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, \random_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-' . bin2hex(random_bytes(16)) . '.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, \random_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-' . bin2hex(random_bytes(16)) . '.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 61564dafa..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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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, \random_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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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, \random_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-' . bin2hex(random_bytes(16)) . '.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, \random_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 8799db67d..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, \random_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, \random_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, \random_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, \random_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 0d083bddd..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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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) \random_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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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[\random_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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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 5262f55cc..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-' . bin2hex(random_bytes(16)) . '.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, \random_int(2, 10)) + \range(1, generate_random_int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \random_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-' . bin2hex(random_bytes(16)) . '.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, \random_int(2, 10)) + \range(1, generate_random_int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \random_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-' . bin2hex(random_bytes(16)) . '.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, \random_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, \random_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 2e0724e0a..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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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, \random_int(2, 10)) + \range(1, generate_random_int(2, 10)) ), 'list_of_string' => \array_map( static fn ($i) => $faker->text(10), - \range(1, \random_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 449b77ed9..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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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-' . bin2hex(random_bytes(16)) . '.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 901a91f2c..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 = \random_int(10, 1000); + $maxValues = generate_random_int(10, 1000); for ($i = 0; $i < $maxValues; $i++) { - $values[] = \random_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 249a12f72..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}; @@ -58,7 +59,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[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 f91034de1..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(\random_int(10, 1000)); + $string = Factory::create()->text(generate_random_int(10, 1000)); self::assertSame( $string,