Skip to content

Commit ba76fac

Browse files
authored
Merge pull request #5 from IlicMiljan/add-cache-and-reader-tests
Add `Cache` and `Reader` Unit Tests
2 parents e94a387 + fd6d71b commit ba76fac

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace IlicMiljan\SecureProps\Tests\Cache\Exception;
4+
5+
use IlicMiljan\SecureProps\Cache\Exception\InvalidCacheKey;
6+
use LogicException;
7+
use PHPUnit\Framework\TestCase;
8+
9+
class InvalidCacheKeyTest extends TestCase
10+
{
11+
private string $cacheKey;
12+
13+
protected function setUp(): void
14+
{
15+
$this->cacheKey = 'invalidKey';
16+
}
17+
18+
public function testCanBeCreated(): void
19+
{
20+
$exception = new InvalidCacheKey($this->cacheKey);
21+
22+
$this->assertInstanceOf(InvalidCacheKey::class, $exception);
23+
}
24+
25+
public function testReturnsCacheKey(): void
26+
{
27+
$exception = new InvalidCacheKey($this->cacheKey);
28+
29+
$this->assertEquals($this->cacheKey, $exception->getCacheKey());
30+
}
31+
32+
public function testPreviousExceptionIsStored(): void
33+
{
34+
$previous = new LogicException('Previous exception');
35+
$exception = new InvalidCacheKey($this->cacheKey, $previous);
36+
37+
$this->assertSame($previous, $exception->getPrevious());
38+
}
39+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace IlicMiljan\SecureProps\Tests\Reader\Exception;
4+
5+
use IlicMiljan\SecureProps\Reader\Exception\ObjectPropertyNotFound;
6+
use IlicMiljan\SecureProps\Reader\Exception\ReaderException;
7+
use PHPUnit\Framework\TestCase;
8+
use RuntimeException;
9+
10+
class ObjectPropertyNotFoundTest extends TestCase
11+
{
12+
private string $className;
13+
14+
protected function setUp(): void
15+
{
16+
$this->className = 'TestClass';
17+
}
18+
19+
public function testCanBeCreated(): void
20+
{
21+
$exception = new ObjectPropertyNotFound($this->className);
22+
23+
$this->assertInstanceOf(ObjectPropertyNotFound::class, $exception);
24+
}
25+
26+
public function testReturnsClassName(): void
27+
{
28+
$exception = new ObjectPropertyNotFound($this->className);
29+
30+
$this->assertEquals($this->className, $exception->getClassName());
31+
}
32+
33+
public function testPreviousExceptionIsStored(): void
34+
{
35+
$previous = new RuntimeException('Previous exception');
36+
$exception = new ObjectPropertyNotFound($this->className, $previous);
37+
38+
$this->assertSame($previous, $exception->getPrevious());
39+
}
40+
41+
public function testImplementsReaderExceptionInterface(): void
42+
{
43+
$exception = new ObjectPropertyNotFound($this->className);
44+
45+
$this->assertInstanceOf(ReaderException::class, $exception);
46+
}
47+
}

0 commit comments

Comments
 (0)