Skip to content

Commit

Permalink
+ more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EdmondDantes committed Nov 15, 2024
1 parent 7eb0afc commit 2a7f6e5
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/ClassNotExist.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(array|string $class)
if (!\is_scalar($class)) {
parent::__construct($class);
} else {
parent::__construct(['class' => $class ]);
parent::__construct(['class' => $class]);
}
}
}
2 changes: 1 addition & 1 deletion src/InterfaceNotImplemented.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(object|array|string $class, string $interface)
parent::__construct($class);
} else {
parent::__construct([
'class' => $this->typeInfo($class),
'class' => is_string($class) ? $class : $this->typeInfo($class),
'interface' => $interface,
]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/RequiredValueEmpty.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
class RequiredValueEmpty extends LoggableException
{
protected string $template = 'The Required value {name} is empty ({expected})';
protected string $template = 'The Required value {name} is empty (expected: {expected})';

/**
* If required value is empty.
Expand Down
5 changes: 2 additions & 3 deletions src/SerializeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
class SerializeException extends LoggableException
{
protected string $template = 'Serialize process was failed (type:{type}, object:{object}, src:{srcObject}). {reason}';
protected string $template = 'Serialize process was failed (type:{type}, object:{object}, src:{srcObject})';

/**
* Object can't be serialized!
Expand All @@ -27,8 +27,7 @@ public function __construct(array|string $reason, $object = null, string $type =
}

parent::__construct([
'message' => 'Serialize Failed',
'reason' => $reason,
'message' => $reason,
'type' => $type,
'object' => $this->typeInfo($object),
'srcObject' => $this->typeInfo($srcObject),
Expand Down
19 changes: 19 additions & 0 deletions tests/InterfaceNotImplementedTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace IfCastle\Exceptions;

use PHPUnit\Framework\TestCase;

class InterfaceNotImplementedTest extends TestCase
{
public function test(): void
{
$exception = new InterfaceNotImplemented('myClassName', 'Interface');
$this->assertEquals("Class 'myClassName' does not implement interface 'Interface'", $exception->getMessage());

$exception = new InterfaceNotImplemented(new \stdClass(), 'Interface');
$this->assertEquals("Class 'stdClass' does not implement interface 'Interface'", $exception->getMessage());
}
}
17 changes: 17 additions & 0 deletions tests/ObjectNotInitializedTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace IfCastle\Exceptions;

use PHPUnit\Framework\TestCase;

class ObjectNotInitializedTest extends TestCase
{
public function test(): void
{
$exception = new ObjectNotInitialized('name', 'Additional message');

$this->assertEquals("Object 'STRING' is not initialized. Additional message", $exception->getMessage());
}
}
17 changes: 17 additions & 0 deletions tests/RecursionLimitExceededTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace IfCastle\Exceptions;

use PHPUnit\Framework\TestCase;

class RecursionLimitExceededTest extends TestCase
{
public function test(): void
{
$exception = new RecursionLimitExceeded(12);

$this->assertEquals("Recursion limit exceeded: '12'", $exception->getMessage());
}
}
17 changes: 17 additions & 0 deletions tests/RequiredValueEmptyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace IfCastle\Exceptions;

use PHPUnit\Framework\TestCase;

class RequiredValueEmptyTest extends TestCase
{
public function test(): void
{
$exception = new RequiredValueEmpty('name', 'string3');

$this->assertEquals("The Required value 'name' is empty (expected: 'string3')", $exception->getMessage());
}
}
17 changes: 17 additions & 0 deletions tests/SerializeExceptionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace IfCastle\Exceptions;

use PHPUnit\Framework\TestCase;

class SerializeExceptionTest extends TestCase
{
public function test(): void
{
$exception = new SerializeException('reason', new \stdClass(), 'phpserialize', new \stdClass());

$this->assertEquals("Serialize process was failed (type:'phpserialize', object:'stdClass', src:'stdClass'). reason", $exception->getMessage());
}
}

0 comments on commit 2a7f6e5

Please sign in to comment.