From f7db4add5b195b65644fd0b4c63a0e58467de2e9 Mon Sep 17 00:00:00 2001 From: Miljan Ilic Date: Sun, 10 Mar 2024 18:54:54 +0100 Subject: [PATCH] Add Tests for New Exceptions --- .../Cipher/Exception/InvalidKeyLengthTest.php | 47 +++++++++++++++++++ tests/Exception/ValueMustBeObjectTest.php | 47 +++++++++++++++++++ tests/Exception/ValueMustBeStringTest.php | 47 +++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 tests/Cipher/Exception/InvalidKeyLengthTest.php create mode 100644 tests/Exception/ValueMustBeObjectTest.php create mode 100644 tests/Exception/ValueMustBeStringTest.php diff --git a/tests/Cipher/Exception/InvalidKeyLengthTest.php b/tests/Cipher/Exception/InvalidKeyLengthTest.php new file mode 100644 index 0000000..86186ff --- /dev/null +++ b/tests/Cipher/Exception/InvalidKeyLengthTest.php @@ -0,0 +1,47 @@ +expectedLength = 32; + } + + public function testCanBeCreated(): void + { + $exception = new InvalidKeyLength($this->expectedLength); + + $this->assertInstanceOf(InvalidKeyLength::class, $exception); + } + + public function testReturnsExpectedLength(): void + { + $exception = new InvalidKeyLength($this->expectedLength); + + $this->assertEquals($this->expectedLength, $exception->getExpectedLength()); + } + + public function testPreviousExceptionIsStored(): void + { + $previous = new RuntimeException('Previous exception'); + $exception = new InvalidKeyLength($this->expectedLength, $previous); + + $this->assertSame($previous, $exception->getPrevious()); + } + + public function testImplementsCipherExceptionInterface(): void + { + $exception = new InvalidKeyLength($this->expectedLength); + + $this->assertInstanceOf(CipherException::class, $exception); + } +} diff --git a/tests/Exception/ValueMustBeObjectTest.php b/tests/Exception/ValueMustBeObjectTest.php new file mode 100644 index 0000000..3008f29 --- /dev/null +++ b/tests/Exception/ValueMustBeObjectTest.php @@ -0,0 +1,47 @@ +type = 'string'; + } + + public function testCanBeCreated(): void + { + $exception = new ValueMustBeObject($this->type); + + $this->assertInstanceOf(ValueMustBeObject::class, $exception); + } + + public function testReturnsType(): void + { + $exception = new ValueMustBeObject($this->type); + + $this->assertEquals($this->type, $exception->getType()); + } + + public function testPreviousExceptionIsStored(): void + { + $previous = new RuntimeException('Previous exception'); + $exception = new ValueMustBeObject($this->type, $previous); + + $this->assertSame($previous, $exception->getPrevious()); + } + + public function testImplementsEncryptionServiceExceptionInterface(): void + { + $exception = new ValueMustBeObject($this->type); + + $this->assertInstanceOf(EncryptionServiceException::class, $exception); + } +} diff --git a/tests/Exception/ValueMustBeStringTest.php b/tests/Exception/ValueMustBeStringTest.php new file mode 100644 index 0000000..f6dc2f2 --- /dev/null +++ b/tests/Exception/ValueMustBeStringTest.php @@ -0,0 +1,47 @@ +type = 'object'; + } + + public function testCanBeCreated(): void + { + $exception = new ValueMustBeString($this->type); + + $this->assertInstanceOf(ValueMustBeString::class, $exception); + } + + public function testReturnsType(): void + { + $exception = new ValueMustBeString($this->type); + + $this->assertEquals($this->type, $exception->getType()); + } + + public function testPreviousExceptionIsStored(): void + { + $previous = new RuntimeException('Previous exception'); + $exception = new ValueMustBeString($this->type, $previous); + + $this->assertSame($previous, $exception->getPrevious()); + } + + public function testImplementsEncryptionServiceExceptionInterface(): void + { + $exception = new ValueMustBeString($this->type); + + $this->assertInstanceOf(EncryptionServiceException::class, $exception); + } +}