Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3c6faff

Browse files
authored
fix: RepositoryAssertion::exist() $criteria should allow mixed (#1007)
1 parent 81cc97d commit 3c6faff

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

src/Persistence/RepositoryAssertions.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,20 @@ public function countLessThanOrEqual(int $expected, array $criteria = [], string
113113

114114
public function exists(mixed $criteria, string $message = 'Expected {entity} to exist but it does not.'): self
115115
{
116-
Assert::that($this->repository->count($criteria))
117-
->isGreaterThan(0, $message, [
118-
'entity' => $this->repository->getClassName(),
119-
'criteria' => $criteria,
120-
]);
116+
Assert::that($this->repository->find($criteria))->isNotEmpty($message, [
117+
'entity' => $this->repository->getClassName(),
118+
'criteria' => $criteria,
119+
]);
121120

122121
return $this;
123122
}
124123

125124
public function notExists(mixed $criteria, string $message = 'Expected {entity} to not exist but it does.'): self
126125
{
127-
Assert::that($this->repository->count($criteria))
128-
->is(0, $message, [
129-
'entity' => $this->repository->getClassName(),
130-
'criteria' => $criteria,
131-
]);
126+
Assert::that($this->repository->find($criteria))->isEmpty($message, [
127+
'entity' => $this->repository->getClassName(),
128+
'criteria' => $criteria,
129+
]);
132130

133131
return $this;
134132
}

tests/Integration/Persistence/GenericFactoryTestCase.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ public function repository_assertions(): void
490490
$assert->empty();
491491
$assert->empty(['prop1' => 'a']);
492492

493-
static::factory()::createOne(['prop1' => 'a']);
493+
$object = static::factory()::createOne(['prop1' => 'a']);
494494
static::factory()::createOne(['prop1' => 'b']);
495495
static::factory()::createOne(['prop1' => 'b']);
496496

@@ -508,6 +508,9 @@ public function repository_assertions(): void
508508
$assert->countLessThanOrEqual(2, ['prop1' => 'b']);
509509
$assert->exists(['prop1' => 'a']);
510510
$assert->notExists(['prop1' => 'c']);
511+
512+
$assert->exists($object->id);
513+
$assert->notExists(999);
511514
}
512515

513516
/**

0 commit comments

Comments
 (0)