create(); $characters = Character::factory(2)->create(); Card::factory()->count(2)->for($raids[0])->create(['jackpot' => 0]); Card::factory()->count(2)->for($raids[1])->create(['jackpot' => 0]); Card::factory()->count(2)->for($characters[0])->create(['jackpot' => 0]); Card::factory()->count(2)->for($characters[1])->create(['jackpot' => 0]); Card::factory()->count(2)->create(['role' => 'dps', 'jackpot' => 0]); Card::factory()->count(2)->create(['role' => 'tank', 'jackpot' => 0]); Card::factory()->count(2)->create(['class' => 'priest', 'jackpot' => 0]); Card::factory()->count(2)->create(['class' => 'warrior', 'jackpot' => 0]); Card::factory()->count(2)->create(['jackpot' => 0]); $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); } } public function test_get_with_jackpot_cards() { Card::factory()->count(10)->create(['jackpot' => 1]); $cards = Card::getBySettings(new GameSettings(), 4, 2); $this->assertSame(4, count($cards)); $jackpot_count = 0; foreach ($cards as $card) { if ($card->jackpot != 0) { $jackpot_count++; } } $this->assertEquals(2, $jackpot_count); } }