Skip to content

Commit f26a062

Browse files
authored
feat(processor): add ProcessorBuilder interface and test suite (#25)
* 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 * feat: add ProcessorRegistry interface and unit tests - Introduced `ProcessorRegistry` interface to standardize processor registration and retrieval across contexts. - Added `ProcessorRegistryTest` class to ensure correctness of the new interface, covering scenarios like processor registration, retrieval, and error handling. * feat(processor): add ProcessorBuilder interface and test suite - Add ProcessorBuilder interface in KaririCode\Contract\Processor namespace - Define build() method for constructing individual processors - Define buildPipeline() method for assembling processor pipelines - Create ProcessorBuilderTest class in KaririCode\Contract\Tests\Processor namespace - Implement tests for build() and buildPipeline() methods - Cover success scenarios and exception handling - Ensure proper interaction with ProcessorRegistry
1 parent fed3014 commit f26a062

File tree

2 files changed

+142
-0
lines changed

2 files changed

+142
-0
lines changed

src/Processor/ProcessorBuilder.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace KaririCode\Contract\Processor;
6+
7+
/**
8+
* Interface ProcessorBuilder.
9+
*
10+
* Defines the contract for a builder that constructs processors and processor pipelines.
11+
* This builder allows for the creation of individual processors and the assembly of
12+
* multiple processors into a pipeline, based on given specifications and contexts.
13+
*
14+
* @category ProcessorPipeline
15+
*
16+
* @author [Your Name] <your.email@example.com>
17+
* @license MIT
18+
*
19+
* @see https://kariricode.org/
20+
*/
21+
interface ProcessorBuilder
22+
{
23+
/**
24+
* Builds a single processor.
25+
*
26+
* This method constructs and configures a processor based on the provided
27+
* context, name, and configuration options.
28+
*
29+
* @param string $context The context in which the processor is being built
30+
* @param string $name The name of the processor to build
31+
* @param array $processorConfig Configuration options for the processor
32+
*
33+
* @throws \RuntimeException If the processor cannot be built or configured
34+
*
35+
* @return Processor The constructed processor instance
36+
*/
37+
public function build(string $context, string $name, array $processorConfig = []): Processor;
38+
39+
/**
40+
* Builds a pipeline of processors.
41+
*
42+
* This method constructs a pipeline by building and assembling multiple
43+
* processors based on the provided specifications and context.
44+
*
45+
* @param string $context The context in which the pipeline is being built
46+
* @param array $processorSpecs An array of processor specifications
47+
*
48+
* @throws \RuntimeException If the pipeline cannot be built or if any processor fails to construct
49+
*
50+
* @return Pipeline The constructed pipeline instance containing the specified processors
51+
*/
52+
public function buildPipeline(string $context, array $processorSpecs): Pipeline;
53+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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 KaririCode\Contract\Processor\ProcessorBuilder;
10+
use KaririCode\Contract\Processor\ProcessorRegistry;
11+
use PHPUnit\Framework\MockObject\MockObject;
12+
use PHPUnit\Framework\TestCase;
13+
14+
final class ProcessorBuilderTest extends TestCase
15+
{
16+
private ProcessorBuilder|MockObject $processorBuilderMock;
17+
private Processor|MockObject $processorMock;
18+
private Pipeline|MockObject $pipelineMock;
19+
private ProcessorRegistry|MockObject $processorRegistryMock;
20+
21+
protected function setUp(): void
22+
{
23+
parent::setUp();
24+
$this->processorBuilderMock = $this->createMock(ProcessorBuilder::class);
25+
$this->processorMock = $this->createMock(Processor::class);
26+
$this->pipelineMock = $this->createMock(Pipeline::class);
27+
$this->processorRegistryMock = $this->createMock(ProcessorRegistry::class);
28+
}
29+
30+
public function testBuild(): void
31+
{
32+
$this->processorBuilderMock->expects($this->once())
33+
->method('build')
34+
->with('context', 'name', [])
35+
->willReturn($this->processorMock);
36+
37+
$this->assertSame($this->processorMock, $this->processorBuilderMock->build('context', 'name'));
38+
}
39+
40+
public function testBuildWithConfig(): void
41+
{
42+
$config = ['option' => 'value'];
43+
$this->processorBuilderMock->expects($this->once())
44+
->method('build')
45+
->with('context', 'name', $config)
46+
->willReturn($this->processorMock);
47+
48+
$this->assertSame($this->processorMock, $this->processorBuilderMock->build('context', 'name', $config));
49+
}
50+
51+
public function testBuildPipeline(): void
52+
{
53+
$processorSpecs = [
54+
'processor1' => [],
55+
'processor2' => ['option' => 'value'],
56+
];
57+
58+
$this->processorBuilderMock->expects($this->once())
59+
->method('buildPipeline')
60+
->with('context', $processorSpecs)
61+
->willReturn($this->pipelineMock);
62+
63+
$this->assertSame($this->pipelineMock, $this->processorBuilderMock->buildPipeline('context', $processorSpecs));
64+
}
65+
66+
public function testBuildThrowsException(): void
67+
{
68+
$this->processorBuilderMock->expects($this->once())
69+
->method('build')
70+
->with('nonexistent', 'name')
71+
->willThrowException(new \RuntimeException('Processor not found'));
72+
73+
$this->expectException(\RuntimeException::class);
74+
$this->expectExceptionMessage('Processor not found');
75+
$this->processorBuilderMock->build('nonexistent', 'name');
76+
}
77+
78+
public function testBuildPipelineThrowsException(): void
79+
{
80+
$this->processorBuilderMock->expects($this->once())
81+
->method('buildPipeline')
82+
->with('nonexistent', [])
83+
->willThrowException(new \RuntimeException('Failed to build pipeline'));
84+
85+
$this->expectException(\RuntimeException::class);
86+
$this->expectExceptionMessage('Failed to build pipeline');
87+
$this->processorBuilderMock->buildPipeline('nonexistent', []);
88+
}
89+
}

0 commit comments

Comments
 (0)