Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: Improve coverage #18

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)),
);
});
Loading