94 lines
2.3 KiB
PHP
94 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Domain\Models\ValueObjects;
|
|
|
|
use Domain\Models\ValueObjects\ImportRowResult;
|
|
|
|
describe('ImportRowResult', function () {
|
|
|
|
function getNewImportRowResult(array $overrides = []): ImportRowResult
|
|
{
|
|
$data = array_merge([
|
|
'lineNumber' => 1,
|
|
'mappedResult' => ['data' => 'value'],
|
|
'error' => null,
|
|
], $overrides);
|
|
|
|
return new ImportRowResult(...$data);
|
|
}
|
|
|
|
it('can instantiate for success', function () {
|
|
// GIVEN
|
|
$lineNumber = 1;
|
|
$mappedResult = 'data';
|
|
$error = null;
|
|
|
|
// WHEN
|
|
$vo = new ImportRowResult(
|
|
lineNumber: $lineNumber,
|
|
mappedResult: $mappedResult,
|
|
error: $error
|
|
);
|
|
|
|
// THEN
|
|
expect($vo)->toBeInstanceOf(ImportRowResult::class);
|
|
expect($vo->isSuccess())->toBeTrue();
|
|
});
|
|
|
|
it('can instantiate for error', function () {
|
|
// GIVEN
|
|
$lineNumber = 1;
|
|
$mappedResult = null;
|
|
$error = 'Invalid format';
|
|
|
|
// WHEN
|
|
$vo = new ImportRowResult(
|
|
lineNumber: $lineNumber,
|
|
mappedResult: $mappedResult,
|
|
error: $error
|
|
);
|
|
|
|
// THEN
|
|
expect($vo)->toBeInstanceOf(ImportRowResult::class);
|
|
expect($vo->isSuccess())->toBeFalse();
|
|
});
|
|
|
|
it('throws exception if line number is zero or negative', function () {
|
|
// GIVEN
|
|
$lineNumber = 0;
|
|
$mappedResult = 'data';
|
|
|
|
// WHEN
|
|
$action = fn () => new ImportRowResult(
|
|
lineNumber: $lineNumber,
|
|
mappedResult: $mappedResult
|
|
);
|
|
|
|
// THEN
|
|
expect($action)->toThrow(\DomainException::class);
|
|
});
|
|
|
|
it('is not success if mappedResult is null', function () {
|
|
// GIVEN
|
|
$overrides = ['mappedResult' => null];
|
|
|
|
// WHEN
|
|
$vo = getNewImportRowResult($overrides);
|
|
|
|
// THEN
|
|
expect($vo->isSuccess())->toBeFalse();
|
|
});
|
|
|
|
it('is not success if error is present', function () {
|
|
// GIVEN
|
|
$overrides = ['error' => 'some error'];
|
|
|
|
// WHEN
|
|
$vo = getNewImportRowResult($overrides);
|
|
|
|
// THEN
|
|
expect($vo->isSuccess())->toBeFalse();
|
|
});
|
|
});
|