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 #14 from IlicMiljan/add-decryption-failure-placeho…
…lder Allow Placeholder Value When Decryption Fails
- Loading branch information
Showing
6 changed files
with
218 additions
and
9 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
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,25 @@ | ||
<?php | ||
|
||
namespace IlicMiljan\SecureProps\Exception; | ||
|
||
use RuntimeException; | ||
use Throwable; | ||
|
||
class SingleEncryptedAttributeExpected extends RuntimeException implements EncryptionServiceException | ||
{ | ||
public function __construct( | ||
private int $count, | ||
?Throwable $previous = null | ||
) { | ||
parent::__construct( | ||
'Each property must be annotated with a single instance of the Encrypted attribute.', | ||
0, | ||
$previous | ||
); | ||
} | ||
|
||
public function getCount(): int | ||
{ | ||
return $this->count; | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
|
||
namespace IlicMiljan\SecureProps\Tests\Attribute; | ||
|
||
use IlicMiljan\SecureProps\Attribute\Encrypted; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class EncryptedTest extends TestCase | ||
{ | ||
public function testCanBeCreated(): void | ||
{ | ||
$encrypted = new Encrypted(); | ||
|
||
$this->assertInstanceOf(Encrypted::class, $encrypted); | ||
} | ||
public function testCanRetrieveSpecifiedPlaceholder(): void | ||
{ | ||
$placeholder = "********"; | ||
$encryptedAttribute = new Encrypted(placeholder: $placeholder); | ||
|
||
$this->assertSame($placeholder, $encryptedAttribute->getPlaceholder()); | ||
} | ||
|
||
public function testDefaultPlaceholderIsNull(): void | ||
{ | ||
$encryptedAttribute = new Encrypted(); | ||
|
||
$this->assertNull($encryptedAttribute->getPlaceholder()); | ||
} | ||
} |
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