Issues (36)

tests/Unit/QuizTest.php (5 issues)

1
<?php
2
3
namespace Tests\Unit;
4
5
use App\Models\Question;
6
use App\Models\Quiz;
7
use Illuminate\Foundation\Testing\RefreshDatabase;
8
use Tests\TestCase;
9
10
class QuizTest extends TestCase
11
{
12
    use RefreshDatabase;
0 ignored issues
show
The trait Illuminate\Foundation\Testing\RefreshDatabase requires some properties which are not provided by Tests\Unit\QuizTest: $seeder, $seed, $connectionsToTransact, $dropTypes, $dropViews
Loading history...
13
14
    /**
15
     * Public Quizzes Test.
16
     *
17
     * @return void
18
     */
19
    public function test_quiz_public_scope()
20
    {
21
        $created_quizzes = Quiz::factory()->count(10)->public()->create();
22
23
        $quizzes = Quiz::public()->get();
24
25
        $this->assertSameSize($created_quizzes, $quizzes);
26
27
        $this->assertEquals(1, $quizzes->random()->status);
28
    }
29
30
    /**
31
     * Filtering quizzes by author test.
32
     *
33
     * @return void
34
     */
35
    public function test_quiz_of_author_scope()
36
    {
37
        $created_quizzes = Quiz::factory()->count(10)->create([
38
            'author_id' => 1,
39
        ]);
40
41
        $quizzes = Quiz::ofAuthor(1)->get();
42
43
        $this->assertSameSize($created_quizzes, $quizzes);
0 ignored issues
show
It seems like $created_quizzes can also be of type Illuminate\Database\Eloquent\Model; however, parameter $expected of PHPUnit\Framework\Assert::assertSameSize() does only seem to accept Countable|iterable, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

43
        $this->assertSameSize(/** @scrutinizer ignore-type */ $created_quizzes, $quizzes);
Loading history...
44
        $this->assertEquals(1, $quizzes->random()->author_id);
45
    }
46
47
    /**
48
     * Filtering except author test.
49
     *
50
     * @return void
51
     */
52
    public function test_quiz_except_author_scope()
53
    {
54
        $created_quizzes = Quiz::factory()->count(10)->create([
55
            'author_id' => rand(2, 10),
56
        ]);
57
58
        $quizzes = Quiz::exceptAuthor(1)->get();
59
60
        $this->assertSameSize($created_quizzes, $quizzes);
0 ignored issues
show
It seems like $created_quizzes can also be of type Illuminate\Database\Eloquent\Model; however, parameter $expected of PHPUnit\Framework\Assert::assertSameSize() does only seem to accept Countable|iterable, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

60
        $this->assertSameSize(/** @scrutinizer ignore-type */ $created_quizzes, $quizzes);
Loading history...
61
        $this->assertNotEquals(1, $quizzes->random()->author_id);
62
    }
63
64
    /**
65
     * Search by string in Quiz name test.
66
     *
67
     * @return void
68
     */
69
    public function test_quiz_searchBy_scope()
70
    {
71
        $created_quizzes = Quiz::factory()->count(10)->create();
72
73
        $quizzes = Quiz::searchBy('a')->get();
74
75
        $filtered = $created_quizzes->filter(function ($item, $key) {
0 ignored issues
show
The parameter $key is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

75
        $filtered = $created_quizzes->filter(function ($item, /** @scrutinizer ignore-unused */ $key) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
76
            return stripos($item->name, 'a') !== false; // Case in-sensitive search
77
        });
78
79
        $this->assertSameSize($filtered, $quizzes);
0 ignored issues
show
It seems like $filtered can also be of type Illuminate\Database\Eloquent\Builder and Illuminate\Database\Eloquent\Model; however, parameter $expected of PHPUnit\Framework\Assert::assertSameSize() does only seem to accept Countable|iterable, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

79
        $this->assertSameSize(/** @scrutinizer ignore-type */ $filtered, $quizzes);
Loading history...
80
    }
81
82
    /**
83
     * Quiz delete test.
84
     *
85
     * @return void
86
     */
87
    public function test_quiz_deletion()
88
    {
89
        $quiz = Quiz::factory()->hasQuestions(10)->create();
90
91
        $this->assertEquals(10, $quiz->questions()->count());
92
93
        $quiz->delete();
94
95
        $this->assertEquals(0, Question::where('quiz_id', $quiz->id)->count());
96
    }
97
}
98