Skip to content

Commit

Permalink
Add delete() method in PersistenceRepositoryInterface::class. (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw authored Nov 11, 2023
1 parent 644932b commit 1eeac3a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Repository/PersistenceRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

final class PersistenceRepository extends Repository implements PersistenceRepositoryInterface
{
public function delete(ActiveRecordInterface $ar): bool
{
return $this->execute($ar->getDb(), static fn (): bool => $ar->delete() > 0);
}

public function deleteAll(ActiveRecordInterface $ar, array $condition): bool
{
return $this->execute($ar->getDb(), static fn (): bool => $ar->deleteAll($condition) > 0);
Expand Down
9 changes: 9 additions & 0 deletions src/Repository/PersistenceRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
*/
interface PersistenceRepositoryInterface
{
/**
* Delete a record from the data store.
*
* @param ActiveRecordInterface $ar The ActiveRecord model instance to be deleted.
*
* @return bool Whether the deletion was successful.
*/
public function delete(ActiveRecordInterface $ar): bool;

/**
* Delete records based on a set of conditions.
*
Expand Down
14 changes: 14 additions & 0 deletions tests/Repository/PersistenceRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ final class PersistenceRepositoryTest extends TestCase
{
use TestSupport;

public function testDelete(): void
{
$ar = new Stub();

$ar->content = 'tests';

$this->assertTrue($ar->save());

$persistenceRepository = new PersistenceRepository();

$this->assertTrue($persistenceRepository->delete($ar));
$this->assertNull($ar->findOne(1));
}

public function testDeleteAll(): void
{
$ar = new Stub();
Expand Down

0 comments on commit 1eeac3a

Please sign in to comment.