2
2
3
3
namespace Tobyz \Tests \JsonApiServer ;
4
4
5
+ use Closure ;
5
6
use Tobyz \JsonApiServer \Adapter \AdapterInterface ;
7
+ use Tobyz \JsonApiServer \Context ;
6
8
use Tobyz \JsonApiServer \Schema \Attribute ;
7
9
use Tobyz \JsonApiServer \Schema \Field ;
8
10
use Tobyz \JsonApiServer \Schema \HasMany ;
9
11
use Tobyz \JsonApiServer \Schema \HasOne ;
12
+ use Tobyz \JsonApiServer \Schema \Relationship ;
10
13
11
14
class MockAdapter implements AdapterInterface
12
15
{
@@ -21,12 +24,12 @@ public function __construct(array $models = [], string $type = null)
21
24
$ this ->type = $ type ;
22
25
}
23
26
24
- public function newModel ()
27
+ public function model ()
25
28
{
26
29
return $ this ->createdModel = (object ) [];
27
30
}
28
31
29
- public function newQuery ()
32
+ public function query ()
30
33
{
31
34
return $ this ->query = (object ) [];
32
35
}
@@ -51,16 +54,21 @@ public function getAttribute($model, Attribute $attribute)
51
54
return $ model ->{$ this ->getProperty ($ attribute )} ?? 'default ' ;
52
55
}
53
56
54
- public function getHasOne ($ model , HasOne $ relationship , bool $ linkage )
57
+ public function getHasOne ($ model , HasOne $ relationship , bool $ linkageOnly , Context $ context )
55
58
{
56
59
return $ model ->{$ this ->getProperty ($ relationship )} ?? null ;
57
60
}
58
61
59
- public function getHasMany ($ model , HasMany $ relationship , bool $ linkage ): array
62
+ public function getHasMany ($ model , HasMany $ relationship , bool $ linkageOnly , Context $ context ): array
60
63
{
61
64
return $ model ->{$ this ->getProperty ($ relationship )} ?? [];
62
65
}
63
66
67
+ public function setId ($ model , string $ id ): void
68
+ {
69
+ $ model ->id = $ id ;
70
+ }
71
+
64
72
public function setAttribute ($ model , Attribute $ attribute , $ value ): void
65
73
{
66
74
$ model ->{$ this ->getProperty ($ attribute )} = $ value ;
@@ -100,14 +108,9 @@ public function filterByAttribute($query, Attribute $attribute, $value, string $
100
108
$ query ->filter [] = [$ attribute , $ operator , $ value ];
101
109
}
102
110
103
- public function filterByHasOne ($ query , HasOne $ relationship , array $ ids ): void
104
- {
105
- $ query ->filter [] = [$ relationship , $ ids ];
106
- }
107
-
108
- public function filterByHasMany ($ query , HasMany $ relationship , array $ ids ): void
111
+ public function filterByRelationship ($ query , Relationship $ relationship , Closure $ scope ): void
109
112
{
110
- $ query ->filter [] = [$ relationship , $ ids ];
113
+ $ query ->filter [] = [$ relationship , $ scope ];
111
114
}
112
115
113
116
public function sortByAttribute ($ query , Attribute $ attribute , string $ direction ): void
@@ -135,7 +138,7 @@ public function load(array $models, array $relationships, $scope, bool $linkage)
135
138
}
136
139
}
137
140
138
- private function getProperty (Field $ field )
141
+ private function getProperty (Field $ field ): string
139
142
{
140
143
return $ field ->getProperty () ?: $ field ->getName ();
141
144
}
0 commit comments