-
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.
Corona: Separate parser for the sapi
Issue: MOVE-14
- Loading branch information
1 parent
e8fa54b
commit 634ea43
Showing
8 changed files
with
216 additions
and
18 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,76 @@ | ||
<?php | ||
|
||
/** | ||
* This file contains the request value parser for the sapi | ||
* | ||
* SPDX-FileCopyrightText: Copyright 2025 Move Agency Group B.V., Zwolle, The Netherlands | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
namespace Lunr\Corona\Parsers\Sapi; | ||
|
||
use BackedEnum; | ||
use Lunr\Corona\RequestValueInterface; | ||
use Lunr\Corona\RequestValueParserInterface; | ||
use RuntimeException; | ||
|
||
/** | ||
* Request Value Parser for sapi | ||
*/ | ||
class SapiParser implements RequestValueParserInterface | ||
{ | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct() | ||
{ | ||
// no-op | ||
} | ||
|
||
/** | ||
* Destructor. | ||
*/ | ||
public function __destruct() | ||
{ | ||
// no-op | ||
} | ||
|
||
/** | ||
* Return the request value type the parser handles. | ||
* | ||
* @return class-string The FQDN of the type enum the parser handles | ||
*/ | ||
public function getRequestValueType(): string | ||
{ | ||
return SapiValue::class; | ||
} | ||
|
||
/** | ||
* Get a request value. | ||
* | ||
* @param BackedEnum&RequestValueInterface $key The identifier/name of the request value to get | ||
* | ||
* @return string|null | ||
*/ | ||
public function get(BackedEnum&RequestValueInterface $key): ?string | ||
{ | ||
return match ($key) { | ||
SapiValue::Sapi => $this->parse(), | ||
default => throw new RuntimeException('Unsupported request value type "' . $key::class . '"'), | ||
}; | ||
} | ||
|
||
/** | ||
* Parse SAPI | ||
* | ||
* @return string|null | ||
*/ | ||
public function parse(): ?string | ||
{ | ||
return PHP_SAPI; | ||
} | ||
|
||
} | ||
|
||
?> |
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,27 @@ | ||
<?php | ||
|
||
/** | ||
* This file contains the sapi value. | ||
* | ||
* SPDX-FileCopyrightText: Copyright 2025 Move Agency Group B.V., Zwolle, The Netherlands | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
namespace Lunr\Corona\Parsers\Sapi; | ||
|
||
use Lunr\Corona\RequestValueInterface; | ||
|
||
/** | ||
* Request Data Enums | ||
*/ | ||
enum SapiValue: string implements RequestValueInterface | ||
{ | ||
|
||
/** | ||
* Sapi | ||
*/ | ||
case Sapi = 'sapi'; | ||
|
||
} | ||
|
||
?> |
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,61 @@ | ||
<?php | ||
|
||
/** | ||
* This file contains the SapiParserGetTest class. | ||
* | ||
* SPDX-FileCopyrightText: Copyright 2025 Move Agency Group B.V., Zwolle, The Netherlands | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
namespace Lunr\Corona\Parsers\Sapi\Tests; | ||
|
||
use Lunr\Corona\Parsers\Sapi\SapiValue; | ||
use Lunr\Corona\Tests\Helpers\MockRequestValue; | ||
use RuntimeException; | ||
|
||
/** | ||
* This class contains test methods for the SapiParser class. | ||
* | ||
* @covers Lunr\Corona\Parsers\Sapi\SapiParser | ||
*/ | ||
class SapiParserGetTest extends SapiParserTestCase | ||
{ | ||
|
||
/** | ||
* Test that getRequestValueType() returns the correct type. | ||
* | ||
* @covers Lunr\Corona\Parsers\Sapi\SapiParser::getRequestValueType | ||
*/ | ||
public function testGetRequestValueType() | ||
{ | ||
$this->assertEquals(SapiValue::class, $this->class->getRequestValueType()); | ||
} | ||
|
||
/** | ||
* Test getting an unsupported value. | ||
* | ||
* @covers Lunr\Corona\Parsers\Sapi\SapiParser::get | ||
*/ | ||
public function testGetUnsupportedValue() | ||
{ | ||
$this->expectException(RuntimeException::class); | ||
$this->expectExceptionMessage('Unsupported request value type "Lunr\Corona\Tests\Helpers\MockRequestValue"'); | ||
|
||
$this->class->get(MockRequestValue::Foo); | ||
} | ||
|
||
/** | ||
* Test getting a parsed sapi | ||
*/ | ||
public function testGetSapi() | ||
{ | ||
$key = SapiValue::Sapi; | ||
|
||
$value = $this->class->get($key); | ||
|
||
$this->assertEquals(PHP_SAPI, $value); | ||
} | ||
|
||
} | ||
|
||
?> |
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,51 @@ | ||
<?php | ||
|
||
/** | ||
* This file contains the SapiParserTestCase class. | ||
* | ||
* SPDX-FileCopyrightText: Copyright 2025 Move Agency Group B.V., Zwolle, The Netherlands | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
namespace Lunr\Corona\Parsers\Sapi\Tests; | ||
|
||
use Lunr\Corona\Parsers\Sapi\SapiParser; | ||
use Lunr\Halo\LunrBaseTestCase; | ||
|
||
/** | ||
* This class contains test methods for the SapiParser class. | ||
* | ||
* @covers Lunr\Corona\Parsers\Sapi\SapiParser | ||
*/ | ||
abstract class SapiParserTestCase extends LunrBaseTestCase | ||
{ | ||
|
||
/** | ||
* Instance of the tested class. | ||
* @var SapiParser | ||
*/ | ||
protected SapiParser $class; | ||
|
||
/** | ||
* TestCase Constructor. | ||
*/ | ||
public function setUp(): void | ||
{ | ||
$this->class = new SapiParser(); | ||
|
||
parent::baseSetUp($this->class); | ||
} | ||
|
||
/** | ||
* TestCase Destructor. | ||
*/ | ||
public function tearDown(): void | ||
{ | ||
unset($this->class); | ||
|
||
parent::tearDown(); | ||
} | ||
|
||
} | ||
|
||
?> |
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