Skip to content

Commit 65c9ef8

Browse files
committed
Fix test - GeneratorTest and more
1 parent 6f2d85f commit 65c9ef8

File tree

15 files changed

+87
-7
lines changed

15 files changed

+87
-7
lines changed

tests/fixtures/blog.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
->setRequired()->setDefault(false)->setFakerStub('$faker->boolean'),
4949
],
5050
'relations' => [
51-
'posts' => new AttributeRelation('posts', 'blog_posts', 'Post', 'hasMany', ['category_id' => 'id']),
51+
'posts' => (new AttributeRelation('posts', 'blog_posts', 'Post', 'hasMany', ['category_id' => 'id']))->setInverse('category'),
5252
],
5353
'indexes' => [
5454
'categories_active_index' => DbIndex::make('categories', ['active']),
@@ -88,7 +88,7 @@
8888
'hasOne',
8989
['id' => 'category_id']),
9090
'created_by' => new AttributeRelation('created_by', 'users', 'User', 'hasOne', ['id' => 'created_by_id']),
91-
'comments' => new AttributeRelation('comments', 'post_comments', 'Comment', 'hasMany', ['post_id' => 'uid']),
91+
'comments' => (new AttributeRelation('comments', 'post_comments', 'Comment', 'hasMany', ['post_id' => 'uid']))->setInverse('post'),
9292
],
9393
'indexes' => [
9494
'blog_posts_title_key' => DbIndex::make('blog_posts', ['title'], null, true),

tests/fixtures/non-db.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
],
2626
'relations' => [
2727
'parentPet' => new AttributeRelation('parentPet', 'pets', 'Pet', 'hasOne', ['id' => 'parentPet_id']),
28-
'favoritePets' => new AttributeRelation('favoritePets', 'pets', 'Pet', 'hasMany', ['pet_statistic_id' => 'id']),
28+
'favoritePets' => (new AttributeRelation('favoritePets', 'pets', 'Pet', 'hasMany', ['pet_statistic_id' => 'id']))->setInverse('petStatistic'),
2929
],
3030
'nonDbRelations' => [
3131
'topDoctors' => new NonDbRelation('topDoctors', 'Doctor', 'hasMany'),

tests/specs/blog/models/base/Category.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public function rules()
3232

3333
public function getPosts()
3434
{
35-
return $this->hasMany(\app\models\Post::class, ['category_id' => 'id']);
35+
return $this->hasMany(\app\models\Post::class, ['category_id' => 'id'])->inverseOf('category');
36+
}
37+
38+
public function getPost()
39+
{
40+
return $this->hasOne(\app\models\Post::class, ['category_id' => 'id'])->inverseOf('category');
3641
}
3742
}

tests/specs/blog/models/base/Post.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ public function getCreatedBy()
5555

5656
public function getComments()
5757
{
58-
return $this->hasMany(\app\models\Comment::class, ['post_id' => 'uid']);
58+
return $this->hasMany(\app\models\Comment::class, ['post_id' => 'uid'])->inverseOf('post');
59+
}
60+
61+
public function getComment()
62+
{
63+
return $this->hasOne(\app\models\Comment::class, ['post_id' => 'uid'])->inverseOf('post');
5964
}
6065
}

tests/specs/blog/models/base/User.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,14 @@ public function rules()
3939
'created_at_datetime' => [['created_at'], 'datetime', 'format' => 'php:Y-m-d H:i:s'],
4040
];
4141
}
42+
43+
public function getPost()
44+
{
45+
return $this->hasOne(\app\models\Post::class, ['created_by_id' => 'id'])->inverseOf('created_by');
46+
}
47+
48+
public function getComment2()
49+
{
50+
return $this->hasOne(\app\models\Comment::class, ['author_id' => 'id'])->inverseOf('author');
51+
}
4252
}

tests/specs/blog_v2/models/base/Category.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ public function rules()
3232

3333
public function getPosts()
3434
{
35-
return $this->hasMany(\app\models\Post::class, ['category_id' => 'id']);
35+
return $this->hasMany(\app\models\Post::class, ['category_id' => 'id'])->inverseOf('category');
36+
}
37+
38+
public function getPost()
39+
{
40+
return $this->hasOne(\app\models\Post::class, ['category_id' => 'id'])->inverseOf('category');
3641
}
3742
}

tests/specs/blog_v2/models/base/Post.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,17 @@ public function getCreatedBy()
6161

6262
public function getComments()
6363
{
64-
return $this->hasMany(\app\models\Comment::class, ['post_id' => 'id']);
64+
return $this->hasMany(\app\models\Comment::class, ['post_id' => 'id'])->inverseOf('post');
6565
}
6666

6767
public function getTags()
6868
{
6969
return $this->hasMany(\app\models\Tag::class, ['id' => 'tag_id'])
7070
->viaTable('posts2tags', ['post_id' => 'id']);
7171
}
72+
73+
public function getComment()
74+
{
75+
return $this->hasOne(\app\models\Comment::class, ['post_id' => 'id'])->inverseOf('post');
76+
}
7277
}

tests/specs/blog_v2/models/base/User.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,14 @@ public function rules()
4343
'created_at_datetime' => [['created_at'], 'datetime', 'format' => 'php:Y-m-d H:i:s'],
4444
];
4545
}
46+
47+
public function getPost()
48+
{
49+
return $this->hasOne(\app\models\Post::class, ['created_by_id' => 'id'])->inverseOf('created_by');
50+
}
51+
52+
public function getComment2()
53+
{
54+
return $this->hasOne(\app\models\Comment::class, ['user_id' => 'id'])->inverseOf('user');
55+
}
4656
}

tests/specs/fk_col_name/app/models/base/Delivery.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,9 @@ public function rules()
2323
'title_string' => [['title'], 'string'],
2424
];
2525
}
26+
27+
public function getWebhook()
28+
{
29+
return $this->hasOne(\app\models\Webhook::class, ['redelivery_of' => 'id'])->inverseOf('redelivery_of');
30+
}
2631
}

tests/specs/fk_col_name/app/models/base/User.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,9 @@ public function rules()
2424
'name_string' => [['name'], 'string'],
2525
];
2626
}
27+
28+
public function getWebhook()
29+
{
30+
return $this->hasOne(\app\models\Webhook::class, ['user_id' => 'id'])->inverseOf('user');
31+
}
2732
}

tests/specs/fk_col_name_index/app/models/base/Delivery.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,14 @@ public function rules()
2323
'title_string' => [['title'], 'string'],
2424
];
2525
}
26+
27+
public function getWebhook()
28+
{
29+
return $this->hasOne(\app\models\Webhook::class, ['redelivery_of' => 'id'])->inverseOf('redelivery_of');
30+
}
31+
32+
public function getWebhook2()
33+
{
34+
return $this->hasOne(\app\models\Webhook::class, ['rd_abc_2' => 'id'])->inverseOf('rd2');
35+
}
2636
}

tests/specs/fk_col_name_index/app/models/base/User.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,9 @@ public function rules()
2424
'name_string' => [['name'], 'string'],
2525
];
2626
}
27+
28+
public function getWebhook()
29+
{
30+
return $this->hasOne(\app\models\Webhook::class, ['user_id' => 'id'])->inverseOf('user');
31+
}
2732
}

tests/specs/petstore/models/base/Store.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,9 @@ public function rules()
2424
'name_string' => [['name'], 'string'],
2525
];
2626
}
27+
28+
public function getPet()
29+
{
30+
return $this->hasOne(\app\models\Pet::class, ['store_id' => 'id'])->inverseOf('store');
31+
}
2732
}

tests/specs/petstore_jsonapi/models/base/Pet.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,9 @@ public function getDuplicates()
5959
{
6060
return $this->hasMany(\app\models\Pet::class, ['tag' => 'tag']);
6161
}
62+
63+
public function getPetStatistic()
64+
{
65+
return $this->hasOne(\app\models\PetStatistic::class, ['parentPet_id' => 'id'])->inverseOf('parentPet');
66+
}
6267
}

tests/specs/petstore_namespace/mymodels/base/Store.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,9 @@ public function rules()
2424
'name_string' => [['name'], 'string'],
2525
];
2626
}
27+
28+
public function getPet()
29+
{
30+
return $this->hasOne(\app\mymodels\Pet::class, ['store_id' => 'id'])->inverseOf('store');
31+
}
2732
}

0 commit comments

Comments
 (0)