Skip to content

Commit

Permalink
Merge branch 'release/0.10.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
pprkut committed Nov 15, 2024
2 parents 73696d6 + 9948722 commit 9f6d7df
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/Lunr/Corona/Exceptions/TemporarilyDisabledException.php
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);
}

}

?>
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;
}

}

?>
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();
}

}

?>

0 comments on commit 9f6d7df

Please sign in to comment.