forked from lunr-php/lunr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Corona: Add http exception for temporary disabled API's
Reviewed at https://reviews.lunr.nl/r/1227/
- Loading branch information
1 parent
b665654
commit 8b1b34f
Showing
3 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
/** | ||
* 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); | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
src/Lunr/Corona/Exceptions/Tests/TemporaryDisabledExceptionBaseTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} | ||
|
||
?> |
79 changes: 79 additions & 0 deletions
79
src/Lunr/Corona/Exceptions/Tests/TemporaryDisabledExceptionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} | ||
|
||
?> |