|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace JoshGaber\NovaUnit\Lenses; |
|
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 MockLensQuery |
|
11
|
|
|
{ |
|
12
|
|
|
private $query; |
|
13
|
|
|
private $results; |
|
14
|
|
|
private $request; |
|
15
|
|
|
|
|
16
|
11 |
|
public function __construct(Builder $query, MockLensRequest $request) |
|
17
|
|
|
{ |
|
18
|
11 |
|
$this->query = $query; |
|
19
|
11 |
|
$this->results = $query->get(); |
|
20
|
11 |
|
$this->request = $request; |
|
21
|
11 |
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Assert that the query builder will return the given model. |
|
25
|
|
|
* |
|
26
|
|
|
* @param Model $element The model contained in the query result |
|
27
|
|
|
* @param string $message |
|
28
|
|
|
* @return $this |
|
29
|
|
|
*/ |
|
30
|
2 |
|
public function assertContains(Model $element, string $message = ''): self |
|
31
|
|
|
{ |
|
32
|
2 |
|
PHPUnit::assertThat( |
|
33
|
2 |
|
$this->results, |
|
34
|
2 |
|
new EloquentCollectionContains($element), |
|
35
|
2 |
|
$message |
|
36
|
|
|
); |
|
37
|
|
|
|
|
38
|
1 |
|
return $this; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Assert that the query builder will not return the given model. |
|
43
|
|
|
* |
|
44
|
|
|
* @param Model $element The model not contained in the query result |
|
45
|
|
|
* @param string $message |
|
46
|
|
|
* @return $this |
|
47
|
|
|
*/ |
|
48
|
2 |
|
public function assertMissing(Model $element, string $message = ''): self |
|
49
|
|
|
{ |
|
50
|
2 |
|
PHPUnit::assertThat( |
|
51
|
2 |
|
$this->results, |
|
52
|
2 |
|
PHPUnit::logicalNot(new EloquentCollectionContains($element)), |
|
53
|
2 |
|
$message |
|
54
|
|
|
); |
|
55
|
|
|
|
|
56
|
1 |
|
return $this; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Assert that the query builder returns the given number of records. |
|
61
|
|
|
* |
|
62
|
|
|
* @param int $count |
|
63
|
|
|
* @param string $message |
|
64
|
|
|
* @return $this |
|
65
|
|
|
*/ |
|
66
|
1 |
|
public function assertCount(int $count, string $message = ''): self |
|
67
|
|
|
{ |
|
68
|
1 |
|
PHPUnit::assertCount( |
|
69
|
1 |
|
$count, |
|
70
|
1 |
|
$this->results, |
|
71
|
1 |
|
$message |
|
72
|
|
|
); |
|
73
|
|
|
|
|
74
|
1 |
|
return $this; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Assert that the query builder uses the "withFilters" request. |
|
79
|
|
|
* |
|
80
|
|
|
* @param string $message |
|
81
|
|
|
* @return $this |
|
82
|
|
|
*/ |
|
83
|
2 |
|
public function assertWithFilters(string $message = ''): self |
|
84
|
|
|
{ |
|
85
|
2 |
|
PHPUnit::assertTrue($this->request->withFilters, $message); |
|
86
|
|
|
|
|
87
|
1 |
|
return $this; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Assert that the query builder uses the "withOrdering" request. |
|
92
|
|
|
* |
|
93
|
|
|
* @param string $message |
|
94
|
|
|
* @return $this |
|
95
|
|
|
*/ |
|
96
|
2 |
|
public function assertWithOrdering(string $message = ''): self |
|
97
|
|
|
{ |
|
98
|
2 |
|
PHPUnit::assertTrue($this->request->withOrdering, $message); |
|
99
|
|
|
|
|
100
|
1 |
|
return $this; |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|