-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/Lunr/Corona/Exceptions/TemporarilyDisabledException.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,34 @@ | ||
<?php | ||
|
||
/** | ||
* This file contains the TemporarilyDisabledException class. | ||
* | ||
* 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 Temporarily Disabled HTTP error (540). | ||
*/ | ||
class TemporarilyDisabledException 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 temporarily disabled', int $app_code = 0, Exception $previous = NULL) | ||
{ | ||
parent::__construct($message, 540, $app_code, $previous); | ||
} | ||
|
||
} | ||
|
||
?> |
48 changes: 48 additions & 0 deletions
48
src/Lunr/Corona/Exceptions/Tests/TemporarilyDisabledExceptionBaseTest.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,48 @@ | ||
<?php | ||
|
||
/** | ||
* This file contains the TemporarilyDisabledExceptionBaseTest class. | ||
* | ||
* 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 TemporarilyDisabledException class. | ||
* | ||
* @covers Lunr\Corona\Exceptions\TemporarilyDisabledException | ||
*/ | ||
class TemporarilyDisabledExceptionBaseTest extends TemporarilyDisabledExceptionTest | ||
{ | ||
|
||
/** | ||
* 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/TemporarilyDisabledExceptionTest.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 TemporarilyDisabledExceptionTest 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\TemporarilyDisabledException; | ||
use Lunr\Halo\LunrBaseTest; | ||
|
||
/** | ||
* This class contains common setup routines, providers | ||
* and shared attributes for testing the TemporarilyDisabledException class. | ||
* | ||
* @covers Lunr\Corona\Exceptions\TemporarilyDisabledException | ||
*/ | ||
abstract class TemporarilyDisabledExceptionTest 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 TemporarilyDisabledException | ||
*/ | ||
protected TemporarilyDisabledException $class; | ||
|
||
/** | ||
* TestCase Constructor. | ||
*/ | ||
public function setUp(): void | ||
{ | ||
$this->message = 'Http error!'; | ||
$this->code = 9999; | ||
|
||
$this->previous = new Exception(); | ||
|
||
$this->class = new TemporarilyDisabledException($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(); | ||
} | ||
|
||
} | ||
|
||
?> |