CoreFiles by mySites.guru
FallbackExceptionHandlerTest.php46 lines, 1,438 bytes, from Joomla_4.1.1-Stable-Full_Package.zip
Raw History Compare with 4.1.0
md5
f447bf5838dba783ce9b1771c8c26cd0
sha1
ab0adb8261b4fff05762a98b06d13bb462b74206
sha256
cacf98f9257e7992f5491217f4256d6d56a81784c44f873110c3a55b09907ef6
<?php

/*
 * This file is part of JSON-API.
 *
 * (c) Toby Zerner <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Tobscure\Tests\Exception\Handler;

use Exception;
use Tobscure\JsonApi\Exception\Handler\FallbackExceptionHandler;
use Tobscure\JsonApi\Exception\Handler\ResponseBag;

class FallbackExceptionHandlerTest extends \PHPUnit_Framework_TestCase
{
    public function testHandlerCanManageExceptions()
    {
        $handler = new FallbackExceptionHandler(false);

        $this->assertTrue($handler->manages(new Exception));
    }

    public function testErrorHandlingWithoutDebugMode()
    {
        $handler = new FallbackExceptionHandler(false);
        $response = $handler->handle(new Exception);

        $this->assertInstanceOf(ResponseBag::class, $response);
        $this->assertEquals(500, $response->getStatus());
        $this->assertEquals([['code' => 500, 'title' => 'Internal server error']], $response->getErrors());
    }

    public function testErrorHandlingWithDebugMode()
    {
        $handler = new FallbackExceptionHandler(true);
        $response = $handler->handle(new Exception);

        $this->assertInstanceOf(ResponseBag::class, $response);
        $this->assertEquals(500, $response->getStatus());
        $this->assertArrayHasKey('detail', $response->getErrors()[0]);
    }
}

The same content is in 9 releases, Joomla 4.1.0-rc1 to 4.1.2. See them all, or every version of this file.