Skip to content

Commit 96277f4

Browse files
authored
Add Processor Interfaces and Tests to KaririCode\Contract (#23)
* add size method * feat: Normalize Interfaces - Refined and standardized interface definitions across the project - Applied Single Responsibility Principle (SRP) to ensure each interface has a clear, singular purpose - Consistent naming conventions were implemented for better readability and maintainability - Added thorough documentation for each interface, including method descriptions and expected behaviors - Organized interfaces within appropriate namespaces to prevent naming collisions and maintain a logical structure - Ensured parameter names in interface methods are consistent with implementing classes - Avoided including constructors in interfaces to maintain flexibility These changes enhance the overall clarity, maintainability, and professional quality of the codebase. * Refactor and Normalize Collection Interface and Implementation - Refactored `Collection` interface for consistency and adherence to best practices. - Ensured all tests are comprehensive and validate the expected behavior. * feat: Add BinaryHeap implementation and comprehensive tests - Implemented BinaryHeap class with support for both min-heap and max-heap operations. - Methods include: add, poll, peek, size, isEmpty, heapifyUp, heapifyDown, swap, and compare. - Created unit tests for BinaryHeap class ensuring 100% coverage. - Tested all key operations: add, poll, peek, heapifyUp, heapifyDown, swap, and compare. - Included edge case tests for min-heap and max-heap scenarios. - Ensured compliance with type safety and PHP 8.0+ features. - Added comprehensive documentation and examples for BinaryHeap usage. This commit enhances the KaririCode Framework by providing a robust, type-safe, and efficient BinaryHeap data structure with extensive unit tests. * docs: Update README files in English and Portuguese - Enhanced the overview and key features sections for clarity and completeness. - Added detailed descriptions for all implemented data structures: - TreeSet - ArrayDeque - ArrayQueue - TreeMap - LinkedList - BinaryHeap - HashMap - Included complexity analysis and key methods for each data structure. - Provided usage examples for each data structure to demonstrate functionality. - Updated installation instructions and requirements. - Updated acknowledgments and roadmap sections. * style: Normalize code formatting and style * feat: Create Container interface and add unit tests - Define the Container interface with methods: `set`, `get`, and `has`. - Implement unit tests for `set` method to ensure services are registered correctly. - Add unit tests for `get` method to verify correct retrieval of services by identifier. - Include unit tests for `has` method to check existence of services in the container. - Normalize the `@category` comments in the interface documentation for consistency. These changes establish a foundational contract for dependency injection within the KaririCode project and ensure robust and reliable functionality through comprehensive testing * feat: Add logging interfaces and corresponding tests - Created Configurable interface for managing configuration settings. - Created Loggable interface to define logging methods for various log levels. - Created ContextAware interface for managing context information in logs. - Created FormatterAware interface for handling log formatter settings. - Created HandlerAware interface for managing log handlers. - Created ProcessorAware interface for managing log processors. - Created LoggingManager interface that combines various logging functionalities. - Created LogFormatter interface for defining log formatters. - Created LogHandler interface for handling log records. - Created LogLevel interface for defining log levels. - Created LogProcessor interface for processing log records before handling. - Created LogRotator interface for managing log file rotation. - Added unit tests for each interface to ensure correct functionality: - ConfigurableTest: Tests for setConfig and getConfig methods. - LoggableTest: Tests for various logging level methods. - ContextAwareTest: Tests for withContext and getContext methods. - FormatterAwareTest: Tests for setFormatter and getFormatter methods. - HandlerAwareTest: Tests for addHandler, pushHandler, popHandler, and getHandlers methods. - ProcessorAwareTest: Tests for addProcessor and getProcessors methods. - LoggingManagerTest: Comprehensive tests for all LoggingManager methods. - LogFormatterTest: Test for the format method. - LogHandlerTest: Test for the handle method. - LogLevelTest: Test for the getLevel method. - LogProcessorTest: Test for the process method. - LogRotatorTest: Test for the rotate method. * feat: Update logging interfaces Add tests for LoggerAware and LoggerConfigurable interfaces - Revised and enhanced logging interfaces for better consistency and flexibility. - Implemented new methods to support asynchronous logging. - Improved documentation of the interfaces to facilitate integration. - Added unit tests to ensure the robustness of the new implementations. - Added unit test for LoggerAware interface to verify setLogger method. - Added unit test for LoggerConfigurable interface to verify configure method. - Ensured proper mock setup and expectations in tests. * feat(logging): improve log rotation and update log handler - Removed .phpcs-cache for cleaner repository - Updated src/Logging/LogHandler.php to enhance log handling capabilities - Modified src/Logging/LogLevel.php for better log level management - Enhanced src/Logging/LogRotator.php with improved file rotation logic - Updated src/Logging/Logger.php to integrate changes in log handling and rotation * Refactor:Indexable interface and LogLevel class - Modified the Indexable.php interface to enhance functionality. - Updated the LogLevel.php class to add new log levels. - Made lint adjustments in LogRotator class. * feat(contract): Add Processor interfaces and tests - Introduce new interfaces: Processor, ConfigurableProcessor, Pipeline - Add comprehensive PHPUnit tests for each interface - Enhance code documentation with detailed PHP DocBlocks - Ensure consistency with existing KaririCode coding standards
1 parent 5d98b00 commit 96277f4

File tree

8 files changed

+184
-1
lines changed

8 files changed

+184
-1
lines changed

src/Logging/LogHandler.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function handle(ImmutableValue $record): void;
3737

3838
/**
3939
* Checks whether the handler is handling the given log level.
40+
*
4041
* @param ImmutableValue $record the log record to be processed, represented as an associative array
4142
*/
4243
public function isHandling(ImmutableValue $record): bool;

src/Logging/LogRotator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
interface LogRotator
2222
{
2323
public function shouldRotate(string $filePath): bool;
24+
2425
/**
2526
* Rotates a log file.
2627
*
@@ -30,5 +31,4 @@ public function shouldRotate(string $filePath): bool;
3031
* @param string $filename the name of the log file to be rotated
3132
*/
3233
public function rotate(string $filename): void;
33-
3434
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace KaririCode\Contract\Processor;
6+
7+
/**
8+
* Interface ConfigurableProcessor.
9+
*
10+
* Extends the Processor interface to allow configuration of the processor.
11+
*
12+
* @category Processor
13+
*
14+
* @author Walmir Silva <walmir.silva@kariricode.org>
15+
* @license MIT
16+
*
17+
* @see https://kariricode.org/
18+
*/
19+
interface ConfigurableProcessor extends Processor
20+
{
21+
/**
22+
* Configures the processor with the provided options.
23+
*
24+
* @param array $options The configuration options
25+
*/
26+
public function configure(array $options): void;
27+
}

src/Processor/Pipeline.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace KaririCode\Contract\Processor;
6+
7+
/**
8+
* Interface Pipeline.
9+
*
10+
* Defines the contract for a pipeline that can execute a series of processors.
11+
*
12+
* @category Processor
13+
*
14+
* @author Walmir Silva <walmir.silva@kariricode.org>
15+
* @license MIT
16+
*
17+
* @see https://kariricode.org/
18+
*/
19+
interface Pipeline
20+
{
21+
/**
22+
* Adds a processor to the pipeline.
23+
*
24+
* @param Processor $processor The processor to be added
25+
*/
26+
public function addProcessor(Processor $processor): self;
27+
28+
/**
29+
* Executes the processing pipeline on the provided input.
30+
*
31+
* @param mixed $input The value to be processed by the pipeline
32+
*
33+
* @return mixed The final result after passing through all processors
34+
*/
35+
public function process(mixed $input): mixed;
36+
}

src/Processor/Processor.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace KaririCode\Contract\Processor;
6+
7+
/**
8+
* Interface Processor.
9+
*
10+
* Defines the contract for a processor that can transform or validate input data.
11+
*
12+
* @category Processor
13+
*
14+
* @author Walmir Silva <walmir.silva@kariricode.org>
15+
* @license MIT
16+
*
17+
* @see https://kariricode.org/
18+
*/
19+
interface Processor
20+
{
21+
/**
22+
* Processes the provided input and returns the result.
23+
*
24+
* @param mixed $input The value to be processed
25+
*
26+
* @return mixed The result of the processing
27+
*/
28+
public function process(mixed $input): mixed;
29+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace KaririCode\Contract\Tests\Processor;
6+
7+
use KaririCode\Contract\Processor\ConfigurableProcessor;
8+
use PHPUnit\Framework\TestCase;
9+
10+
final class ConfigurableProcessorTest extends TestCase
11+
{
12+
public function testConfigure(): void
13+
{
14+
$mock = $this->createMock(ConfigurableProcessor::class);
15+
$mock->expects($this->once())
16+
->method('configure')
17+
->with(['option' => 'value']);
18+
19+
$mock->configure(['option' => 'value']);
20+
}
21+
22+
public function testProcess(): void
23+
{
24+
$mock = $this->createMock(ConfigurableProcessor::class);
25+
$mock->expects($this->once())
26+
->method('process')
27+
->with('input')
28+
->willReturn('output');
29+
30+
$this->assertSame('output', $mock->process('input'));
31+
}
32+
}

tests/Processor/PipelineTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace KaririCode\Contract\Tests\Processor;
6+
7+
use KaririCode\Contract\Processor\Pipeline;
8+
use KaririCode\Contract\Processor\Processor;
9+
use PHPUnit\Framework\TestCase;
10+
11+
final class PipelineTest extends TestCase
12+
{
13+
public function testAddProcessor(): void
14+
{
15+
$mock = $this->createMock(Pipeline::class);
16+
$processor = $this->createMock(Processor::class);
17+
18+
$mock->expects($this->once())
19+
->method('addProcessor')
20+
->with($processor)
21+
->willReturnSelf();
22+
23+
$this->assertSame($mock, $mock->addProcessor($processor));
24+
}
25+
26+
public function testProcess(): void
27+
{
28+
$mock = $this->createMock(Pipeline::class);
29+
$mock->expects($this->once())
30+
->method('process')
31+
->with('input')
32+
->willReturn('output');
33+
34+
$this->assertSame('output', $mock->process('input'));
35+
}
36+
}

tests/Processor/ProcessorTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace KaririCode\Contract\Tests\Processor;
6+
7+
use KaririCode\Contract\Processor\Processor;
8+
use PHPUnit\Framework\TestCase;
9+
10+
final class ProcessorTest extends TestCase
11+
{
12+
public function testProcess(): void
13+
{
14+
$mock = $this->createMock(Processor::class);
15+
$mock->expects($this->once())
16+
->method('process')
17+
->with('input')
18+
->willReturn('output');
19+
20+
$this->assertSame('output', $mock->process('input'));
21+
}
22+
}

0 commit comments

Comments
 (0)