Skip to content

Commit

Permalink
Run PHPStan for the test suite (#1329)
Browse files Browse the repository at this point in the history
* Run PHPStan with baseline for tests

* Add new commands

* Run PHPStan for tests in PRs

* Double-dash seems to be commited by mistake

* Run static analysis of tests in parallel with the other actions

* Update baseline after latest changes in main branch

* Generate baseline using the same php version that the Github action runs on

* Unify PHPStan for source and PHPStan for test suite

* Double dash tells composer to pass arguments to script

* Remove old config files

* ElasticSearch Adapter tests require the library itself

* Fix FakeExtractor

* Fix ScalarFunctionTransformerTest

* Fix MetadataTest

* Fix UuidEntryTest

* Fix LimitOptimizationTest

* Fix BatchSizeOptimizationTest

* Fix BatchSizeOptimizationTest

* Fix TypeDetectorTest

* Fix XPathTest

* Fix TypeDetectorTest

* Fix DOMElementValueTest

* Fix DOMElementAttributesCountTest

* Fix DOMElementAttributeValueTest

* Fix CasterTest

* Fix AnalyzeTest

* Fix FlowIntegrationTestCase

* Fix Example

* Fix TypedOptionTest

* Fix FlowStreamedResponseTest

* Fix AzureBlobServiceTestCase

* Fix AzureBlobFilesystemTest

* Fix AzureBlobDestinationStreamTest

* Fix AsyncAWSS3FilesystemTest

* Fix AsyncAWSS3FilesystemTest

* Fix AzureBlobDestinationStreamTest

* Fix AsyncAWSS3DestinationStreamTest

* Fix AsyncAWSS3DestinationStreamTest

* Fix PHPValueNormalizerTest

* Fix ParquetTest

* Fix ParquetExtractorTest

* Fix InsertQueryCounter

* Remove baseline import

* Include vendor autoload

* All errors have been fixed

* Baseline command is unused

* Fix style issues
  • Loading branch information
Bellangelo authored Jan 8, 2025
1 parent e67c3f4 commit 2bb79f5
Show file tree
Hide file tree
Showing 27 changed files with 137 additions and 82 deletions.
22 changes: 22 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ parameters:
ignoreErrors:
- identifier: argument.type
- identifier: missingType.iterableValue
bootstrapFiles:
- tools/phpunit/vendor/autoload.php
- tools/phpbench/vendor/autoload.php
- vendor/autoload.php
paths:
- src/core/etl/src
- src/cli/src
Expand Down Expand Up @@ -34,6 +38,24 @@ parameters:
- src/lib/snappy/src
- examples/topics
- src/tools/documentation/src
- src/core/etl/tests
- src/cli/tests
- src/adapter/etl-adapter-avro/tests
- src/adapter/etl-adapter-chartjs/tests
- src/adapter/etl-adapter-csv/tests
- src/adapter/etl-adapter-doctrine/tests
- src/adapter/etl-adapter-google-sheet/tests
- src/adapter/etl-adapter-http/tests
- src/adapter/etl-adapter-json/tests
- src/adapter/etl-adapter-logger/tests
- src/adapter/etl-adapter-meilisearch/tests
- src/adapter/etl-adapter-parquet/tests
- src/adapter/etl-adapter-text/tests
- src/adapter/etl-adapter-xml/tests
- src/bridge/filesystem/async-aws/tests
- src/bridge/filesystem/azure/tests
- src/bridge/monolog/http/tests
- src/bridge/symfony/http-foundation/tests

excludePaths:
- src/cli/src/Flow/CLI/Command/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __construct()
$this->logger = new NullLogger();
}

public function log($level, $message, array $context = []) : void
public function log(mixed $level, string|\Stringable $message, array $context = []) : void
{
if (!isset($context['sql'])) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
use Flow\ETL\Extractor\Signal;
use Flow\ETL\{Tests\FlowTestCase};
use Flow\Filesystem\Path;
use Flow\Parquet\{Options, Reader};
use Flow\Parquet\{Reader};

final class ParquetExtractorTest extends FlowTestCase
{
public function test_limit() : void
{
$extractor = new ParquetExtractor(\Flow\Filesystem\DSL\path(__DIR__ . '/Fixtures/orders_1k.parquet'), Options::default());
$extractor = new ParquetExtractor(\Flow\Filesystem\DSL\path(__DIR__ . '/Fixtures/orders_1k.parquet'));
$extractor->changeLimit(2);

self::assertCount(
Expand All @@ -40,7 +40,7 @@ public function test_reading_file_from_given_offset() : void

public function test_signal_stop() : void
{
$extractor = new ParquetExtractor(\Flow\Filesystem\DSL\path(__DIR__ . '/Fixtures/orders_1k.parquet'), Options::default());
$extractor = new ParquetExtractor(\Flow\Filesystem\DSL\path(__DIR__ . '/Fixtures/orders_1k.parquet'));

$generator = $extractor->extract(flow_context(config()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public function test_writing_with_provided_schema() : void
private function cleanDirectory(string $path) : void
{
if (\file_exists($path) && \is_dir($path)) {
$files = \array_values(\array_diff(\scandir($path), ['..', '.']));

$files = \array_diff(\scandir($path), ['..', '.']);

foreach ($files as $file) {
if (\is_file($path . DIRECTORY_SEPARATOR . $file)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public function test_normalizing_object_type() : void
{
self::markTestSkipped('We need to figure out what to do with object types');

/** @phpstan-ignore-next-line */
$normalizer = new PHPValueNormalizer(Caster::default());

self::assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function test_writing_content_from_resource() : void
$stream->fromResource(\fopen(__DIR__ . '/Fixtures/orders.csv', 'rb'));
$stream->close();

self::assertTrue($fs->status(path('aws-s3://orders.csv'))->isFile());
self::assertTrue($fs->status(path('aws-s3://orders.csv'))?->isFile());
self::assertFalse($fs->status(path('aws-s3://orders.csv'))->isDirectory());
self::assertSame(\file_get_contents(__DIR__ . '/Fixtures/orders.csv'), $fs->readFrom(path('aws-s3://orders.csv'))->content());

Expand All @@ -41,7 +41,7 @@ public function test_writing_content_smaller_than_block_size_to_s3() : void
$stream->append('Hello, World!');
$stream->close();

self::assertTrue($fs->status(path('aws-s3://file.txt'))->isFile());
self::assertTrue($fs->status(path('aws-s3://file.txt'))?->isFile());
self::assertFalse($fs->status(path('aws-s3://file.txt'))->isDirectory());
self::assertSame('Hello, World!', $fs->readFrom(path('aws-s3://file.txt'))->content());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function test_appending_to_existing_5mb_blob() : void
->append("This is second line\n")
->close();

self::assertTrue($fs->status(path('aws-s3://var/file.txt'))->isFile());
self::assertTrue($fs->status(path('aws-s3://var/file.txt'))?->isFile());
self::assertFalse($fs->status(path('aws-s3://var/file.txt'))->isDirectory());

self::assertStringStartsWith(\str_repeat('a', 1024), $fs->readFrom(path('aws-s3://var/file.txt'))->read(1024, 0));
Expand All @@ -43,7 +43,7 @@ public function test_appending_to_existing_blob() : void
->append("This is second line\n")
->close();

self::assertTrue($fs->status(path('aws-s3://var/file.txt'))->isFile());
self::assertTrue($fs->status(path('aws-s3://var/file.txt'))?->isFile());
self::assertFalse($fs->status(path('aws-s3://var/file.txt'))->isDirectory());
self::assertSame(
<<<'TXT'
Expand All @@ -65,7 +65,7 @@ public function test_file_status_on_existing_file() : void
$stream = $fs->writeTo(path('aws-s3://orders.csv'))->fromResource(\fopen(__DIR__ . '/Fixtures/orders.csv', 'rb'));
$stream->close();

self::assertTrue($fs->status(path('aws-s3://orders.csv'))->isFile());
self::assertTrue($fs->status(path('aws-s3://orders.csv'))?->isFile());
}

public function test_file_status_on_existing_folder() : void
Expand All @@ -76,8 +76,8 @@ public function test_file_status_on_existing_folder() : void
->fromResource(\fopen(__DIR__ . '/Fixtures/orders.csv', 'rb'))
->close();

self::assertTrue($fs->status(path('aws-s3://var/nested'))->isDirectory());
self::assertTrue($fs->status(path('aws-s3://var/nested/'))->isDirectory());
self::assertTrue($fs->status(path('aws-s3://var/nested'))?->isDirectory());
self::assertTrue($fs->status(path('aws-s3://var/nested/'))?->isDirectory());
}

public function test_file_status_on_non_existing_file() : void
Expand Down Expand Up @@ -118,7 +118,7 @@ public function test_file_status_on_pattern() : void
$stream = $fs->writeTo(path('aws-s3://var/some_path_to/file.txt'))->fromResource(\fopen(__DIR__ . '/Fixtures/orders.csv', 'rb'));
$stream->close();

self::assertTrue($fs->status(path('aws-s3://var/some_path_to/*.txt'))->isFile());
self::assertTrue($fs->status(path('aws-s3://var/some_path_to/*.txt'))?->isFile());
self::assertSame(
'aws-s3://var/some_path_to/file.txt',
$fs->status(path('aws-s3://var/some_path_to/*.txt'))->path->uri()
Expand All @@ -129,7 +129,7 @@ public function test_file_status_on_root_folder() : void
{
$fs = aws_s3_filesystem($this->bucket(), $this->s3Client());

self::assertTrue($fs->status(path('aws-s3:///'))->isDirectory());
self::assertTrue($fs->status(path('aws-s3:///'))?->isDirectory());
}

public function test_move_blob() : void
Expand All @@ -152,8 +152,8 @@ public function test_not_removing_a_content_when_its_not_a_full_folder_path_patt
$fs->writeTo(path('aws-s3://var/nested/orders/orders.csv'))->fromResource(\fopen(__DIR__ . '/Fixtures/orders.csv', 'rb'))->close();
$fs->writeTo(path('aws-s3://var/nested/orders/orders_01.csv'))->fromResource(\fopen(__DIR__ . '/Fixtures/orders.csv', 'rb'))->close();

self::assertTrue($fs->status(path('aws-s3://var/nested/orders/orders.csv'))->isFile());
self::assertTrue($fs->status(path('aws-s3://var/nested/orders/orders_01.csv'))->isFile());
self::assertTrue($fs->status(path('aws-s3://var/nested/orders/orders.csv'))?->isFile());
self::assertTrue($fs->status(path('aws-s3://var/nested/orders/orders_01.csv'))?->isFile());

self::assertFalse($fs->rm(path('aws-s3://var/nested/orders/ord')));
}
Expand All @@ -166,7 +166,7 @@ public function test_remove_file_when_exists() : void
$stream->append('some data to make file not empty');
$stream->close();

self::assertTrue($fs->status($stream->path())->isFile());
self::assertTrue($fs->status($stream->path())?->isFile());

self::assertTrue($fs->rm($stream->path()));
self::assertNull($fs->status($stream->path()));
Expand All @@ -183,8 +183,8 @@ public function test_remove_pattern() : void
->append('some data to make file not empty')
->close();

self::assertTrue($fs->status(path('aws-s3://var/flow-fs-test-directory/'))->isDirectory());
self::assertTrue($fs->status(path('aws-s3://var/flow-fs-test-directory/remove_file_when_exists.txt'))->isFile());
self::assertTrue($fs->status(path('aws-s3://var/flow-fs-test-directory/'))?->isDirectory());
self::assertTrue($fs->status(path('aws-s3://var/flow-fs-test-directory/remove_file_when_exists.txt'))?->isFile());
$fs->rm(path('aws-s3://var/flow-fs-test-directory/*.txt'));
self::assertTrue($fs->status(path('aws-s3://var/flow-fs-test-directory/'))->isDirectory());
self::assertNull($fs->status(path('aws-s3://var/flow-fs-test-directory/remove_file_when_exists.txt')));
Expand All @@ -199,12 +199,12 @@ public function test_removing_folder() : void
$fs->writeTo(path('aws-s3://var/nested/orders/orders.csv'))->fromResource(\fopen(__DIR__ . '/Fixtures/orders.csv', 'rb'))->close();
$fs->writeTo(path('aws-s3://var/nested/orders/orders_01.csv'))->fromResource(\fopen(__DIR__ . '/Fixtures/orders.csv', 'rb'))->close();

self::assertTrue($fs->status(path('aws-s3://var/nested/orders/orders.csv'))->isFile());
self::assertTrue($fs->status(path('aws-s3://var/nested/orders/orders_01.csv'))->isFile());
self::assertTrue($fs->status(path('aws-s3://var/nested/orders/orders.csv'))?->isFile());
self::assertTrue($fs->status(path('aws-s3://var/nested/orders/orders_01.csv'))?->isFile());

$fs->rm(path('aws-s3://var/nested/orders'));

self::assertTrue($fs->status(path('aws-s3://var/orders.csv'))->isFile());
self::assertTrue($fs->status(path('aws-s3://var/orders.csv'))?->isFile());
self::assertNull($fs->status(path('aws-s3://var/nested/orders/orders.csv')));
self::assertNull($fs->status(path('aws-s3://var/nested/orders/orders_01.csv')));
}
Expand All @@ -217,12 +217,12 @@ public function test_removing_folder_pattern() : void
$fs->writeTo(path('aws-s3://var/nested/orders/orders.csv'))->fromResource(\fopen(__DIR__ . '/Fixtures/orders.csv', 'rb'))->close();
$fs->writeTo(path('aws-s3://var/nested/orders/orders_01.csv'))->fromResource(\fopen(__DIR__ . '/Fixtures/orders.csv', 'rb'))->close();

self::assertTrue($fs->status(path('aws-s3://var/nested/orders/orders.csv'))->isFile());
self::assertTrue($fs->status(path('aws-s3://var/nested/orders/orders_01.csv'))->isFile());
self::assertTrue($fs->status(path('aws-s3://var/nested/orders/orders.csv'))?->isFile());
self::assertTrue($fs->status(path('aws-s3://var/nested/orders/orders_01.csv'))?->isFile());

$fs->rm(path('aws-s3://var/nested/orders/*.csv'));

self::assertTrue($fs->status(path('aws-s3://var/nested/orders/orders.txt'))->isFile());
self::assertTrue($fs->status(path('aws-s3://var/nested/orders/orders.txt'))?->isFile());
self::assertNull($fs->status(path('aws-s3://var/nested/orders/orders.csv')));
self::assertNull($fs->status(path('aws-s3://var/nested/orders/orders_01.csv')));
}
Expand All @@ -244,7 +244,7 @@ public function test_that_scan_sort_files_by_path_names() : void

$paths = \iterator_to_array($fs->list(path('aws-s3://multi_partitions/**/*.txt')));

self::assertTrue($fs->status(path('aws-s3://multi_partitions/**/*.txt'))->isFile());
self::assertTrue($fs->status(path('aws-s3://multi_partitions/**/*.txt'))?->isFile());

self::assertEquals(
[
Expand Down Expand Up @@ -274,7 +274,7 @@ public function test_tmp_dir_status() : void
{
$fs = aws_s3_filesystem($this->bucket(), $this->s3Client());

self::assertTrue($fs->status($fs->getSystemTmpDir())->isDirectory());
self::assertTrue($fs->status($fs->getSystemTmpDir())?->isDirectory());
}

public function test_write_to_tmp_dir() : void
Expand All @@ -285,7 +285,7 @@ public function test_write_to_tmp_dir() : void
$stream->append('Hello, World!');
$stream->close();

self::assertTrue($fs->status($filePath)->isFile());
self::assertTrue($fs->status($filePath)?->isFile());
self::assertSame('Hello, World!', $fs->readFrom($filePath)->content());

$fs->rm($filePath);
Expand All @@ -308,7 +308,7 @@ public function test_writing_to_aws_s3_storage() : void
$stream->append('Hello, World!');
$stream->close();

self::assertTrue($fs->status(path('aws-s3://file.txt'))->isFile());
self::assertTrue($fs->status(path('aws-s3://file.txt'))?->isFile());
self::assertFalse($fs->status(path('aws-s3://file.txt'))->isDirectory());
self::assertSame('Hello, World!', $fs->readFrom(path('aws-s3://file.txt'))->content());

Expand All @@ -323,7 +323,7 @@ public function test_writing_to_to_aws_s3_from_resources() : void
$stream->fromResource(\fopen(__DIR__ . '/Fixtures/orders.csv', 'rb'));
$stream->close();

self::assertTrue($fs->status(path('aws-s3://orders.csv'))->isFile());
self::assertTrue($fs->status(path('aws-s3://orders.csv'))?->isFile());
self::assertFalse($fs->status(path('aws-s3://orders.csv'))->isDirectory());
self::assertSame(\file_get_contents(__DIR__ . '/Fixtures/orders.csv'), $fs->readFrom(path('aws-s3://orders.csv'))->content());

Expand All @@ -344,7 +344,7 @@ public function test_writing_to_to_s3_using_blocks() : void

$stream->close();

self::assertTrue($fs->status(path('aws-s3://block_blob.csv'))->isFile());
self::assertTrue($fs->status(path('aws-s3://block_blob.csv'))?->isFile());
self::assertFalse($fs->status(path('aws-s3://block_blob.csv'))->isDirectory());

$fs->rm(path('aws-s3://block_blob.csv'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function test_writing_content_bigger_than_block_size_to_azure() : void
$stream->append($content = \str_repeat('a', 200));
$stream->close();

self::assertTrue($fs->status(new Path('azure-blob://file.txt'))->isFile());
self::assertTrue($fs->status(new Path('azure-blob://file.txt'))?->isFile());
self::assertFalse($fs->status(new Path('azure-blob://file.txt'))->isDirectory());
self::assertSame($content, $fs->readFrom(new Path('azure-blob://file.txt'))->content());

Expand All @@ -42,7 +42,7 @@ public function test_writing_content_from_resource() : void
$stream->fromResource(\fopen(__DIR__ . '/Fixtures/orders.csv', 'rb'));
$stream->close();

self::assertTrue($fs->status(new Path('azure-blob://orders.csv'))->isFile());
self::assertTrue($fs->status(new Path('azure-blob://orders.csv'))?->isFile());
self::assertFalse($fs->status(new Path('azure-blob://orders.csv'))->isDirectory());
self::assertSame(\file_get_contents(__DIR__ . '/Fixtures/orders.csv'), $fs->readFrom(new Path('azure-blob://orders.csv'))->content());

Expand All @@ -57,7 +57,7 @@ public function test_writing_content_smaller_than_block_size_to_azure() : void
$stream->append('Hello, World!');
$stream->close();

self::assertTrue($fs->status(new Path('azure-blob://file.txt'))->isFile());
self::assertTrue($fs->status(new Path('azure-blob://file.txt'))?->isFile());
self::assertFalse($fs->status(new Path('azure-blob://file.txt'))->isDirectory());
self::assertSame('Hello, World!', $fs->readFrom(new Path('azure-blob://file.txt'))->content());

Expand Down
Loading

0 comments on commit 2bb79f5

Please sign in to comment.