Skip to content

Commit

Permalink
+ Error test
Browse files Browse the repository at this point in the history
  • Loading branch information
EdmondDantes committed Nov 14, 2024
1 parent 8766a28 commit 21fa633
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Resource/ResourceDataWrong.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ResourceDataWrong extends ResourceException
public function __construct(mixed $resource, string $type = 'resource', string $format = 'format')
{
parent::__construct([
'resource' => $this->typeInfo($resource),
'resource' => !is_string($resource) ? $this->typeInfo($resource) : $resource,
'type' => $type,
'operation' => 'format:' . $format,
'format' => $format,
Expand Down
2 changes: 1 addition & 1 deletion src/Resource/ResourceNotExists.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ResourceNotExists extends ResourceException
public function __construct(mixed $resource, string $type = 'resource')
{
parent::__construct([
'resource' => $this->typeInfo($resource),
'resource' => !is_string($resource) ? $this->typeInfo($resource) : $resource,
'operation' => 'is_' . $type,
'type' => $type,
'system' => $this->system,
Expand Down
16 changes: 16 additions & 0 deletions tests/Resource/FileSystem/FileCloseErrorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace IfCastle\Exceptions\Resource\FileSystem;

use PHPUnit\Framework\TestCase;

class FileCloseErrorTest extends TestCase
{
public function test(): void
{
$exception = new FileCloseError('file.txt');
$this->assertEquals("'FileSystem' error: operation 'close' for the resource 'file.txt' ('file') is failed. FileSystem error: operation \"close\" failed", $exception->getMessage());
}
}
16 changes: 16 additions & 0 deletions tests/Resource/FileSystem/FileLockFailedTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace IfCastle\Exceptions\Resource\FileSystem;

use PHPUnit\Framework\TestCase;

class FileLockFailedTest extends TestCase
{
public function test(): void
{
$exception = new FileLockFailed('file.txt');
$this->assertEquals("'FileSystem' error: operation 'lock' for the resource 'file.txt' ('file') is failed. FileSystem error: operation \"lock\" failed", $exception->getMessage());
}
}
16 changes: 16 additions & 0 deletions tests/Resource/FileSystem/FileNotExistsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace IfCastle\Exceptions\Resource\FileSystem;

use PHPUnit\Framework\TestCase;

class FileNotExistsTest extends TestCase
{
public function test(): void
{
$exception = new FileNotExists('file.txt');
$this->assertEquals("'FileSystem' error: 'file' is not exist. Resource: 'STRING', Operation: 'is_file'", $exception->getMessage());
}
}
17 changes: 17 additions & 0 deletions tests/Resource/FileSystem/FileNotReadableTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace IfCastle\Exceptions\Resource\FileSystem;

use PHPUnit\Framework\TestCase;

class FileNotReadableTest extends TestCase
{
public function testNotReadable(): void
{
$exception = new FileNotReadable('file.txt', 'file');

$this->assertEquals("'FileSystem' error: operation 'readable' for the resource 'file.txt' ('file') is failed. FileSystem error: operation \"readable\" failed", $exception->getMessage());
}
}
23 changes: 23 additions & 0 deletions tests/Resource/FileSystem/FileUnLockFailedTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace IfCastle\Exceptions\Resource\FileSystem;

use PHPUnit\Framework\TestCase;

class FileUnLockFailedTest extends TestCase
{
public function test(): void
{
$exception = new FileUnLockFailed('file', 'string');

$this->assertEquals([
'resource' => 'file',
'type' => 'string',
'operation' => 'unlock',
'system' => 'FileSystem',
'message' => 'FileSystem error: operation "unlock" failed',
], $exception->getExceptionData());
}
}
2 changes: 1 addition & 1 deletion tests/Resource/ResourceDataWrongTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function test(): void
$exception = new ResourceDataWrong('resource', 'string', 'string');

$this->assertEquals([
'resource' => 'STRING',
'resource' => 'resource',
'type' => 'string',
'operation' => 'format:string',
'format' => 'string',
Expand Down
2 changes: 1 addition & 1 deletion tests/Resource/ResourceNotExistsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public function testNotExists(): void
{
$exception = new ResourceNotExists('file.txt', 'file');

$this->assertEquals("'undefined' error: 'file' is not exist. Resource: 'STRING', Operation: 'is_file'", $exception->getMessage());
$this->assertEquals("'undefined' error: 'file' is not exist. Resource: 'file.txt', Operation: 'is_file'", $exception->getMessage());
}
}

0 comments on commit 21fa633

Please sign in to comment.