diff --git a/src/Repository/MongoDBRepository.php b/src/Repository/MongoDBRepository.php index 0ae81d7..fb8de09 100644 --- a/src/Repository/MongoDBRepository.php +++ b/src/Repository/MongoDBRepository.php @@ -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]])); diff --git a/src/Repository/RangoRepository.php b/src/Repository/RangoRepository.php index 59279a6..e9a1c8e 100644 --- a/src/Repository/RangoRepository.php +++ b/src/Repository/RangoRepository.php @@ -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]])); diff --git a/tests/Integration/RepositoryTestCase.php b/tests/Integration/RepositoryTestCase.php index 248e9d4..760859b 100644 --- a/tests/Integration/RepositoryTestCase.php +++ b/tests/Integration/RepositoryTestCase.php @@ -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);