PHP Classes

File: tests/error_responder_test.php

Recommend this page to a friend!
  Packages of Adrian M   PHP CRUD API Generator   tests/error_responder_test.php   Download  
File: tests/error_responder_test.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP CRUD API Generator
Create an API to access MySQL database record
Author: By
Last change:
Date: 3 months ago
Size: 563 bytes
 

Contents

Class file image Download
<?php
require_once __DIR__ . '/../vendor/autoload.php';

use
App\Http\ErrorResponder;
use
App\Observability\RequestLogger;
use
App\Observability\Monitor;

$responder = new ErrorResponder(new RequestLogger(), new Monitor(), true);
try {
    throw new \
RuntimeException('Boom');
} catch (\
Throwable $e) {
    [
$payload,$status] = $responder->fromException($e, ['action'=>'test'], 500);
    if (
$status !== 500 || $payload['error'] !== 'Boom') {
       
fwrite(STDERR, "unexpected payload/status" . PHP_EOL);
        exit(
1);
    }
}
echo
"error_responder: PASS\n";