-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from itk-devops/develop
Allow PHP 8.3 and Symfony 7.0
- Loading branch information
Showing
7 changed files
with
218 additions
and
19 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 |
---|---|---|
|
@@ -16,6 +16,7 @@ jobs: | |
- "8.0" | ||
- "8.1" | ||
- "8.2" | ||
- "8.3" | ||
include: | ||
- php-version: "8.0" | ||
phpunit: "9.5" | ||
|
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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Asm\Ansible\Utils; | ||
|
||
use JsonException; | ||
|
||
class Str | ||
{ | ||
/** | ||
* Validate the provided string is JSON formatted. | ||
* | ||
* Not JSON if result is not an object (stdClass). | ||
* Silent return false on exceptions e.g. Invalid/Incorrect encoding, Array depth more than 512 etc. | ||
* | ||
* @param string $value | ||
* @return bool | ||
*/ | ||
public static function isJsonFormatted(string $value): bool | ||
{ | ||
try { | ||
return is_object(json_decode($value, false, 512, JSON_THROW_ON_ERROR)); | ||
} catch (JsonException) { | ||
return false; | ||
} | ||
} | ||
} |
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,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Asm\Ansible\Utils; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @group utils | ||
*/ | ||
class StrTest extends TestCase | ||
{ | ||
/** | ||
* Assert valid JSON string is correctly checked. | ||
* | ||
* @return void | ||
*/ | ||
public function testJsonWithValidFormat(): void | ||
{ | ||
$value = '{ "key1": "value1" }'; | ||
|
||
$this->assertTrue(Str::isJsonFormatted($value)); | ||
} | ||
|
||
/** | ||
* Assert string is not valid JSON. | ||
* | ||
* @return void | ||
*/ | ||
public function testStringIsNotJson(): void | ||
{ | ||
$value = 'something'; | ||
|
||
$this->assertFalse(Str::isJsonFormatted($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