Пример #1
0
 public function testIfWillFindAllByCompositePks()
 {
     $pks[] = ['primaryOne' => new \MongoId(), 'primaryTwo' => 1, 'primaryThree' => 'one', 'title' => 'xxx'];
     $pks[] = ['primaryOne' => new \MongoId(), 'primaryTwo' => 2, 'primaryThree' => 'two', 'title' => 'yyy'];
     $pks[] = ['primaryOne' => new \MongoId(), 'primaryTwo' => 3, 'primaryThree' => 'three', 'title' => 'zzz'];
     foreach ($pks as $i => $keys) {
         $model = new CompositePrimaryKey();
         $em = new EntityManager($model);
         foreach ($keys as $field => $value) {
             $model->{$field} = $value;
         }
         $em->insert();
     }
     $model = new CompositePrimaryKey();
     $em = new EntityManager($model);
     $model->primaryOne = new \MongoId();
     $model->primaryTwo = 12;
     $model->primaryThree = 'ddd';
     $em->insert();
     $finder = new Finder($model);
     $all = $finder->findAllByPk($pks);
     $this->assertSame(3, count($all));
     foreach ($all as $found) {
         $this->assertInstanceof(CompositePrimaryKey::class, $found);
         $this->assertTrue(in_array($found->title, ['xxx', 'yyy', 'zzz']));
     }
 }