Skip to content

Commit

Permalink
Merge pull request #5 from IlicMiljan/add-cache-and-reader-tests
Browse files Browse the repository at this point in the history
Add `Cache` and `Reader` Unit Tests
  • Loading branch information
IlicMiljan authored Mar 10, 2024
2 parents e94a387 + fd6d71b commit ba76fac
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/Cache/Exception/InvalidCacheKeyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace IlicMiljan\SecureProps\Tests\Cache\Exception;

use IlicMiljan\SecureProps\Cache\Exception\InvalidCacheKey;
use LogicException;
use PHPUnit\Framework\TestCase;

class InvalidCacheKeyTest extends TestCase
{
private string $cacheKey;

protected function setUp(): void
{
$this->cacheKey = 'invalidKey';
}

public function testCanBeCreated(): void
{
$exception = new InvalidCacheKey($this->cacheKey);

$this->assertInstanceOf(InvalidCacheKey::class, $exception);
}

public function testReturnsCacheKey(): void
{
$exception = new InvalidCacheKey($this->cacheKey);

$this->assertEquals($this->cacheKey, $exception->getCacheKey());
}

public function testPreviousExceptionIsStored(): void
{
$previous = new LogicException('Previous exception');
$exception = new InvalidCacheKey($this->cacheKey, $previous);

$this->assertSame($previous, $exception->getPrevious());
}
}
47 changes: 47 additions & 0 deletions tests/Reader/Exception/ObjectPropertyNotFoundTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace IlicMiljan\SecureProps\Tests\Reader\Exception;

use IlicMiljan\SecureProps\Reader\Exception\ObjectPropertyNotFound;
use IlicMiljan\SecureProps\Reader\Exception\ReaderException;
use PHPUnit\Framework\TestCase;
use RuntimeException;

class ObjectPropertyNotFoundTest extends TestCase
{
private string $className;

protected function setUp(): void
{
$this->className = 'TestClass';
}

public function testCanBeCreated(): void
{
$exception = new ObjectPropertyNotFound($this->className);

$this->assertInstanceOf(ObjectPropertyNotFound::class, $exception);
}

public function testReturnsClassName(): void
{
$exception = new ObjectPropertyNotFound($this->className);

$this->assertEquals($this->className, $exception->getClassName());
}

public function testPreviousExceptionIsStored(): void
{
$previous = new RuntimeException('Previous exception');
$exception = new ObjectPropertyNotFound($this->className, $previous);

$this->assertSame($previous, $exception->getPrevious());
}

public function testImplementsReaderExceptionInterface(): void
{
$exception = new ObjectPropertyNotFound($this->className);

$this->assertInstanceOf(ReaderException::class, $exception);
}
}

0 comments on commit ba76fac

Please sign in to comment.