Skip to content

Commit 42e0b9e

Browse files
committed
Failing test
1 parent 649743c commit 42e0b9e

File tree

9 files changed

+234
-0
lines changed

9 files changed

+234
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
return [
4+
'openApiPath' => '@specs/issue_fix/100_fix_numbering_issue_in_relation_names_in_case_of_more_than_one_similar_belongs_to_relation/index.yml',
5+
'generateUrls' => false,
6+
'generateModels' => true,
7+
'excludeModels' => [
8+
'Error',
9+
],
10+
'generateControllers' => false,
11+
'generateMigrations' => false,
12+
'generateModelFaker' => false,
13+
];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
openapi: "3.0.0"
2+
info:
3+
version: 1.0.0
4+
title: 100_fix_numbering_issue_in_relation_names_in_case_of_more_than_one_similar_belongs_to_relation
5+
paths:
6+
/:
7+
get:
8+
summary: List
9+
operationId: list
10+
responses:
11+
'200':
12+
description: The information
13+
14+
components:
15+
schemas:
16+
Address:
17+
type: object
18+
properties:
19+
id:
20+
type: integer
21+
shortName:
22+
type: string
23+
postCode:
24+
type: string
25+
maxLength: 64
26+
Foo:
27+
type: object
28+
properties:
29+
id:
30+
type: integer
31+
address:
32+
$ref: '#/components/schemas/Address'
33+
34+
Bar:
35+
type: object
36+
properties:
37+
id:
38+
type: integer
39+
task:
40+
$ref: '#/components/schemas/Address'
41+
related_task:
42+
$ref: '#/components/schemas/Address'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace app\models;
4+
5+
class Address extends \app\models\base\Address
6+
{
7+
}
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace app\models;
4+
5+
class Bar extends \app\models\base\Bar
6+
{
7+
}
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace app\models;
4+
5+
class Foo extends \app\models\base\Foo
6+
{
7+
}
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 "addresses".
11+
*
12+
* @property int $id
13+
* @property string $shortName
14+
* @property string $postCode
15+
*
16+
*/
17+
abstract class Address extends \yii\db\ActiveRecord
18+
{
19+
public static function tableName()
20+
{
21+
return '{{%addresses}}';
22+
}
23+
24+
public function rules()
25+
{
26+
return [
27+
'trim' => [['shortName', 'postCode'], 'trim'],
28+
'shortName_string' => [['shortName'], 'string'],
29+
'postCode_string' => [['postCode'], 'string', 'max' => 64],
30+
];
31+
}
32+
33+
# belongs to relation
34+
public function getFoo()
35+
{
36+
return $this->hasOne(\app\models\Foo::class, ['address_id' => 'id']);
37+
}
38+
39+
# belongs to relation
40+
public function getBar()
41+
{
42+
return $this->hasOne(\app\models\Bar::class, ['task_id' => 'id']);
43+
}
44+
45+
# belongs to relation
46+
public function getBar2()
47+
{
48+
return $this->hasOne(\app\models\Bar::class, ['related_task_id' => 'id']);
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 "bars".
11+
*
12+
* @property int $id
13+
* @property int $task_id
14+
* @property int $related_task_id
15+
*
16+
* @property \app\models\Address $task
17+
* @property \app\models\Address $relatedTask
18+
*/
19+
abstract class Bar extends \yii\db\ActiveRecord
20+
{
21+
public static function tableName()
22+
{
23+
return '{{%bars}}';
24+
}
25+
26+
public function rules()
27+
{
28+
return [
29+
'task_id_integer' => [['task_id'], 'integer'],
30+
'task_id_exist' => [['task_id'], 'exist', 'targetRelation' => 'task'],
31+
'related_task_id_integer' => [['related_task_id'], 'integer'],
32+
'related_task_id_exist' => [['related_task_id'], 'exist', 'targetRelation' => 'relatedTask'],
33+
];
34+
}
35+
36+
public function getTask()
37+
{
38+
return $this->hasOne(\app\models\Address::class, ['id' => 'task_id']);
39+
}
40+
41+
public function getRelatedTask()
42+
{
43+
return $this->hasOne(\app\models\Address::class, ['id' => 'related_task_id']);
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 "foos".
11+
*
12+
* @property int $id
13+
* @property int $address_id
14+
*
15+
* @property \app\models\Address $address
16+
*/
17+
abstract class Foo extends \yii\db\ActiveRecord
18+
{
19+
public static function tableName()
20+
{
21+
return '{{%foos}}';
22+
}
23+
24+
public function rules()
25+
{
26+
return [
27+
'address_id_integer' => [['address_id'], 'integer'],
28+
'address_id_exist' => [['address_id'], 'exist', 'targetRelation' => 'address'],
29+
];
30+
}
31+
32+
public function getAddress()
33+
{
34+
return $this->hasOne(\app\models\Address::class, ['id' => 'address_id']);
35+
}
36+
}

tests/unit/issues/Issue100Test.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace tests\unit\issues;
4+
5+
use tests\DbTestCase;
6+
use Yii;
7+
use yii\helpers\FileHelper;
8+
9+
class Issue100Test extends DbTestCase
10+
{
11+
// https://github.com/php-openapi/yii2-openapi/issues/100
12+
public function testFixNumberingIssueInRelationNamesInCaseOfMoreThanOneSimilarBelongsToRelation()
13+
{
14+
$testFile = Yii::getAlias("@specs/issue_fix/100_fix_numbering_issue_in_relation_names_in_case_of_more_than_one_similar_belongs_to_relation/index.php");
15+
$this->runGenerator($testFile);
16+
$actualFiles = FileHelper::findFiles(Yii::getAlias('@app'), [
17+
'recursive' => true,
18+
]);
19+
$expectedFiles = FileHelper::findFiles(Yii::getAlias("@specs/issue_fix/100_fix_numbering_issue_in_relation_names_in_case_of_more_than_one_similar_belongs_to_relation/mysql"), [
20+
'recursive' => true,
21+
]);
22+
$this->checkFiles($actualFiles, $expectedFiles);
23+
}
24+
}

0 commit comments

Comments
 (0)