MockFilterQuery::assertContains()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 1
rs 10
1
<?php
2
3
namespace JoshGaber\NovaUnit\Filters;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Illuminate\Database\Eloquent\Model;
7
use JoshGaber\NovaUnit\Constraints\EloquentCollectionContains;
8
use PHPUnit\Framework\Assert as PHPUnit;
9
10
class MockFilterQuery
11
{
12
    private $results;
13
14 6
    public function __construct(Builder $query)
15
    {
16 6
        $this->results = $query->get();
17 6
    }
18
19
    /**
20
     * Assert that the query builder will return the given model.
21
     *
22
     * @param Model $element The model contained in the query result
23
     * @param string $message
24
     * @return $this
25
     */
26 2
    public function assertContains(Model $element, string $message = ''): self
27
    {
28 2
        PHPUnit::assertThat(
29 2
            $this->results,
30 2
            new EloquentCollectionContains($element),
31 2
            $message
32
        );
33
34 1
        return $this;
35
    }
36
37
    /**
38
     * Assert that the query builder will not return the given model.
39
     *
40
     * @param Model $element The model not contained in the query result
41
     * @param string $message
42
     * @return $this
43
     */
44 2
    public function assertMissing(Model $element, string $message = ''): self
45
    {
46 2
        PHPUnit::assertThat(
47 2
            $this->results,
48 2
            PHPUnit::logicalNot(new EloquentCollectionContains($element)),
49 2
            $message
50
        );
51
52 1
        return $this;
53
    }
54
55
    /**
56
     * Assert that the query builder returns the given number of records.
57
     *
58
     * @param int $count
59
     * @param string $message
60
     * @return $this
61
     */
62 1
    public function assertCount(int $count, string $message = ''): self
63
    {
64 1
        PHPUnit::assertCount($count, $this->results, $message);
65
66 1
        return $this;
67
    }
68
}
69