|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Tests; |
| 6 | + |
| 7 | +use PHPUnit\Event\Code\Throwable as PHPUnitThrowable; |
| 8 | +use PHPUnit\Framework\AssertionFailedError; |
| 9 | +use PHPUnit\Framework\ExpectationFailedException; |
| 10 | +use PHPUnit\Framework\TestCase; |
| 11 | +use Qase\PHPUnitReporter\StatusDetector; |
| 12 | + |
| 13 | +class StatusDetectorTest extends TestCase |
| 14 | +{ |
| 15 | + public function testIsAssertionFailureWithAssertionFailedError(): void |
| 16 | + { |
| 17 | + $throwable = $this->createPHPUnitThrowable(AssertionFailedError::class, 'Test assertion failed'); |
| 18 | + |
| 19 | + $this->assertTrue(StatusDetector::isAssertionFailure($throwable)); |
| 20 | + } |
| 21 | + |
| 22 | + public function testIsAssertionFailureWithExpectationFailedException(): void |
| 23 | + { |
| 24 | + $throwable = $this->createPHPUnitThrowable(ExpectationFailedException::class, 'Expected value was not equal to actual value'); |
| 25 | + |
| 26 | + $this->assertTrue(StatusDetector::isAssertionFailure($throwable)); |
| 27 | + } |
| 28 | + |
| 29 | + public function testIsNotAssertionFailureWithGenericException(): void |
| 30 | + { |
| 31 | + $throwable = $this->createPHPUnitThrowable(\Exception::class, 'Generic exception occurred'); |
| 32 | + |
| 33 | + $this->assertFalse(StatusDetector::isAssertionFailure($throwable)); |
| 34 | + } |
| 35 | + |
| 36 | + public function testIsNotAssertionFailureWithRuntimeException(): void |
| 37 | + { |
| 38 | + $throwable = $this->createPHPUnitThrowable(\RuntimeException::class, 'Runtime error occurred'); |
| 39 | + |
| 40 | + $this->assertFalse(StatusDetector::isAssertionFailure($throwable)); |
| 41 | + } |
| 42 | + |
| 43 | + public function testGetStatusForFailureWithAssertionFailedError(): void |
| 44 | + { |
| 45 | + $throwable = $this->createPHPUnitThrowable(AssertionFailedError::class, 'Test assertion failed'); |
| 46 | + |
| 47 | + $this->assertEquals('failed', StatusDetector::getStatusForFailure($throwable)); |
| 48 | + } |
| 49 | + |
| 50 | + public function testGetStatusForFailureWithExpectationFailedException(): void |
| 51 | + { |
| 52 | + $throwable = $this->createPHPUnitThrowable(ExpectationFailedException::class, 'Expected value was not equal to actual value'); |
| 53 | + |
| 54 | + $this->assertEquals('failed', StatusDetector::getStatusForFailure($throwable)); |
| 55 | + } |
| 56 | + |
| 57 | + public function testGetStatusForFailureWithGenericException(): void |
| 58 | + { |
| 59 | + $throwable = $this->createPHPUnitThrowable(\Exception::class, 'Generic exception occurred'); |
| 60 | + |
| 61 | + $this->assertEquals('invalid', StatusDetector::getStatusForFailure($throwable)); |
| 62 | + } |
| 63 | + |
| 64 | + public function testGetStatusForFailureWithRuntimeException(): void |
| 65 | + { |
| 66 | + $throwable = $this->createPHPUnitThrowable(\RuntimeException::class, 'Runtime error occurred'); |
| 67 | + |
| 68 | + $this->assertEquals('invalid', StatusDetector::getStatusForFailure($throwable)); |
| 69 | + } |
| 70 | + |
| 71 | + private function createPHPUnitThrowable(string $className, string $message): PHPUnitThrowable |
| 72 | + { |
| 73 | + return new PHPUnitThrowable( |
| 74 | + $className, |
| 75 | + $message, |
| 76 | + $message, |
| 77 | + 'Stack trace here', |
| 78 | + null |
| 79 | + ); |
| 80 | + } |
| 81 | +} |
0 commit comments