Skip to content

Commit ff08c71

Browse files
committed
Fix test
1 parent 702b880 commit ff08c71

File tree

9 files changed

+195
-12
lines changed

9 files changed

+195
-12
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace app\models;
4+
5+
class Animal extends \app\models\base\Animal
6+
{
7+
8+
9+
}
10+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
namespace app\models;
3+
4+
use Faker\UniqueGenerator;
5+
6+
/**
7+
* Fake data generator for Animal
8+
* @method static Animal makeOne($attributes = [], ?UniqueGenerator $uniqueFaker = null);
9+
* @method static Animal saveOne($attributes = [], ?UniqueGenerator $uniqueFaker = null);
10+
* @method static Animal[] make(int $number, $commonAttributes = [], ?UniqueGenerator $uniqueFaker = null)
11+
* @method static Animal[] save(int $number, $commonAttributes = [], ?UniqueGenerator $uniqueFaker = null)
12+
*/
13+
class AnimalFaker extends BaseModelFaker
14+
{
15+
16+
/**
17+
* @param array|callable $attributes
18+
* @return Animal|\yii\db\ActiveRecord
19+
* @example
20+
* $model = (new PostFaker())->generateModels(['author_id' => 1]);
21+
* $model = (new PostFaker())->generateModels(function($model, $faker, $uniqueFaker) {
22+
* $model->scenario = 'create';
23+
* $model->author_id = 1;
24+
* return $model;
25+
* });
26+
**/
27+
public function generateModel($attributes = [])
28+
{
29+
$faker = $this->faker;
30+
$uniqueFaker = $this->uniqueFaker;
31+
$model = new Animal();
32+
//$model->id = $uniqueFaker->numberBetween(0, 1000000);
33+
$model->name = $faker->sentence;
34+
if (!is_callable($attributes)) {
35+
$model->setAttributes($attributes, false);
36+
} else {
37+
$model = $attributes($model, $faker, $uniqueFaker);
38+
}
39+
return $model;
40+
}
41+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace app\models;
4+
5+
class Fruit extends \app\models\base\Fruit
6+
{
7+
8+
9+
}
10+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
namespace app\models;
3+
4+
use Faker\UniqueGenerator;
5+
6+
/**
7+
* Fake data generator for Fruit
8+
* @method static Fruit makeOne($attributes = [], ?UniqueGenerator $uniqueFaker = null);
9+
* @method static Fruit saveOne($attributes = [], ?UniqueGenerator $uniqueFaker = null);
10+
* @method static Fruit[] make(int $number, $commonAttributes = [], ?UniqueGenerator $uniqueFaker = null)
11+
* @method static Fruit[] save(int $number, $commonAttributes = [], ?UniqueGenerator $uniqueFaker = null)
12+
*/
13+
class FruitFaker extends BaseModelFaker
14+
{
15+
16+
/**
17+
* @param array|callable $attributes
18+
* @return Fruit|\yii\db\ActiveRecord
19+
* @example
20+
* $model = (new PostFaker())->generateModels(['author_id' => 1]);
21+
* $model = (new PostFaker())->generateModels(function($model, $faker, $uniqueFaker) {
22+
* $model->scenario = 'create';
23+
* $model->author_id = 1;
24+
* return $model;
25+
* });
26+
**/
27+
public function generateModel($attributes = [])
28+
{
29+
$faker = $this->faker;
30+
$uniqueFaker = $this->uniqueFaker;
31+
$model = new Fruit();
32+
//$model->id = $uniqueFaker->numberBetween(0, 1000000);
33+
$model->name = $faker->sentence;
34+
if (!is_callable($attributes)) {
35+
$model->setAttributes($attributes, false);
36+
} else {
37+
$model = $attributes($model, $faker, $uniqueFaker);
38+
}
39+
return $model;
40+
}
41+
}

tests/specs/issue_fix/52_bug_dependenton_allof_with_x_faker_false/mysql/models/InvoiceFaker.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public function generateModel($attributes = [])
3131
$model = new Invoice();
3232
//$model->id = $uniqueFaker->numberBetween(0, 1000000);
3333
$model->reference_invoice_2_id = $faker->randomElement(\app\models\Invoice::find()->select("id")->column());
34-
$model->user_id = $faker->randomElement(\app\models\Invoice::find()->select("id")->column());
34+
$model->user_id = $faker->randomElement(\app\models\User::find()->select("id")->column());
35+
$model->fruit_id = $faker->randomElement(\app\models\Fruit::find()->select("id")->column());
3536
if (!is_callable($attributes)) {
3637
$model->setAttributes($attributes, false);
3738
} else {
@@ -44,6 +45,8 @@ public static function dependentOn()
4445
{
4546
return [
4647
// just model class names
48+
'User',
49+
'Fruit',
4750

4851
];
4952
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/**
4+
* This file is generated by Gii, do not change manually!
5+
*/
6+
7+
namespace app\models\base;
8+
9+
/**
10+
* This is the model class for table "animals".
11+
*
12+
* @property int $id
13+
* @property string $name
14+
*
15+
*/
16+
abstract class Animal extends \yii\db\ActiveRecord
17+
{
18+
public static function tableName()
19+
{
20+
return '{{%animals}}';
21+
}
22+
23+
public function rules()
24+
{
25+
return [
26+
'trim' => [['name'], 'trim'],
27+
'name_string' => [['name'], 'string'],
28+
];
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/**
4+
* This file is generated by Gii, do not change manually!
5+
*/
6+
7+
namespace app\models\base;
8+
9+
/**
10+
* This is the model class for table "fruits".
11+
*
12+
* @property int $id
13+
* @property string $name
14+
*
15+
*/
16+
abstract class Fruit extends \yii\db\ActiveRecord
17+
{
18+
public static function tableName()
19+
{
20+
return '{{%fruits}}';
21+
}
22+
23+
public function rules()
24+
{
25+
return [
26+
'trim' => [['name'], 'trim'],
27+
'name_string' => [['name'], 'string'],
28+
];
29+
}
30+
}

tests/specs/issue_fix/52_bug_dependenton_allof_with_x_faker_false/mysql/models/base/Invoice.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@
1414
* @property int $reference_invoice_2_id
1515
* @property int $user_id
1616
* @property int $user_2_id
17+
* @property int $fruit_id
18+
* @property int $animal_id
1719
*
1820
* @property \app\models\Invoice $referenceInvoice
1921
* @property \app\models\Invoice $referenceInvoice2
20-
* @property \app\models\Invoice $user
21-
* @property \app\models\Invoice $user2
22+
* @property \app\models\User $user
23+
* @property \app\models\User $user2
24+
* @property \app\models\Fruit $fruit
25+
* @property \app\models\Animal $animal
2226
*/
2327
abstract class Invoice extends \yii\db\ActiveRecord
2428
{
@@ -38,6 +42,10 @@ public function rules()
3842
'user_id_exist' => [['user_id'], 'exist', 'targetRelation' => 'User'],
3943
'user_2_id_integer' => [['user_2_id'], 'integer'],
4044
'user_2_id_exist' => [['user_2_id'], 'exist', 'targetRelation' => 'User2'],
45+
'fruit_id_integer' => [['fruit_id'], 'integer'],
46+
'fruit_id_exist' => [['fruit_id'], 'exist', 'targetRelation' => 'Fruit'],
47+
'animal_id_integer' => [['animal_id'], 'integer'],
48+
'animal_id_exist' => [['animal_id'], 'exist', 'targetRelation' => 'Animal'],
4149
];
4250
}
4351

@@ -53,11 +61,21 @@ public function getReferenceInvoice2()
5361

5462
public function getUser()
5563
{
56-
return $this->hasOne(\app\models\Invoice::class, ['id' => 'user_id']);
64+
return $this->hasOne(\app\models\User::class, ['id' => 'user_id']);
5765
}
5866

5967
public function getUser2()
6068
{
61-
return $this->hasOne(\app\models\Invoice::class, ['id' => 'user_2_id']);
69+
return $this->hasOne(\app\models\User::class, ['id' => 'user_2_id']);
70+
}
71+
72+
public function getFruit()
73+
{
74+
return $this->hasOne(\app\models\Fruit::class, ['id' => 'fruit_id']);
75+
}
76+
77+
public function getAnimal()
78+
{
79+
return $this->hasOne(\app\models\Animal::class, ['id' => 'animal_id']);
6280
}
6381
}

tests/unit/IssueFixTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -366,12 +366,12 @@ public function test52BugDependentonAllofWithXFakerFalse()
366366
{
367367
$testFile = Yii::getAlias("@specs/issue_fix/52_bug_dependenton_allof_with_x_faker_false/index.php");
368368
$this->runGenerator($testFile);
369-
// $actualFiles = FileHelper::findFiles(Yii::getAlias('@app'), [
370-
// 'recursive' => true,
371-
// ]);
372-
// $expectedFiles = FileHelper::findFiles(Yii::getAlias("@specs/issue_fix/52_bug_dependenton_allof_with_x_faker_false/mysql"), [
373-
// 'recursive' => true,
374-
// ]);
375-
// $this->checkFiles($actualFiles, $expectedFiles);
369+
$actualFiles = FileHelper::findFiles(Yii::getAlias('@app'), [
370+
'recursive' => true,
371+
]);
372+
$expectedFiles = FileHelper::findFiles(Yii::getAlias("@specs/issue_fix/52_bug_dependenton_allof_with_x_faker_false/mysql"), [
373+
'recursive' => true,
374+
]);
375+
$this->checkFiles($actualFiles, $expectedFiles);
376376
}
377377
}

0 commit comments

Comments
 (0)