File tree 5 files changed +96
-1
lines changed
5 files changed +96
-1
lines changed Original file line number Diff line number Diff line change 8
8
convertNoticesToExceptions =" true"
9
9
convertWarningsToExceptions =" true"
10
10
processIsolation =" false"
11
- stopOnFailure =" false " >
11
+ stopOnFailure =" true " >
12
12
<testsuites >
13
13
<testsuite name =" AwesIO Repository Package" >
14
14
<directory suffix =" .php" >./tests/</directory >
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace AwesIO \Repository \Tests \Stubs ;
4
+
5
+ use AwesIO \Repository \Scopes \ScopeAbstract ;
6
+
7
+ class Scope extends ScopeAbstract
8
+ {
9
+ public function mappings ()
10
+ {
11
+ return ['full_name ' => 'name ' ];
12
+ }
13
+
14
+ public function scope ($ builder , $ value , $ scope )
15
+ {
16
+ $ scope = $ this ->resolveScopeValue ($ scope );
17
+
18
+ return $ builder ->where ($ scope , $ value );
19
+ }
20
+ }
Original file line number Diff line number Diff line change 8
8
9
9
class OrderByTest extends TestCase
10
10
{
11
+ /** @test */
12
+ public function it_has_mappings ()
13
+ {
14
+ $ scope = new OrderByScope ;
15
+
16
+ $ this ->assertEquals ([], $ scope ->mappings ());
17
+ }
18
+
19
+ /** @test */
20
+ public function it_returns_ignores_wrong_order_postfix ()
21
+ {
22
+ factory (Model::class, 5 )->create ();
23
+
24
+ $ scope = new OrderByScope ;
25
+
26
+ $ results = Model::get ();
27
+
28
+ $ this ->assertEquals (1 , $ results ->first ()->id );
29
+
30
+ $ results = $ scope ->scope (new Model , 'id_wrong-order-postfix ' , '' )->get ();
31
+
32
+ $ this ->assertEquals (1 , $ results ->first ()->id );
33
+ }
34
+
11
35
/** @test */
12
36
public function it_orders_by_asc ()
13
37
{
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace AwesIO \Repository \Tests \Unit \Scopes ;
4
+
5
+ use AwesIO \Repository \Tests \TestCase ;
6
+ use Illuminate \Support \Facades \Request ;
7
+ use AwesIO \Repository \Tests \Stubs \Model ;
8
+ use AwesIO \Repository \Tests \Stubs \Scope ;
9
+
10
+ class ScopeTest extends TestCase
11
+ {
12
+ /** @test */
13
+ public function it_resolves_scope_value ()
14
+ {
15
+ factory (Model::class, 5 )->create ();
16
+
17
+ $ model = factory (Model::class)->create ();
18
+
19
+ $ scope = new Scope ;
20
+
21
+ $ results = $ scope ->scope (new Model , $ model ->name , 'full_name ' )->get ();
22
+
23
+ $ this ->assertEquals ($ model ->id , $ results ->first ()->id );
24
+ }
25
+ }
Original file line number Diff line number Diff line change 9
9
10
10
class ScopesTest extends TestCase
11
11
{
12
+ /** @test */
13
+ public function it_scopes_request_by_field ()
14
+ {
15
+ $ request = Request::create (
16
+ '/ ' ,
17
+ 'GET ' ,
18
+ ['name ' => 'name ' ]
19
+ );
20
+
21
+ $ scopes = new Scopes ($ request , ['name ' => 'like ' ]);
22
+
23
+ factory (Model::class, 5 )->create ();
24
+
25
+ $ model = factory (Model::class)->create ([
26
+ 'name ' => 'name '
27
+ ]);
28
+
29
+ $ results = Model::get ();
30
+
31
+ $ this ->assertEquals (1 , $ results ->first ()->id );
32
+
33
+ $ results = $ scopes ->scope (new Model )->get ();
34
+
35
+ $ this ->assertEquals ($ model ->id , $ results ->first ()->id );
36
+ }
37
+
12
38
/** @test */
13
39
public function it_scopes_request_by_orderBy ()
14
40
{
You can’t perform that action at this time.
0 commit comments