Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Repository/MongoDBRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ public function find(string $id): object|null

public function remove(string ...$id): void
{
$id = array_values($id);

if (count($id) === 1) {
$this->collection->deleteOne($this->withDiscriminator(['_id' => $id[0]]));

Expand Down
2 changes: 2 additions & 0 deletions src/Repository/RangoRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ public function find(string $id): object|null

public function remove(string ...$id): void
{
$id = array_values($id);

if (count($id) === 1) {
$this->collection->deleteOne($this->withDiscriminator(['_id' => $id[0]]));

Expand Down
28 changes: 28 additions & 0 deletions tests/Integration/RepositoryTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,34 @@ public function testRemoveMany(): void
self::assertSame(1, $repository->count());
}

public function testWriteOperationsAcceptStringKeyedArguments(): void
{
$repository = $this->repositoryManager->get(Profile::class);

$repository->insert(...['first' => new Profile('r-1', 'Rango', Status::ACTIVE, [new Skill('php')])]);
$repository->insert(...[
'second' => new Profile('r-2', 'Beans', Status::INACTIVE, [new Skill('js')]),
'third' => new Profile('r-3', 'Elsa', Status::ACTIVE, [new Skill('go')]),
]);

self::assertSame(3, $repository->count());

$repository->update(...['first' => new Profile('r-1', 'Rango Updated', Status::ACTIVE, [new Skill('php')])]);
$repository->update(...[
'second' => new Profile('r-2', 'Beans Updated', Status::INACTIVE, [new Skill('js')]),
'third' => new Profile('r-3', 'Elsa Updated', Status::ACTIVE, [new Skill('go')]),
]);

self::assertSame('Rango Updated', $repository->get('r-1')->name);
self::assertSame('Beans Updated', $repository->get('r-2')->name);
self::assertSame('Elsa Updated', $repository->get('r-3')->name);

$repository->remove(...['first' => 'r-1']);
$repository->remove(...['second' => 'r-2', 'third' => 'r-3']);

self::assertSame(0, $repository->count());
}

public function testDropCollection(): void
{
$repository = $this->repositoryManager->get(Profile::class);
Expand Down
Loading