Skip to content

Commit b0fa081

Browse files
committed
any tests added
1 parent 2d87aee commit b0fa081

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

Diff for: tests/AnyTest.php

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
<?php
22
namespace Tests;
33

4-
use Tests\Models\User;
4+
use Tests\Models\Order;
55

66
class AnyTest extends TestCase
77
{
8-
public function testLazyLoading2LevelsOne()
8+
public function testAnyActualTag()
99
{
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);
1223
}
1324
}
1425

Diff for: tests/Models/Order.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Order extends Model
99
use SoftDeletes;
1010

1111
function user_profile() {
12-
this->tagOne(UserProfile::class);
12+
return $this->tagOne(UserProfile::class);
1313
}
1414

1515
function billing_profile() {
@@ -32,4 +32,12 @@ function billing_contact() {
3232
return $this->tagOneThrough(Category::class, (int) getenv('ORDERS_BILLING_PROFILE'), Contact::class)
3333
->where('contacts.status', 1);
3434
}
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+
}
3543
}

Diff for: tests/TestCase.php

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
define('USER_PRIMARY_CONTACT', 2);
2323
define('BILLING_PROFILE', 3);
2424
define('FILLING_PROFILE', 4);
25+
define('ORDER_CATEGORY', 5);
2526

2627
abstract class TestCase extends Base
2728
{
@@ -236,6 +237,10 @@ protected function seed(): void {
236237
_tag('UserProfile', 21, 'Order', 31);
237238
_tag('UserProfile', 22, 'Order', 32);
238239

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);
239244

240245
// for category testing
241246
$categoryTag = _tag('User', 15, 'Category', BILLING_PROFILE);

0 commit comments

Comments
 (0)