Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Cache and Reader Unit Tests #5

Merged
merged 2 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading