Skip to content

Commit

Permalink
Add Tests for New Exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
ilicmiljan committed Mar 10, 2024
1 parent b4ef7f9 commit f7db4ad
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/Cipher/Exception/InvalidKeyLengthTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace IlicMiljan\SecureProps\Tests\Cipher\Exception;

use IlicMiljan\SecureProps\Cipher\Exception\CipherException;
use IlicMiljan\SecureProps\Cipher\Exception\InvalidKeyLength;
use PHPUnit\Framework\TestCase;
use RuntimeException;

class InvalidKeyLengthTest extends TestCase
{
private int $expectedLength;

protected function setUp(): void
{
$this->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);
}
}
47 changes: 47 additions & 0 deletions tests/Exception/ValueMustBeObjectTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace IlicMiljan\SecureProps\Tests\Exception;

use IlicMiljan\SecureProps\Exception\EncryptionServiceException;
use IlicMiljan\SecureProps\Exception\ValueMustBeObject;
use PHPUnit\Framework\TestCase;
use RuntimeException;

class ValueMustBeObjectTest extends TestCase
{
private string $type;

protected function setUp(): void
{
$this->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);
}
}
47 changes: 47 additions & 0 deletions tests/Exception/ValueMustBeStringTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace IlicMiljan\SecureProps\Tests\Exception;

use IlicMiljan\SecureProps\Exception\EncryptionServiceException;
use IlicMiljan\SecureProps\Exception\ValueMustBeString;
use PHPUnit\Framework\TestCase;
use RuntimeException;

class ValueMustBeStringTest extends TestCase
{
private string $type;

protected function setUp(): void
{
$this->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);
}
}

0 comments on commit f7db4ad

Please sign in to comment.