From 9948722b35a80b8c097d611cdaddc18df4dac1ca Mon Sep 17 00:00:00 2001 From: Brian Stoop Date: Fri, 8 Nov 2024 11:46:20 +0100 Subject: [PATCH] Corona: Add http exception for temporarily disabled API's Reviewed at https://reviews.lunr.nl/r/1227/ --- .../TemporarilyDisabledException.php | 34 ++++++++ .../TemporarilyDisabledExceptionBaseTest.php | 48 +++++++++++ .../TemporarilyDisabledExceptionTest.php | 79 +++++++++++++++++++ 3 files changed, 161 insertions(+) create mode 100644 src/Lunr/Corona/Exceptions/TemporarilyDisabledException.php create mode 100644 src/Lunr/Corona/Exceptions/Tests/TemporarilyDisabledExceptionBaseTest.php create mode 100644 src/Lunr/Corona/Exceptions/Tests/TemporarilyDisabledExceptionTest.php diff --git a/src/Lunr/Corona/Exceptions/TemporarilyDisabledException.php b/src/Lunr/Corona/Exceptions/TemporarilyDisabledException.php new file mode 100644 index 00000000..46c8443c --- /dev/null +++ b/src/Lunr/Corona/Exceptions/TemporarilyDisabledException.php @@ -0,0 +1,34 @@ + diff --git a/src/Lunr/Corona/Exceptions/Tests/TemporarilyDisabledExceptionBaseTest.php b/src/Lunr/Corona/Exceptions/Tests/TemporarilyDisabledExceptionBaseTest.php new file mode 100644 index 00000000..fe7a2efd --- /dev/null +++ b/src/Lunr/Corona/Exceptions/Tests/TemporarilyDisabledExceptionBaseTest.php @@ -0,0 +1,48 @@ +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; + } + +} + +?> diff --git a/src/Lunr/Corona/Exceptions/Tests/TemporarilyDisabledExceptionTest.php b/src/Lunr/Corona/Exceptions/Tests/TemporarilyDisabledExceptionTest.php new file mode 100644 index 00000000..e4d9ff10 --- /dev/null +++ b/src/Lunr/Corona/Exceptions/Tests/TemporarilyDisabledExceptionTest.php @@ -0,0 +1,79 @@ +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(); + } + +} + +?>