CoreFiles by mySites.guru
InvalidParameterExceptionHandlerTest.php44 lines, 1,409 bytes, from Joomla_4.1.0-rc1-Release_Candidate-Full_Package.zip
Raw History Compare with 4.0.6-rc3
md5
43a13909778640342a4082f87a37534a
sha1
1315b5c2449d6860a3235503b6ed41995f385578
sha256
d4da87b068ecf480fec7fdea3dcc5cb8bbf4d421592339462e640b99829c19c8
<?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\InvalidParameterExceptionHandler;
use Tobscure\JsonApi\Exception\Handler\ResponseBag;
use Tobscure\JsonApi\Exception\InvalidParameterException;

class InvalidParameterExceptionHandlerTest extends \PHPUnit_Framework_TestCase
{
    public function testHandlerCanManageInvalidParameterExceptions()
    {
        $handler = new InvalidParameterExceptionHandler();

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

    public function testHandlerCanNotManageOtherExceptions()
    {
        $handler = new InvalidParameterExceptionHandler();

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

    public function testErrorHandling()
    {
        $handler = new InvalidParameterExceptionHandler();
        $response = $handler->handle(new InvalidParameterException('error', 1, null, 'include'));

        $this->assertInstanceOf(ResponseBag::class, $response);
        $this->assertEquals(400, $response->getStatus());
        $this->assertEquals([['code' => 1, 'source' => ['parameter' => 'include']]], $response->getErrors());
    }
}

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.