Skip to content

Commit

Permalink
Reorganizing Exceptions Namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
rotimi committed Feb 4, 2024
1 parent 2b03f7a commit 6e46c5d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
declare(strict_types=1);
namespace LeanOrm\Exceptions;

class CantDeleteReadOnlyRecordFromDBException extends \Exception{}

2 changes: 1 addition & 1 deletion src/LeanOrm/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -1768,7 +1768,7 @@ public function deleteSpecifiedRecord(\GDAO\Model\RecordInterface $record): ?boo
$msg = "ERROR: Can't delete ReadOnlyRecord from the database in "
. static::class . '::' . __FUNCTION__ . '(...).'
. PHP_EOL .'Undeleted record' . var_export($record, true) . PHP_EOL;
throw new \LeanOrm\CantDeleteReadOnlyRecordFromDBException($msg);
throw new \LeanOrm\Exceptions\CantDeleteReadOnlyRecordFromDBException($msg);
}

if(
Expand Down
4 changes: 2 additions & 2 deletions src/LeanOrm/Model/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(
* PDOException would be thrown if the deletion failed.
*
* @throws \PDOException
* @throws \LeanOrm\CantDeleteReadOnlyRecordFromDBException
* @throws \LeanOrm\Exceptions\CantDeleteReadOnlyRecordFromDBException
*/
public function deleteAll(): bool|array {

Expand All @@ -57,7 +57,7 @@ public function deleteAll(): bool|array {
$msg = "ERROR: Can't delete ReadOnlyRecord in Collection from the database in "
. static::class . '::' . __FUNCTION__ . '(...).'
. PHP_EOL .'Undeleted record' . var_export($record, true) . PHP_EOL;
throw new \LeanOrm\CantDeleteReadOnlyRecordFromDBException($msg);
throw new \LeanOrm\Exceptions\CantDeleteReadOnlyRecordFromDBException($msg);
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function deleteSpecifiedRecord(\GDAO\Model\RecordInterface $record): ?boo

public function testThatDeleteAllOnCollectionWithAtLeastOneReadOnlyRecordThrowsException() {

$this->expectException(\LeanOrm\CantDeleteReadOnlyRecordFromDBException::class);
$this->expectException(\LeanOrm\Exceptions\CantDeleteReadOnlyRecordFromDBException::class);

$model = new \LeanOrm\Model(
static::$dsn, static::$username ?? "", static::$password ?? "",
Expand All @@ -193,7 +193,7 @@ public function testThatDeleteAllOnCollectionWithAtLeastOneReadOnlyRecordThrowsE
$collection = new \LeanOrm\Model\Collection($model, ...$records);
self::assertCount(2, $collection); // 2 records in this collection

// Throws \LeanOrm\CantDeleteReadOnlyRecordFromDBException
// Throws \LeanOrm\Exceptions\CantDeleteReadOnlyRecordFromDBException
// because a ReadOnlyRecord exists in the collection
$collection->deleteAll();
} // public function testThatDeleteAllOnCollectionWithAtLeastOneReadOnlyRecordThrowsException()
Expand Down
2 changes: 1 addition & 1 deletion tests/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ public function testThatDeleteSpecifiedRecordWorksAsExpected() {

public function testThatDeleteSpecifiedRecordThrowsExceptionForReadOnlyRecords() {

$this->expectException(\LeanOrm\CantDeleteReadOnlyRecordFromDBException::class);
$this->expectException(\LeanOrm\Exceptions\CantDeleteReadOnlyRecordFromDBException::class);

$authorsModel = new $this->modelClass(static::$dsn, static::$username ?? "", static::$password ?? "",[],'author_id','authors');

Expand Down

0 comments on commit 6e46c5d

Please sign in to comment.