create(); $characters = Character::factory(2)->create(); Card::factory()->count(2)->for($raids[0])->create(); Card::factory()->count(2)->for($raids[1])->create(); Card::factory()->count(2)->for($characters[0])->create(); Card::factory()->count(2)->for($characters[1])->create(); Card::factory()->count(2)->create(['role' => 'dps']); Card::factory()->count(2)->create(['role' => 'tank']); Card::factory()->count(2)->create(['class' => 'priest']); Card::factory()->count(2)->create(['class' => 'warrior']); Card::factory()->count(2)->create(); $this->raids = $raids->pluck('id'); $this->characters = $characters->pluck('id'); } public function provider(): array { return [ [ [ 0 ], 16 ], [ [ 0, 1 ], 18 ], ]; } public function providerClasses(): array { return [ [ [ 'priest' ], 16 ], [ [ 'priest', 'warrior' ], 18 ], ]; } public function providerRoles(): array { return [ [ [ 'dps' ], 16 ], [ [ 'dps', 'tank' ], 18 ], ]; } /** * @dataProvider provider */ public function test_get_with_character_settings($characters, $count) { $settings = new GameSettings(); foreach($characters as $i) { $settings->characters->set($this->characters[$i]); } $cards = Card::getBySettings($settings); $this->assertSame($count, count($cards)); $expected = collect($characters)->map(function($i) { return $this->characters[$i]; })->push(null); foreach($cards as $card) { $this->assertContains($card->character_id, $expected, $cards->pluck('character_id')); } } /** * @dataProvider provider */ public function test_get_with_raid_settings($raids, $count) { $settings = new GameSettings(); foreach($raids as $i) { $settings->raids->set($this->raids[$i]); } $cards = Card::getBySettings($settings); $this->assertSame($count, count($cards)); $expected = collect($raids)->map(function($item) { return $this->raids[$item]; })->push(null); foreach($cards as $card) { $this->assertContains($card->raid_id, $expected); } } /** * @dataProvider providerClasses */ public function test_get_with_class_settings($classes, $count) { $settings = new GameSettings(); foreach($classes as $class) { $settings->classes->set($class); } $cards = Card::getBySettings($settings); $this->assertSame($count, count($cards)); $expected = collect($classes)->push(null); foreach($cards as $card) { $this->assertContains($card->class, $expected); } } /** * @dataProvider providerRoles */ public function test_get_with_role_settings($roles, $count) { $settings = new GameSettings(); foreach($roles as $role) { $settings->roles->set($role); } $cards = Card::getBySettings($settings); $this->assertSame($count, count($cards)); $expected = collect($roles)->push(null); foreach($cards as $card) { $this->assertContains($card->role, $expected); } } }