Skip to content

Commit

Permalink
Corona: Add http exception for temporary disabled API's
Browse files Browse the repository at this point in the history
  • Loading branch information
brianstoop committed Oct 30, 2024
1 parent b665654 commit 8b1b34f
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/Lunr/Corona/Exceptions/TemporaryDisabledException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

Check failure on line 1 in src/Lunr/Corona/Exceptions/TemporaryDisabledException.php

View workflow job for this annotation

GitHub Actions / php-tests / phpcs / PHPCS

The PHP open tag does not have a corresponding PHP close tag

/**
* This file contains the TemporaryDisabledException class.
*
* SPDX-FileCopyrightText: Copyright 2018 M2mobi B.V., Amsterdam, The Netherlands
* SPDX-FileCopyrightText: Copyright 2024 Move Agency Group B.V., Zwolle, The Netherlands
* SPDX-License-Identifier: MIT
*/

namespace Lunr\Corona\Exceptions;

use Exception;

/**
* Exception for the Temporary Disabled HTTP error (540).
*/
class TemporaryDisabledException extends HttpException
{

/**
* Constructor.
*
* @param string $message Error message
* @param int $app_code Application error code
* @param Exception|null $previous The previously thrown exception
*/
public function __construct(string $message = 'The requested API is currently disabled', int $app_code = 0, Exception $previous = NULL)
{
parent::__construct($message, 540, $app_code, $previous);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/**
* This file contains the TemporaryDisabledExceptionBaseTest class.
*
* SPDX-FileCopyrightText: Copyright 2018 M2mobi B.V., Amsterdam, The Netherlands
* SPDX-FileCopyrightText: Copyright 2024 Move Agency Group B.V., Zwolle, The Netherlands
* SPDX-License-Identifier: MIT
*/

namespace Lunr\Corona\Exceptions\Tests;

/**
* This class contains tests for the TemporaryDisabledException class.
*
* @covers Lunr\Corona\Exceptions\TemporaryDisabledException
*/
class TemporaryDisabledExceptionBaseTest extends TemporaryDisabledExceptionTest
{

/**
* Test that the error code was set correctly.
*/
public function testErrorCodeSetCorrectly(): void
{
$this->assertPropertySame('code', 540);
}

/**
* Test that the error code was set correctly.
*/
public function testApplicationErrorCodeSetCorrectly(): void
{
$this->assertPropertySame('app_code', $this->code);
}

/**
* Test that the error message was passed correctly.
*/
public function testErrorMessagePassedCorrectly(): void
{
$this->expectExceptionMessage($this->message);

throw $this->class;
}

}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

/**
* This file contains the TemporaryDisabledExceptionTest class.
*
* SPDX-FileCopyrightText: Copyright 2024 Move Agency Group B.V., Zwolle, The Netherlands
* SPDX-License-Identifier: MIT
*/

namespace Lunr\Corona\Exceptions\Tests;

use Exception;
use Lunr\Corona\Exceptions\TemporaryDisabledException;
use Lunr\Halo\LunrBaseTest;

/**
* This class contains common setup routines, providers
* and shared attributes for testing the TemporaryDisabledException class.
*
* @covers Lunr\Corona\Exceptions\TemporaryDisabledException
*/
abstract class TemporaryDisabledExceptionTest extends LunrBaseTest
{

/**
* Previous exception.
* @var Exception
*/
protected $previous;

/**
* Error message.
* @var string
*/
protected $message;

/**
* Application error code.
* @var int
*/
protected $code;

/**
* Instance of the tested class.
* @var TemporaryDisabledException
*/
protected TemporaryDisabledException $class;

/**
* TestCase Constructor.
*/
public function setUp(): void
{
$this->message = 'Http error!';
$this->code = 9999;

$this->previous = new Exception();

$this->class = new TemporaryDisabledException($this->message, $this->code, $this->previous);

parent::baseSetUp($this->class);
}

/**
* TestCase Destructor.
*/
public function tearDown(): void
{
unset($this->code);
unset($this->message);
unset($this->previous);
unset($this->class);

parent::tearDown();
}

}

?>

0 comments on commit 8b1b34f

Please sign in to comment.