Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
6dfff1c
add size method
walmir-silva Jul 1, 2024
18284e0
feat: Normalize Interfaces
walmir-silva Jul 1, 2024
21fc7c0
Merge branch 'main' into develop
walmir-silva Jul 1, 2024
132e0ee
Refactor and Normalize Collection Interface and Implementation
walmir-silva Jul 1, 2024
1124a8a
Merge branch 'main' into develop
walmir-silva Jul 1, 2024
f40b0c3
feat: Add BinaryHeap implementation and comprehensive tests
walmir-silva Jul 2, 2024
aaeb8d9
docs: Update README files in English and Portuguese
walmir-silva Jul 2, 2024
b1d7662
style: Normalize code formatting and style
walmir-silva Jul 2, 2024
d677ae5
Merge branch 'main' into develop
walmir-silva Jul 2, 2024
ff2922f
feat: Create Container interface and add unit tests
walmir-silva Jul 5, 2024
8316540
feat: Add logging interfaces and corresponding tests
walmir-silva Jul 5, 2024
fd0cb1c
feat: Update logging interfaces Add tests for LoggerAware and LoggerC…
walmir-silva Jul 10, 2024
1b46d44
Merge branch 'main' into develop
walmir-silva Jul 10, 2024
30dd462
feat(logging): improve log rotation and update log handler
walmir-silva Jul 18, 2024
fc2bbe3
Refactor:Indexable interface and LogLevel class
walmir-silva Oct 10, 2024
c00bfdc
Merge branch 'main' into develop
walmir-silva Oct 10, 2024
788e773
feat(contract): Add Processor interfaces and tests
walmir-silva Oct 13, 2024
b40023f
feat: add ProcessorRegistry interface and unit tests
walmir-silva Oct 13, 2024
468dc9a
Merge branch 'main' into develop
walmir-silva Oct 13, 2024
9e223a4
feat(processor): add ProcessorBuilder interface and test suite
walmir-silva Oct 14, 2024
3da44b1
Merge branch 'develop' of https://github.com/KaririCode-Framework/kar…
walmir-silva Oct 14, 2024
611e84f
feat(contract): add PHPDoc for ProcessableAttribute interface and cre…
walmir-silva Oct 15, 2024
185bd7c
Merge branch 'main' into develop
walmir-silva Oct 15, 2024
bf99f58
feat(contract): add Sanitizer, Serializer, and Validator interfaces w…
walmir-silva Oct 15, 2024
3e56162
Merge branch 'develop' of https://github.com/KaririCode-Framework/kar…
walmir-silva Oct 15, 2024
b1a9521
fix(validator): correct return type of Validator interface
walmir-silva Oct 15, 2024
115cad9
Merge branch 'main' into develop
walmir-silva Oct 15, 2024
2fcec44
feat(contract): add CustomizableMessageAttribute interface
walmir-silva Oct 18, 2024
c6758d7
Merge branch 'develop' of https://github.com/KaririCode-Framework/kar…
walmir-silva Oct 18, 2024
1cbe3ca
feat: add BaseProcessorAttribute abstract class
walmir-silva Oct 18, 2024
756ea9f
refactor: adjusty filterValidProcessors in BaseProcessorAttribute
walmir-silva Oct 18, 2024
bf508f4
Merge branch 'main' into develop
walmir-silva Oct 18, 2024
9de21b2
feat(processor): add ProcessorValidator and ValidatableProcessor inte…
walmir-silva Oct 21, 2024
b5c27a7
Merge branch 'develop' of https://github.com/KaririCode-Framework/kar…
walmir-silva Oct 21, 2024
8b7d45b
feat(validator): Add reset method to ValidatableProcessor interface
walmir-silva Oct 24, 2024
50f6c51
feat(validator): Add reset method to ValidatableProcessor interface
walmir-silva Oct 24, 2024
87e89f0
Merge branch 'develop' of https://github.com/KaririCode-Framework/kar…
walmir-silva Oct 24, 2024
0d0fc3a
Merge branch 'main' into develop
walmir-silva Oct 24, 2024
260fd83
test(processor): add unit tests for ProcessingResult interface
walmir-silva Oct 25, 2024
a3a4547
Merge branch 'develop' of https://github.com/KaririCode-Framework/kar…
walmir-silva Oct 25, 2024
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
26 changes: 13 additions & 13 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions src/Processor/ProcessingResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

declare(strict_types=1);

namespace KaririCode\Contract\Processor;

/**
* Interface ProcessingResult.
*
* Defines the contract for handling processing results, including errors and processed data management.
*
* @category Processor
*
* @author Walmir Silva <walmir.silva@kariricode.org>
* @license MIT
*
* @see https://kariricode.org/
*/
interface ProcessingResult
{
/**
* Adds an error associated with a specific property.
*
* @param string $property The property where the error occurred
* @param string $errorKey A unique identifier for the type of error
* @param string $message A human-readable error message
*/
public function addError(string $property, string $errorKey, string $message): void;

/**
* Stores processed data for a specific property.
*
* @param string $property The property associated with the processed data
* @param mixed $value The processed value to be stored
*/
public function setProcessedData(string $property, mixed $value): void;

/**
* Checks if there are any errors in the processing result.
*
* @return bool True if there are errors, false otherwise
*/
public function hasErrors(): bool;

/**
* Retrieves all errors that occurred during processing.
*
* @return array<string, array<int, array{errorKey: string, message: string}>>
* A map of property names to their associated errors
*/
public function getErrors(): array;

/**
* Retrieves all processed data.
*
* @return array<string, mixed> A map of property names to their processed values
*/
public function getProcessedData(): array;

/**
* Converts the processing result into an array representation.
*
* @return array{
* isValid: bool,
* errors: array<string, array<int, array{errorKey: string, message: string}>>,
* processedData: array<string, mixed>
* }
*/
public function toArray(): array;

/**
* Clears all stored errors and processed data.
*/
public function clear(): void;
}
10 changes: 10 additions & 0 deletions src/Processor/ValidatableProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@
*/
interface ValidatableProcessor extends Processor
{
/**
* Resets the processor's state to its initial values.
*
* This method should be called before reusing the processor instance to ensure
* that any previous validation state is cleared and the processor is ready for
* new validation. This is particularly important when processors are reused
* across multiple validation cycles.
*/
public function reset(): void;

/**
* Checks if the processor is in a valid state.
*
Expand Down
110 changes: 110 additions & 0 deletions tests/Processor/ProcessingResultTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

declare(strict_types=1);

namespace KaririCode\Contract\Tests\Processor;

use KaririCode\Contract\Processor\ProcessingResult;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

final class ProcessingResultTest extends TestCase
{
private ProcessingResult|MockObject $processingResultMock;

protected function setUp(): void
{
parent::setUp();
$this->processingResultMock = $this->createMock(ProcessingResult::class);
}

public function testAddError(): void
{
$this->processingResultMock->expects($this->once())
->method('addError')
->with('property', 'error_key', 'error message');

$this->processingResultMock->addError('property', 'error_key', 'error message');
}

public function testSetProcessedData(): void
{
$this->processingResultMock->expects($this->once())
->method('setProcessedData')
->with('property', 'value');

$this->processingResultMock->setProcessedData('property', 'value');
}

public function testHasErrors(): void
{
$this->processingResultMock->expects($this->once())
->method('hasErrors')
->willReturn(true);

$this->assertTrue($this->processingResultMock->hasErrors());
}

public function testGetErrors(): void
{
$expectedErrors = [
'property' => [
[
'errorKey' => 'error_key',
'message' => 'error message',
],
],
];

$this->processingResultMock->expects($this->once())
->method('getErrors')
->willReturn($expectedErrors);

$this->assertSame($expectedErrors, $this->processingResultMock->getErrors());
}

public function testGetProcessedData(): void
{
$expectedData = [
'property' => 'processed value',
];

$this->processingResultMock->expects($this->once())
->method('getProcessedData')
->willReturn($expectedData);

$this->assertSame($expectedData, $this->processingResultMock->getProcessedData());
}

public function testToArray(): void
{
$expectedArray = [
'isValid' => false,
'errors' => [
'property' => [
[
'errorKey' => 'error_key',
'message' => 'error message',
],
],
],
'processedData' => [
'property' => 'processed value',
],
];

$this->processingResultMock->expects($this->once())
->method('toArray')
->willReturn($expectedArray);

$this->assertSame($expectedArray, $this->processingResultMock->toArray());
}

public function testClear(): void
{
$this->processingResultMock->expects($this->once())
->method('clear');

$this->processingResultMock->clear();
}
}
Loading