<?php
declare(strict_types=1);
final class ActionLoggerTest extends PHPUnit\Framework\TestCase {
public function testActionStart() {
$process = new \Common\ActionLogger();
$process->action_start('first_action');
$process->action_start('second_action');
$this->assertEquals(count($process->actions()), 2, 'add_action should add an action');
$this->assertEquals(($process->actions())[0]['result'], 'success', 'starting a new actions should mark the last action as successful');
}
public function testActionEnd() {
$process = new \Common\ActionLogger();
$process->action_start('Unpredictable action');
$exception = new Exception('The error of all errors!');
try {
throw $exception;
$process->action_end();
}
catch (\Exception $e) {
$process->action_end(false, $e);
}
$this->assertEquals(($process->actions())[0]['result'], 'fail', 'ending an action w/ failure key should mark the action as failed');
$this->assertEquals(['error' => 'The error of all errors!'], ($process->actions())[0]['details'], 'errors should be marked in details');
}
}
?>