-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(pipeline): complete test coverage and remove unused exceptions
COVERAGE: - Complete test coverage for ProcessingResultCollection - Implement comprehensive tests for ProcessedData - Add full coverage for ProcessingError - Add tests for error hash generation - Cover all timestamp validations - Verify array conversions - Test error collections and data management CLEANUP: - Remove unused exception methods from ProcessorRuntimeException: * invalidProcessor() * invalidContext() * invalidConfiguration()
- Loading branch information
1 parent
c621016
commit 6d2e25b
Showing
7 changed files
with
630 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace KaririCode\ProcessorPipeline\Tests\Exception; | ||
|
||
use KaririCode\ProcessorPipeline\Exception\ProcessorRuntimeException; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class ProcessorRuntimeExceptionTest extends TestCase | ||
{ | ||
public function testContextNotFound(): void | ||
{ | ||
$exception = ProcessorRuntimeException::contextNotFound('payment'); | ||
|
||
$this->assertInstanceOf(ProcessorRuntimeException::class, $exception); | ||
$this->assertEquals(2601, $exception->getCode()); | ||
$this->assertEquals('PROCESSOR_CONTEXT_NOT_FOUND', $exception->getErrorCode()); | ||
$this->assertEquals("Processor context 'payment' not found", $exception->getMessage()); | ||
$this->assertNull($exception->getPrevious()); | ||
} | ||
|
||
public function testProcessorNotFound(): void | ||
{ | ||
$exception = ProcessorRuntimeException::processorNotFound('validate', 'payment'); | ||
|
||
$this->assertInstanceOf(ProcessorRuntimeException::class, $exception); | ||
$this->assertEquals(2602, $exception->getCode()); | ||
$this->assertEquals('PROCESSOR_NOT_FOUND', $exception->getErrorCode()); | ||
$this->assertEquals("Processor 'validate' not found in context 'payment'", $exception->getMessage()); | ||
$this->assertNull($exception->getPrevious()); | ||
} | ||
|
||
public function testProcessingFailed(): void | ||
{ | ||
$exception = ProcessorRuntimeException::processingFailed('email'); | ||
|
||
$this->assertInstanceOf(ProcessorRuntimeException::class, $exception); | ||
$this->assertEquals(2606, $exception->getCode()); | ||
$this->assertEquals('PROCESSOR_PROCESSING_FAILED', $exception->getErrorCode()); | ||
$this->assertEquals( | ||
"Processing failed for property 'email'", | ||
$exception->getMessage() | ||
); | ||
$this->assertNull($exception->getPrevious()); | ||
} | ||
|
||
/** | ||
* @dataProvider specialValuesProvider | ||
*/ | ||
public function testWithSpecialValues(string $context, string $processor, string $details): void | ||
{ | ||
$exceptionContext = ProcessorRuntimeException::contextNotFound($context); | ||
$this->assertStringContainsString($context, $exceptionContext->getMessage()); | ||
|
||
$exceptionProcessor = ProcessorRuntimeException::processorNotFound($processor, $context); | ||
$this->assertStringContainsString($processor, $exceptionProcessor->getMessage()); | ||
$this->assertStringContainsString($context, $exceptionProcessor->getMessage()); | ||
} | ||
|
||
public static function specialValuesProvider(): array | ||
{ | ||
return [ | ||
'empty values' => ['', '', ''], | ||
'special characters' => ['payment!@#', 'validator$%^', 'error&*()'], | ||
'unicode characters' => ['pagaménto', 'validação', 'erro'], | ||
'very long values' => [ | ||
str_repeat('a', 100), | ||
str_repeat('b', 100), | ||
str_repeat('c', 100), | ||
], | ||
]; | ||
} | ||
|
||
public function testExceptionHierarchy(): void | ||
{ | ||
$exception = ProcessorRuntimeException::contextNotFound('payment'); | ||
|
||
$this->assertInstanceOf(\Exception::class, $exception); | ||
$this->assertInstanceOf(\Throwable::class, $exception); | ||
} | ||
|
||
public function testExceptionWithPreviousException(): void | ||
{ | ||
$previous = new \Exception('Original error'); | ||
|
||
$reflection = new \ReflectionClass(ProcessorRuntimeException::class); | ||
$method = $reflection->getMethod('createException'); | ||
$method->setAccessible(true); | ||
|
||
$exception = $method->invokeArgs(null, [ | ||
2601, | ||
'PROCESSOR_CONTEXT_NOT_FOUND', | ||
'Test message', | ||
$previous, | ||
]); | ||
|
||
$this->assertInstanceOf(ProcessorRuntimeException::class, $exception); | ||
$this->assertEquals(2601, $exception->getCode()); | ||
$this->assertEquals('PROCESSOR_CONTEXT_NOT_FOUND', $exception->getErrorCode()); | ||
$this->assertEquals('Test message', $exception->getMessage()); | ||
$this->assertSame($previous, $exception->getPrevious()); | ||
} | ||
|
||
/** | ||
* @dataProvider invalidPropertyValuesProvider | ||
*/ | ||
public function testProcessingFailedWithDifferentPropertyTypes($property): void | ||
{ | ||
$exception = ProcessorRuntimeException::processingFailed($property); | ||
$message = $exception->getMessage(); | ||
|
||
$this->assertIsString($message); | ||
$this->assertStringContainsString((string) $property, $message); | ||
} | ||
|
||
public static function invalidPropertyValuesProvider(): array | ||
{ | ||
return [ | ||
'valid string' => ['email'], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace KaririCode\ProcessorPipeline\Tests\Result; | ||
|
||
use KaririCode\ProcessorPipeline\Result\ProcessedData; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class ProcessedDataTest extends TestCase | ||
{ | ||
public function testGetProperty(): void | ||
{ | ||
$data = new ProcessedData('email', 'test@example.com'); | ||
|
||
$this->assertEquals('email', $data->getProperty()); | ||
} | ||
|
||
public function testGetValue(): void | ||
{ | ||
$data = new ProcessedData('email', 'test@example.com'); | ||
|
||
$this->assertEquals('test@example.com', $data->getValue()); | ||
} | ||
|
||
public function testToArray(): void | ||
{ | ||
$data = new ProcessedData('email', 'test@example.com'); | ||
$result = $data->toArray(); | ||
|
||
$this->assertIsArray($result); | ||
$this->assertArrayHasKey('value', $result); | ||
$this->assertArrayHasKey('timestamp', $result); | ||
$this->assertEquals('test@example.com', $result['value']); | ||
$this->assertIsInt($result['timestamp']); | ||
$this->assertLessThanOrEqual(time(), $result['timestamp']); | ||
} | ||
|
||
/** | ||
* @dataProvider valueTypesProvider | ||
*/ | ||
public function testDifferentValueTypes(mixed $value): void | ||
{ | ||
$data = new ProcessedData('property', $value); | ||
|
||
$this->assertSame($value, $data->getValue()); | ||
$array = $data->toArray(); | ||
$this->assertSame($value, $array['value']); | ||
} | ||
|
||
public static function valueTypesProvider(): array | ||
{ | ||
return [ | ||
'string' => ['test'], | ||
'integer' => [42], | ||
'float' => [3.14], | ||
'boolean' => [true], | ||
'null' => [null], | ||
'array' => [['test' => 'value']], | ||
'object' => [new \stdClass()], | ||
]; | ||
} | ||
} |
Oops, something went wrong.