From 30297d2806e28366d3ad02c2c2814b2ca085dc08 Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Mon, 1 Jul 2024 20:05:31 +0200 Subject: [PATCH] chore: Replace `uniqid` with guarantee uniqueness (#1102) --- .../Adapter/CSV/Tests/Integration/CSVTest.php | 4 +- .../ElasticsearchLoaderTest.php | 8 +-- .../Tests/Integration/FlysystemFSTest.php | 2 +- .../JSON/Tests/Integration/JsonTest.php | 4 +- .../MeilisearchPHP/MeilisearchLoaderTest.php | 8 +-- .../Text/Tests/Integration/TextTest.php | 2 +- src/core/etl/src/Flow/ETL/ConfigBuilder.php | 2 +- src/core/etl/src/Flow/ETL/Filesystem/Path.php | 4 +- .../Integration/Cache/PSRSimpleCacheTest.php | 2 +- .../DataFrame/PartitioningTest.php | 2 +- .../Filesystem/LocalFilesystemTest.php | 2 +- .../Tests/Integration/IO/CompressionTest.php | 6 +-- .../Tests/Integration/IO/ListsWritingTest.php | 14 +++--- .../Tests/Integration/IO/MapsWritingTest.php | 6 +-- .../Integration/IO/SimpleTypesWritingTest.php | 50 +++++++++---------- .../Integration/IO/StructsWritingTest.php | 6 +-- .../Tests/Integration/IO/WriterTest.php | 28 +++++------ .../Integration/IO/WriterValidatorTest.php | 18 +++---- 18 files changed, 84 insertions(+), 84 deletions(-) diff --git a/src/adapter/etl-adapter-csv/tests/Flow/ETL/Adapter/CSV/Tests/Integration/CSVTest.php b/src/adapter/etl-adapter-csv/tests/Flow/ETL/Adapter/CSV/Tests/Integration/CSVTest.php index 76220bc11..e93a477a7 100644 --- a/src/adapter/etl-adapter-csv/tests/Flow/ETL/Adapter/CSV/Tests/Integration/CSVTest.php +++ b/src/adapter/etl-adapter-csv/tests/Flow/ETL/Adapter/CSV/Tests/Integration/CSVTest.php @@ -15,7 +15,7 @@ final class CSVTest extends TestCase { public function test_loading_array_entry() : void { - $path = \sys_get_temp_dir() . '/' . \uniqid('flow_php_etl_csv_loader', true) . '.csv'; + $path = \sys_get_temp_dir() . '/flow_php_etl_csv_loader' . bin2hex(random_bytes(16)) . '.csv'; if (\file_exists($path)) { \unlink($path); @@ -31,7 +31,7 @@ public function test_loading_array_entry() : void public function test_loading_csv_files() : void { - $path = \sys_get_temp_dir() . '/' . \uniqid('flow_php_etl_csv_loader', true) . '.csv'; + $path = \sys_get_temp_dir() . '/flow_php_etl_csv_loader' . bin2hex(random_bytes(16)) . '.csv'; if (\file_exists($path)) { \unlink($path); 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 344c22d97..fd092199b 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(\uniqid('id', true))), + new Row\Entry\StringEntry('id', \sha1('id' . bin2hex(random_bytes(16)))), new Row\Entry\StringEntry('name', 'Łukasz') ), Row::create( - new Row\Entry\StringEntry('id', \sha1(\uniqid('id', true))), + new Row\Entry\StringEntry('id', \sha1('id' . bin2hex(random_bytes(16)))), new Row\Entry\StringEntry('name', 'Norbert') ), Row::create( - new Row\Entry\StringEntry('id', \sha1(\uniqid('id', true))), + new Row\Entry\StringEntry('id', \sha1('id' . bin2hex(random_bytes(16)))), new Row\Entry\StringEntry('name', 'Dawid') ), Row::create( - new Row\Entry\StringEntry('id', \sha1(\uniqid('id', true))), + new Row\Entry\StringEntry('id', \sha1('id' . bin2hex(random_bytes(16)))), new Row\Entry\StringEntry('name', 'Tomek') ), ), new FlowContext(Config::default())); diff --git a/src/adapter/etl-adapter-filesystem/tests/Flow/ETL/Adapter/Filesystem/Tests/Integration/FlysystemFSTest.php b/src/adapter/etl-adapter-filesystem/tests/Flow/ETL/Adapter/Filesystem/Tests/Integration/FlysystemFSTest.php index 433e0e9eb..4329dd0dc 100644 --- a/src/adapter/etl-adapter-filesystem/tests/Flow/ETL/Adapter/Filesystem/Tests/Integration/FlysystemFSTest.php +++ b/src/adapter/etl-adapter-filesystem/tests/Flow/ETL/Adapter/Filesystem/Tests/Integration/FlysystemFSTest.php @@ -70,7 +70,7 @@ public function test_open_file_stream_for_existing_file() : void public function test_open_file_stream_for_non_existing_file() : void { - $path = \sys_get_temp_dir() . '/' . \uniqid('flow_php_test_file_', true) . '.txt'; + $path = \sys_get_temp_dir() . '/flow_php_test_file_' . bin2hex(random_bytes(16)) . '.txt'; $stream = (new FlysystemFS())->open(new Path($path), Mode::WRITE); diff --git a/src/adapter/etl-adapter-json/tests/Flow/ETL/Adapter/JSON/Tests/Integration/JsonTest.php b/src/adapter/etl-adapter-json/tests/Flow/ETL/Adapter/JSON/Tests/Integration/JsonTest.php index dcc4fb0d1..0edf07a2e 100644 --- a/src/adapter/etl-adapter-json/tests/Flow/ETL/Adapter/JSON/Tests/Integration/JsonTest.php +++ b/src/adapter/etl-adapter-json/tests/Flow/ETL/Adapter/JSON/Tests/Integration/JsonTest.php @@ -17,7 +17,7 @@ final class JsonTest extends TestCase { public function test_json_loader() : void { - $path = \sys_get_temp_dir() . '/' . \uniqid('flow_php_etl_json_loader', true) . '.json'; + $path = \sys_get_temp_dir() . '/flow_php_etl_json_loader' . bin2hex(random_bytes(16)) . '.json'; if (\file_exists($path)) { \unlink($path); @@ -40,7 +40,7 @@ public function test_json_loader() : void public function test_json_loader_loading_empty_string() : void { - $stream = \sys_get_temp_dir() . '/' . \uniqid('flow_php_etl_json_loader', true) . '.json'; + $stream = \sys_get_temp_dir() . '/flow_php_etl_json_loader' . bin2hex(random_bytes(16)) . '.json'; $loader = new JsonLoader(Path::realpath($stream)); 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 71f26325b..b7c69f85a 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(\uniqid('id', true))), + new Row\Entry\StringEntry('id', \sha1('id' . bin2hex(random_bytes(16)))), new Row\Entry\StringEntry('name', 'Łukasz') ), Row::create( - new Row\Entry\StringEntry('id', \sha1(\uniqid('id', true))), + new Row\Entry\StringEntry('id', \sha1('id' . bin2hex(random_bytes(16)))), new Row\Entry\StringEntry('name', 'Norbert') ), Row::create( - new Row\Entry\StringEntry('id', \sha1(\uniqid('id', true))), + new Row\Entry\StringEntry('id', \sha1('id' . bin2hex(random_bytes(16)))), new Row\Entry\StringEntry('name', 'Dawid') ), Row::create( - new Row\Entry\StringEntry('id', \sha1(\uniqid('id', true))), + new Row\Entry\StringEntry('id', \sha1('id' . bin2hex(random_bytes(16)))), 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 feafce261..2ff65bbb6 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 = \sys_get_temp_dir() . '/' . \uniqid('flow_php_etl_csv_loader', true) . '.csv'; + $path = \sys_get_temp_dir() . '/flow_php_etl_csv_loader' . bin2hex(random_bytes(16)) . '.csv'; (new Flow()) ->process( diff --git a/src/core/etl/src/Flow/ETL/ConfigBuilder.php b/src/core/etl/src/Flow/ETL/ConfigBuilder.php index ad0c5c136..f656e90d0 100644 --- a/src/core/etl/src/Flow/ETL/ConfigBuilder.php +++ b/src/core/etl/src/Flow/ETL/ConfigBuilder.php @@ -54,7 +54,7 @@ public function __construct() */ public function build() : Config { - $this->id ??= \uniqid('flow_php', true); + $this->id ??= 'flow_php' . bin2hex(random_bytes(16)); $entryFactory = new NativeEntryFactory(); $this->serializer ??= new Base64Serializer(new NativePHPSerializer()); $cachePath = \is_string(\getenv(Config::CACHE_DIR_ENV)) && \realpath(\getenv(Config::CACHE_DIR_ENV)) diff --git a/src/core/etl/src/Flow/ETL/Filesystem/Path.php b/src/core/etl/src/Flow/ETL/Filesystem/Path.php index 946d1fd33..2ffee0ce8 100644 --- a/src/core/etl/src/Flow/ETL/Filesystem/Path.php +++ b/src/core/etl/src/Flow/ETL/Filesystem/Path.php @@ -143,7 +143,7 @@ public static function realpath(string $path, array $options = []) : self public static function tmpFile(string $extension, ?string $name = null) : self { - $name = \ltrim($name ?? \str_replace('.', '', \uniqid('', true)), '/'); + $name = \ltrim($name ?? bin2hex(random_bytes(16)), '/'); return new self(\sys_get_temp_dir() . DIRECTORY_SEPARATOR . $name . '.' . $extension); } @@ -302,7 +302,7 @@ public function randomize() : self $base = \trim(\mb_substr($this->path(), 0, \mb_strrpos($this->path(), $this->basename())), DIRECTORY_SEPARATOR); return new self( - $this->scheme . '://' . $base . DIRECTORY_SEPARATOR . $this->filename . '_' . \str_replace('.', '', \uniqid('', true)) . $extension, + $this->scheme . '://' . $base . DIRECTORY_SEPARATOR . $this->filename . '_' . bin2hex(random_bytes(16)) . $extension, $this->options ); } 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 index fb7988a9b..1be1d52b5 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Cache/PSRSimpleCacheTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Cache/PSRSimpleCacheTest.php @@ -17,7 +17,7 @@ public function test_saving_to_psr_simple_cache_implementation() : void { $cache = new PSRSimpleCache( new Psr16Cache( - new FilesystemAdapter(directory: \sys_get_temp_dir() . '/' . \uniqid('flow-etl-cache-', true)) + new FilesystemAdapter(directory: \sys_get_temp_dir() . '/flow-etl-cache-' . bin2hex(random_bytes(16))) ), ); 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 c595cdb87..20780f6d6 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 @@ -166,7 +166,7 @@ function (int $i) : array { for ($d = 0; $d < $maxItems; $d++) { $data[] = [ - 'id' => \uniqid('', true), + '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), ]; diff --git a/src/core/etl/tests/Flow/ETL/Tests/Integration/Filesystem/LocalFilesystemTest.php b/src/core/etl/tests/Flow/ETL/Tests/Integration/Filesystem/LocalFilesystemTest.php index c705caf65..843a6d84e 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Integration/Filesystem/LocalFilesystemTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Integration/Filesystem/LocalFilesystemTest.php @@ -69,7 +69,7 @@ public function test_open_file_stream_for_existing_file() : void public function test_open_file_stream_for_non_existing_file() : void { - $path = \sys_get_temp_dir() . '/' . \uniqid('flow_php_test_file_', true) . '.txt'; + $path = \sys_get_temp_dir() . '/flow_php_test_file_' . bin2hex(random_bytes(16)) . '.txt'; $stream = (new LocalFilesystem())->open(new Path($path), Mode::WRITE); 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 2dc8567c6..d4de8ee4b 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 @@ -14,7 +14,7 @@ final class CompressionTest extends TestCase { public function test_writing_and_reading_file_with_gzip_compression() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(Compressions::GZIP); @@ -61,7 +61,7 @@ public function test_writing_and_reading_file_with_gzip_compression() : void public function test_writing_and_reading_file_with_snappy_compression() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(Compressions::SNAPPY); @@ -108,7 +108,7 @@ public function test_writing_and_reading_file_with_snappy_compression() : void public function test_writing_and_reading_file_with_uncompressed_compression() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(Compressions::UNCOMPRESSED); 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 b3eab56f3..2ea96e22d 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 @@ -14,7 +14,7 @@ final class ListsWritingTest extends TestCase { public function test_writing_list_of_ints() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::list('list_of_ints', ListElement::int32())); @@ -38,7 +38,7 @@ public function test_writing_list_of_ints() : void public function test_writing_list_of_strings() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::list('list_of_strings', ListElement::string())); @@ -62,7 +62,7 @@ public function test_writing_list_of_strings() : void public function test_writing_list_of_structures() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with( @@ -96,7 +96,7 @@ public function test_writing_list_of_structures() : void public function test_writing_list_with_nullable_elements() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::list('list_of_ints', ListElement::int32())); @@ -122,7 +122,7 @@ public function test_writing_list_with_nullable_elements() : void public function test_writing_list_with_nullable_list_values() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::list('list_of_ints', ListElement::int32())); @@ -148,7 +148,7 @@ public function test_writing_list_with_nullable_list_values() : void public function test_writing_nullable_list_of_ints() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::list('list_of_ints', ListElement::int32())); @@ -174,7 +174,7 @@ public function test_writing_nullable_list_of_ints() : void public function test_writing_nullable_list_of_structures() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with( 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 738c072f1..b2d1d3908 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 @@ -14,7 +14,7 @@ final class MapsWritingTest extends TestCase { public function test_writing_map_of_int_int() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::map('map_int_int', MapKey::int32(), MapValue::int32())); @@ -43,7 +43,7 @@ public function test_writing_map_of_int_int() : void public function test_writing_map_of_int_string() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::map('map_int_string', MapKey::int32(), MapValue::string())); @@ -72,7 +72,7 @@ public function test_writing_map_of_int_string() : void public function test_writing_nullable_map_of_int_int() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::map('map_int_int', MapKey::int32(), MapValue::int32())); 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 83cfa9afc..426a7160a 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 @@ -14,7 +14,7 @@ final class SimpleTypesWritingTest extends TestCase { public function test_writing_bool_column() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::boolean('boolean')); @@ -40,7 +40,7 @@ public function test_writing_bool_column() : void public function test_writing_bool_nullable_column() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::boolean('boolean')); @@ -66,7 +66,7 @@ public function test_writing_bool_nullable_column() : void public function test_writing_date_column() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::date('date')); @@ -94,7 +94,7 @@ public function test_writing_date_column() : void public function test_writing_date_nullable_column() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::date('date')); @@ -122,7 +122,7 @@ public function test_writing_date_nullable_column() : void public function test_writing_decimal_column() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::decimal('decimal')); @@ -150,7 +150,7 @@ public function test_writing_decimal_column() : void public function test_writing_decimal_nullable_column() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::decimal('decimal')); @@ -178,7 +178,7 @@ public function test_writing_decimal_nullable_column() : void public function test_writing_double_column() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::double('double')); @@ -206,7 +206,7 @@ public function test_writing_double_column() : void public function test_writing_double_nullable_column() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::double('double')); @@ -234,7 +234,7 @@ public function test_writing_double_nullable_column() : void public function test_writing_enum_column() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::enum('enum')); @@ -262,7 +262,7 @@ public function test_writing_enum_column() : void public function test_writing_float_column() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::float('float')); @@ -288,7 +288,7 @@ public function test_writing_float_column() : void public function test_writing_float_nullable_column() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::float('float')); @@ -314,7 +314,7 @@ public function test_writing_float_nullable_column() : void public function test_writing_int32_column() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::int32('int32')); @@ -342,7 +342,7 @@ public function test_writing_int32_column() : void public function test_writing_int32_nullable_column() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::int32('int32')); @@ -370,7 +370,7 @@ public function test_writing_int32_nullable_column() : void public function test_writing_int64() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::int64('int64')); @@ -397,7 +397,7 @@ public function test_writing_int64() : void public function test_writing_int64_nullable_column() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::int64('int64')); @@ -424,7 +424,7 @@ public function test_writing_int64_nullable_column() : void public function test_writing_json_column() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::json('json')); @@ -451,7 +451,7 @@ public function test_writing_json_column() : void public function test_writing_json_nullable_column() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::json('json')); @@ -480,7 +480,7 @@ public function test_writing_json_nullable_column() : void public function test_writing_string_column() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::string('string')); @@ -507,7 +507,7 @@ public function test_writing_string_column() : void public function test_writing_string_nullable_column() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::string('string')); @@ -534,7 +534,7 @@ public function test_writing_string_nullable_column() : void public function test_writing_time_column() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::time('time')); @@ -559,7 +559,7 @@ public function test_writing_time_column() : void public function test_writing_time_nullable_column() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::time('time')); @@ -584,7 +584,7 @@ public function test_writing_time_nullable_column() : void public function test_writing_timestamp_column() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::dateTime('dateTime')); @@ -611,7 +611,7 @@ public function test_writing_timestamp_column() : void public function test_writing_timestamp_nullable_column() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::dateTime('dateTime')); @@ -638,7 +638,7 @@ public function test_writing_timestamp_nullable_column() : void public function test_writing_uuid_column() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(FlatColumn::uuid('uuid')); @@ -665,7 +665,7 @@ public function test_writing_uuid_column() : void public function test_writing_uuid_nullable_column() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.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 8bcb5d881..11ea0a116 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 @@ -14,7 +14,7 @@ final class StructsWritingTest extends TestCase { public function test_writing_flat_nullable_structure() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::struct('struct', [ @@ -60,7 +60,7 @@ public function test_writing_flat_nullable_structure() : void public function test_writing_flat_structure() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::struct('struct', [ @@ -104,7 +104,7 @@ public function test_writing_flat_structure() : void public function test_writing_flat_structure_with_nullable_elements() : void { - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $writer = new Writer(); $schema = Schema::with(NestedColumn::struct('struct', [ 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 cb1ae1afa..edccf722d 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 @@ -18,7 +18,7 @@ public function test_appending_to_file() : void { $writer = new Writer(); - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $schema = $this->createSchema(); $row = $this->createRow(); @@ -39,7 +39,7 @@ public function test_appending_to_in_batches_file() : void { $writer = new Writer(); - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $schema = $this->createSchema(); $row = $this->createRow(); @@ -66,7 +66,7 @@ public function test_appending_to_stream() : void { $writer = new Writer(); - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $schema = $this->createSchema(); $row = $this->createRow(); @@ -101,7 +101,7 @@ public function test_created_by_metadata() : void { $writer = new Writer(); - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $schema = $this->createSchema(); $writer->open($path, $schema); @@ -116,7 +116,7 @@ public function test_opening_already_open_writer() : void { $writer = new Writer(); - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $schema = $this->createSchema(); @@ -145,7 +145,7 @@ public function test_writing_batch_to_not_writable_stream() : void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Given stream is not opened in write mode, expected wb, got: rb+'); - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; \file_put_contents($path, 'test'); $stream = \fopen($path, 'rb+'); @@ -161,7 +161,7 @@ public function test_writing_column_statistics() : void ->set(Option::WRITER_VERSION, 1) ); - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-v2-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-v2-' . bin2hex(random_bytes(16)) . '.parquet'; $schema = Schema::with($column = FlatColumn::int32('int32')); @@ -190,7 +190,7 @@ public function test_writing_data_page_v2_statistics() : void ->set(Option::WRITER_VERSION, 2) ); - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-v2-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-v2-' . bin2hex(random_bytes(16)) . '.parquet'; $schema = Schema::with($column = FlatColumn::int32('int32')); @@ -217,7 +217,7 @@ public function test_writing_in_batches_to_file() : void { $writer = new Writer(); - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $schema = $this->createSchema(); @@ -244,7 +244,7 @@ public function test_writing_in_batches_to_file_without_explicit_close() : void { $writer = new Writer(); - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $schema = $this->createSchema(); @@ -270,7 +270,7 @@ public function test_writing_in_batches_to_stream() : void { $writer = new Writer(); - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $schema = $this->createSchema(); @@ -308,7 +308,7 @@ public function test_writing_to_file() : void { $writer = new Writer(); - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $schema = $this->createSchema(); $row = $this->createRow(); @@ -330,7 +330,7 @@ public function test_writing_to_file_v2() : void ->set(Option::WRITER_VERSION, 2) ); - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-v2-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-v2-' . bin2hex(random_bytes(16)) . '.parquet'; $schema = $this->createSchema(); $row = $this->createRow(); @@ -350,7 +350,7 @@ public function test_writing_to_stream() : void { $writer = new Writer(); - $path = \sys_get_temp_dir() . '/test-writer' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $schema = $this->createSchema(); $row = $this->createRow(); 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 59d5d66cb..215e6495e 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 @@ -15,7 +15,7 @@ public function test_skipping_required_row() : void $this->expectExceptionMessage('Column "string" is required'); $writer = new Writer(); - $path = \sys_get_temp_dir() . '/test-writer-validator' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-validator-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $schema = Schema::with( Schema\FlatColumn::int32('id'), @@ -30,7 +30,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 = \sys_get_temp_dir() . '/test-writer-validator' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-validator-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $schema = Schema::with(Schema\FlatColumn::string('string')); @@ -42,7 +42,7 @@ public function test_writing_null_to_list_that_is_required() : void $this->expectExceptionMessage('Column "list" is required'); $writer = new Writer(); - $path = \sys_get_temp_dir() . '/test-writer-validator' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-validator-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $schema = Schema::with(Schema\NestedColumn::list('list', Schema\ListElement::string())->makeRequired()); @@ -54,7 +54,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 = \sys_get_temp_dir() . '/test-writer-validator' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-validator-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $schema = Schema::with(Schema\NestedColumn::list('list', Schema\ListElement::string(required: true))); @@ -66,7 +66,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 = \sys_get_temp_dir() . '/test-writer-validator' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-validator-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $schema = Schema::with(Schema\NestedColumn::map('map', Schema\MapKey::string(), Schema\MapValue::string(required: true))); @@ -78,7 +78,7 @@ public function test_writing_null_to_required_map() : void $this->expectExceptionMessage('Column "map" is required'); $writer = new Writer(); - $path = \sys_get_temp_dir() . '/test-writer-validator' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-validator-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $schema = Schema::with(Schema\NestedColumn::map('map', Schema\MapKey::string(), Schema\MapValue::string())->makeRequired()); @@ -90,7 +90,7 @@ public function test_writing_null_value_to_required_column() : void $this->expectExceptionMessage('Column "string" is required'); $writer = new Writer(); - $path = \sys_get_temp_dir() . '/test-writer-validator' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-validator-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $schema = Schema::with(Schema\FlatColumn::string('string')->makeRequired()); @@ -100,7 +100,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 = \sys_get_temp_dir() . '/test-writer-validator' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-validator-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $schema = Schema::with( Schema\FlatColumn::int32('id'), @@ -134,7 +134,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 = \sys_get_temp_dir() . '/test-writer-validator' . \uniqid('parquet-test-', true) . '.parquet'; + $path = \sys_get_temp_dir() . '/test-writer-validator-parquet-test-' . bin2hex(random_bytes(16)) . '.parquet'; $schema = Schema::with( Schema\FlatColumn::int32('id'),