-
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.
refactor: throw UnsupportedIndexLanguageException for unsupported lan…
…guage
- Loading branch information
1 parent
390c685
commit b3a9b32
Showing
7 changed files
with
115 additions
and
21 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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Atoolo\Search\Exception; | ||
|
||
use Atoolo\Resource\ResourceLanguage; | ||
use RuntimeException; | ||
|
||
class UnsupportedIndexLanguageException extends RuntimeException | ||
{ | ||
public function __construct( | ||
private readonly string $index, | ||
private readonly ResourceLanguage $lang, | ||
string $message = "", | ||
int $code = 0, | ||
?\Throwable $previous = null | ||
) { | ||
parent::__construct( | ||
$index . '/' . $lang->code . ': ' . $message, | ||
$code, | ||
$previous | ||
); | ||
} | ||
|
||
public function getIndex(): string | ||
{ | ||
return $this->index; | ||
} | ||
|
||
public function getLang(): ResourceLanguage | ||
{ | ||
return $this->lang; | ||
} | ||
} |
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
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
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
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,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Atoolo\Search\Test\Exception; | ||
|
||
use Atoolo\Resource\ResourceLanguage; | ||
use Atoolo\Search\Exception\UnsupportedIndexLanguageException; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class UnsupportedIndexLanguageExceptionTest extends TestCase | ||
{ | ||
public function testGetIndex(): void | ||
{ | ||
$e = new UnsupportedIndexLanguageException( | ||
'test', | ||
ResourceLanguage::of('de') | ||
); | ||
$this->assertEquals( | ||
'test', | ||
$e->getIndex(), | ||
'unexpected index' | ||
); | ||
} | ||
|
||
public function testGetLang(): void | ||
{ | ||
$e = new UnsupportedIndexLanguageException( | ||
'test', | ||
ResourceLanguage::of('de') | ||
); | ||
$this->assertEquals( | ||
ResourceLanguage::of('de'), | ||
$e->getLang(), | ||
'unexpected index' | ||
); | ||
} | ||
} |
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
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