Skip to content

Commit

Permalink
Tests: Improve coverage (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpolaszek authored Nov 8, 2023
1 parent d0163e2 commit b9c345c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions phpstan.dist.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 0 additions & 3 deletions src/Recipe/LoggerRecipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
use Psr\Log\NullLogger;
use Stringable;

/**
* @codeCoverageIgnore
*/
final class LoggerRecipe extends Recipe
{
/**
Expand Down
41 changes: 41 additions & 0 deletions tests/Unit/Recipe/LoggerRecipeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace BenTools\ETL\Tests\Unit\Recipe;

use Bentools\ETL\EtlConfiguration;
use Bentools\ETL\EtlExecutor;
use Bentools\ETL\Recipe\LoggerRecipe;
use Monolog\Handler\TestHandler;
use Monolog\Level;
use Monolog\Logger;

it('logs messages during ETL process', function () {
// Given
$handler = new TestHandler();
$logger = new Logger('test', [$handler]);
$loggerRecipe = new LoggerRecipe($logger);
$executor = new EtlExecutor(options: new EtlConfiguration(flushEvery: 1));
$executor = $executor->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)),
);
});

0 comments on commit b9c345c

Please sign in to comment.