From debecd5e9ff4914728bb6b15e373a284702c608f Mon Sep 17 00:00:00 2001 From: Beno!t POLASZEK Date: Wed, 8 Nov 2023 10:50:14 +0100 Subject: [PATCH] tests: improve coverage --- composer.json | 1 + phpstan.dist.neon | 4 +++ src/Recipe/LoggerRecipe.php | 3 -- tests/Unit/Recipe/LoggerRecipeTest.php | 41 ++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 tests/Unit/Recipe/LoggerRecipeTest.php diff --git a/composer.json b/composer.json index b591dcd..279ecc5 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,7 @@ "doctrine/orm": "^2.16", "friendsofphp/php-cs-fixer": "^3.35", "mockery/mockery": "^1.6", + "monolog/monolog": "^3.5", "pestphp/pest": "^2.24", "phpstan/phpstan": "^1.10", "phpstan/phpstan-mockery": "^1.1", diff --git a/phpstan.dist.neon b/phpstan.dist.neon index b76d47f..bce5a27 100644 --- a/phpstan.dist.neon +++ b/phpstan.dist.neon @@ -3,5 +3,9 @@ parameters: paths: - src/ - tests/ + ignoreErrors: + - + message: "#Access to an undefined property#" + path: "tests/Unit/Recipe/LoggerRecipeTest.php" includes: - vendor/phpstan/phpstan-mockery/extension.neon diff --git a/src/Recipe/LoggerRecipe.php b/src/Recipe/LoggerRecipe.php index a8f0c14..ffaf1da 100644 --- a/src/Recipe/LoggerRecipe.php +++ b/src/Recipe/LoggerRecipe.php @@ -22,9 +22,6 @@ use Psr\Log\NullLogger; use Stringable; -/** - * @codeCoverageIgnore - */ final class LoggerRecipe extends Recipe { /** diff --git a/tests/Unit/Recipe/LoggerRecipeTest.php b/tests/Unit/Recipe/LoggerRecipeTest.php new file mode 100644 index 0000000..c050ecf --- /dev/null +++ b/tests/Unit/Recipe/LoggerRecipeTest.php @@ -0,0 +1,41 @@ +withRecipe($loggerRecipe); + + // When + $executor->process(['foo', 'bar']); + + // Then + $records = $handler->getRecords(); + expect($records)->toHaveCount(12)->and($records)->sequence( + fn ($record) => $record->message->toEqual('Initializing ETL...')->and($record->level->toBe(Level::Debug)), + fn ($record) => $record->message->toEqual('Starting ETL...')->and($record->level->toBe(Level::Info)), + fn ($record) => $record->message->toContain('Extracting item')->and($record->level->toBe(Level::Debug)), + fn ($record) => $record->message->toContain('Transformed item')->and($record->level->toBe(Level::Debug)), + fn ($record) => $record->message->toContain('Loaded item')->and($record->level->toBe(Level::Debug)), + fn ($record) => $record->message->toContain('Flushing items (partial)...')->and($record->level->toBe(Level::Info)), + fn ($record) => $record->message->toContain('Extracting item')->and($record->level->toBe(Level::Debug)), + fn ($record) => $record->message->toContain('Transformed item')->and($record->level->toBe(Level::Debug)), + fn ($record) => $record->message->toContain('Loaded item')->and($record->level->toBe(Level::Debug)), + fn ($record) => $record->message->toContain('Flushing items (partial)...')->and($record->level->toBe(Level::Info)), + fn ($record) => $record->message->toContain('Flushing items...')->and($record->level->toBe(Level::Info)), + fn ($record) => $record->message->toContain('ETL complete.')->and($record->level->toBe(Level::Info)), + ); +});