File tree 3 files changed +29
-5
lines changed
3 files changed +29
-5
lines changed Original file line number Diff line number Diff line change 1
1
<?php
2
2
namespace Tests ;
3
3
4
- use Tests \Models \User ;
4
+ use Tests \Models \Order ;
5
5
6
6
class AnyTest extends TestCase
7
7
{
8
- public function testLazyLoading2LevelsOne ()
8
+ public function testAnyActualTag ()
9
9
{
10
- $ user = User::where ('id ' , 8 )->first ();
11
- $ this ->assertEquals (21 , $ user ->contact ->user_profile ->id );
10
+ $ order = Order::where ('id ' , 31 )->first ();
11
+ // dump($order->order_category->toArray());
12
+ $ this ->assertEquals (12 , $ order ->order_category ->target_type );
13
+ }
14
+ public function testAnyConnection ()
15
+ {
16
+ $ order = Order::where ('id ' , 31 )->first ();
17
+ $ this ->assertEquals (1 , $ order ->order_category_any [0 ]->target_type );
18
+ $ this ->assertEquals (21 , $ order ->order_category_any [0 ]->target_id );
19
+ $ this ->assertEquals (8 , $ order ->order_category_any [1 ]->target_type );
20
+ $ this ->assertEquals (24 , $ order ->order_category_any [1 ]->target_id );
21
+ $ this ->assertEquals (11 , $ order ->order_category_any [2 ]->target_type );
22
+ $ this ->assertEquals (11 , $ order ->order_category_any [2 ]->target_id );
12
23
}
13
24
}
14
25
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ class Order extends Model
9
9
use SoftDeletes;
10
10
11
11
function user_profile () {
12
- this ->tagOne (UserProfile::class);
12
+ return $ this ->tagOne (UserProfile::class);
13
13
}
14
14
15
15
function billing_profile () {
@@ -32,4 +32,12 @@ function billing_contact() {
32
32
return $ this ->tagOneThrough (Category::class, (int ) getenv ('ORDERS_BILLING_PROFILE ' ), Contact::class)
33
33
->where ('contacts.status ' , 1 );
34
34
}
35
+
36
+ function order_category () {
37
+ return $ this ->tagOneThrough (Category::class, ORDER_CATEGORY );
38
+ }
39
+
40
+ function order_category_any () {
41
+ return $ this ->tagManyThrough (Category::class, ORDER_CATEGORY , 'any ' );
42
+ }
35
43
}
Original file line number Diff line number Diff line change 22
22
define ('USER_PRIMARY_CONTACT ' , 2 );
23
23
define ('BILLING_PROFILE ' , 3 );
24
24
define ('FILLING_PROFILE ' , 4 );
25
+ define ('ORDER_CATEGORY ' , 5 );
25
26
26
27
abstract class TestCase extends Base
27
28
{
@@ -236,6 +237,10 @@ protected function seed(): void {
236
237
_tag ('UserProfile ' , 21 , 'Order ' , 31 );
237
238
_tag ('UserProfile ' , 22 , 'Order ' , 32 );
238
239
240
+ $ orderCategoryTag = _tag ('Order ' , 31 , 'Category ' , ORDER_CATEGORY );
241
+ _tagCategory ($ orderCategoryTag ->id , 'UserProfile ' , 24 );
242
+ _tagCategory ($ orderCategoryTag ->id , 'User ' , 21 );
243
+ _tagCategory ($ orderCategoryTag ->id , 'Contact ' , 11 );
239
244
240
245
// for category testing
241
246
$ categoryTag = _tag ('User ' , 15 , 'Category ' , BILLING_PROFILE );
You can’t perform that action at this time.
0 commit comments