Understand the Scope: Since this package is archived and no longer maintained, evaluate if its purpose aligns with your needs. It defines error specifications (e.g., for exception-based error handlers) and provides testing tools to validate conformance.
exception-based-error-handler.md (specification)test/exception-based-error-handler (test scripts)First Use Case:
Setup:
git clone https://github.com/php-errors/specification.git
cd specification/test/exception-based-error-handler
Defining Custom Error Specifications:
# Custom Laravel Error Specification
## Requirements
- All exceptions must implement `Throwable` and include a `getErrorCode()` method.
- Error handlers must log to `storage/logs/errors.log`.
docs/specs/ in your Laravel project.Testing Conformance:
exception-based-error-handler) to validate your Laravel app’s error handlers.use PHPUnit\Framework\TestCase;
class CustomErrorHandlerTest extends TestCase
{
public function testExceptionConformance()
{
$exception = new \App\Exceptions\CustomException('Test', 500);
$this->assertInstanceOf(\Throwable::class, $exception);
$this->assertEquals(500, $exception->getErrorCode());
}
}
Integration with Laravel:
// app/Exceptions/Handler.php
public function render($request, Throwable $exception)
{
if ($exception instanceof \App\Exceptions\CustomException) {
// Validate against your spec here
return response()->json(['error' => $exception->getMessage()], 500);
}
return parent::render($request, $exception);
}
Documentation-Driven Development:
README or CONTRIBUTING.md.No Active Maintenance:
Lack of Laravel-Specific Tools:
App\Exceptions\Handler). You’ll need to manually adapt specs/tests.report() or render() methods.Overhead for Small Projects:
Test Script Issues:
PHPUnit_Framework_TestCase). Update to modern PHPUnit:
// Before (deprecated)
class OldTest extends PHPUnit_Framework_TestCase {}
// After
class NewTest extends \PHPUnit\Framework\TestCase {}
--verbose to diagnose failures:
phpunit --verbose test/exception-based-error-handler/ExceptionTest.php
Spec Ambiguity:
getErrorCode() return null for unknown errors? Document this in your spec.Integration with Laravel’s Error Pages:
debug() method in Handler.php.resources/views/errors/500.blade.php).Custom Validation Logic:
// test/CustomLaravelExceptionTest.php
public function testLaravelExceptionFormat()
{
$exception = new \App\Exceptions\CustomException('Oops');
$this->assertArrayHasKey('message', $exception->toArray());
$this->assertArrayHasKey('code', $exception->toArray());
}
CI/CD Enforcement:
# .github/workflows/tests.yml
jobs:
test:
runs-on: ubuntu-latest
steps:
- run: php artisan test --filter=ExceptionConformanceTest
Static Analysis:
<!-- psalm.xml -->
<file-list>
<directory name="app/Exceptions" />
</file-list>
<properties>
<property name="interfaces_extend_classes" value="true" />
</properties>
Documentation Generation:
php artisan docs:generate (if using a custom docs system).flowchart TD
A[Exception Thrown] --> B{Custom?}
B -->|Yes| C[Validate Spec]
B -->|No| D[Default Handler]
C --> E[Log & Render]
---
How can I help you explore Laravel packages today?