예제 #1
0
 public function testRelationshipWith32Uuid()
 {
     $firstUser = Eloquent32UserModel::create(['username' => 'first-user', 'password' => 'secret']);
     $secondUser = Eloquent32UserModel::create(['username' => 'second-user', 'password' => 'secret']);
     $postsForFirstUser = [];
     $postsForSecondUser = [];
     for ($i = 0; $i < 10; $i++) {
         $postsForFirstUser[] = new Eloquent32PostModel(['name' => 'First user - post ' . $i]);
         $postsForSecondUser[] = Eloquent32PostModel::create(['name' => 'Second user - post ' . $i, 'user_id' => $secondUser->id]);
     }
     $firstUser->posts()->saveMany($postsForFirstUser);
     $this->assertEquals(10, $firstUser->posts()->count());
     $this->assertEquals(10, $secondUser->posts()->count());
 }
예제 #2
0
 public function testManyToManyRelationshipsWithChar32()
 {
     $firstUser = Eloquent32UserModel::create(['username' => 'first-user', 'password' => 'secret']);
     $secondUser = Eloquent32UserModel::create(['username' => 'second-user', 'password' => 'secret']);
     $thirdUser = Eloquent32UserModel::create(['username' => 'third-user', 'password' => 'secret']);
     $firstRole = Eloquent32RoleModel::create(['name' => 'Sailor']);
     $secondRole = Eloquent32RoleModel::create(['name' => 'Cook']);
     $thirdRole = Eloquent32RoleModel::create(['name' => 'Pirate']);
     $firstUser->roles()->attach([$firstRole->id, $secondRole->id]);
     $crusoe = Eloquent32UserModel::find($firstUser->id);
     $this->assertEquals(2, $crusoe->roles()->count());
     $secondUser->roles()->attach([$firstRole->id, $secondRole->id]);
     $secondUser->roles()->sync([$secondRole->id, $thirdRole->id]);
     $crusoe = Eloquent32UserModel::find($secondUser->id);
     $found = false;
     foreach ($crusoe->roles as $role) {
         if ($role->id === $thirdRole->id) {
             $found = true;
         }
     }
     $this->assertTrue($found);
 }