Skip to content

Commit 1bfc499

Browse files
committed
Fix issue and other failing tests
1 parent e27d9a0 commit 1bfc499

File tree

58 files changed

+129
-60
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+129
-60
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,4 +568,3 @@ Professional support, consulting as well as software development services are av
568568
https://www.cebe.cc/en/contact
569569

570570
Development of this library is sponsored by [cebe.:cloud: "Your Professional Deployment Platform"](https://cebe.cloud).
571-

TODO.taskpaper

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
TODO.taskpaper
2+
3+
### Bug: rules() "required" is generated before "*_default" #22
4+
✔ create failing test @done (24-08-18 19:21)
5+
✔ implement the solution @done (24-08-18 19:21)
6+
☐ fix failing tests if any
7+
☐ resolve TODOs if any
8+
☐ review PR
9+
☐ delete this file and submit PR

src/lib/ValidationRulesBuilder.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
use cebe\yii2openapi\lib\items\Attribute;
1111
use cebe\yii2openapi\lib\items\DbModel;
1212
use cebe\yii2openapi\lib\items\ValidationRule;
13-
use yii\helpers\VarDumper;
14-
use yii\validators\DateValidator;
1513
use function count;
1614
use function implode;
1715
use function in_array;
@@ -53,9 +51,6 @@ public function build():array
5351
$this->rules['trim'] = new ValidationRule($this->typeScope['trim'], 'trim');
5452
}
5553

56-
if (!empty($this->typeScope['required'])) {
57-
$this->rules['required'] = new ValidationRule($this->typeScope['required'], 'required');
58-
}
5954
if (!empty($this->typeScope['ref'])) {
6055
$this->addExistRules($this->typeScope['ref']);
6156
}
@@ -77,6 +72,9 @@ public function build():array
7772
if (!empty($this->typeScope['safe'])) {
7873
$this->rules['safe'] = new ValidationRule($this->typeScope['safe'], 'safe');
7974
}
75+
if (!empty($this->typeScope['required'])) {
76+
$this->rules['required'] = new ValidationRule($this->typeScope['required'], 'required');
77+
}
8078
return $this->rules;
8179
}
8280

tests/DbTestCase.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
namespace tests;
44

55
use cebe\yii2openapi\generator\ApiGenerator;
6+
use SamIT\Yii2\MariaDb\Schema as MariaDbSchema;
67
use Yii;
7-
use yii\di\Container;
88
use yii\db\mysql\Schema as MySqlSchema;
99
use yii\db\pgsql\Schema as PgSqlSchema;
10-
use \SamIT\Yii2\MariaDb\Schema as MariaDbSchema;
11-
use yii\helpers\{ArrayHelper, VarDumper, StringHelper, Console};
10+
use yii\di\Container;
11+
use yii\helpers\{ArrayHelper, StringHelper};
1212
use yii\helpers\FileHelper;
1313

1414
class DbTestCase extends \PHPUnit\Framework\TestCase
@@ -127,6 +127,7 @@ protected function checkFiles(array $actual, array $expected)
127127
);
128128
}
129129

130+
// exec('cp '.$file.' '.$expectedFilePath);
130131
$this->assertFileEquals($expectedFilePath, $file, "Failed asserting that file contents of\n$file\nare equal to file contents of\n$expectedFilePath \n\n cp $file $expectedFilePath \n\n ");
131132
}
132133
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ public function rules()
2222
{
2323
return [
2424
'trim' => [['title'], 'trim'],
25-
'required' => [['title', 'active'], 'required'],
2625
'title_unique' => [['title'], 'unique'],
2726
'title_string' => [['title'], 'string', 'max' => 255],
2827
'active_boolean' => [['active'], 'boolean'],
2928
'active_default' => [['active'], 'default', 'value' => false],
29+
'required' => [['title', 'active'], 'required'],
3030
];
3131
}
3232

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public function rules()
2626
{
2727
return [
2828
'trim' => [['post_id'], 'trim'],
29-
'required' => [['post_id', 'author_id', 'message', 'created_at'], 'required'],
3029
'post_id_string' => [['post_id'], 'string', 'max' => 128],
3130
'post_id_exist' => [['post_id'], 'exist', 'targetRelation' => 'Post'],
3231
'author_id_integer' => [['author_id'], 'integer'],
@@ -35,6 +34,7 @@ public function rules()
3534
'meta_data_default' => [['meta_data'], 'default', 'value' => []],
3635
'created_at_integer' => [['created_at'], 'integer'],
3736
'safe' => [['message', 'meta_data'], 'safe'],
37+
'required' => [['post_id', 'author_id', 'message', 'created_at'], 'required'],
3838
];
3939
}
4040

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public function rules()
2828
{
2929
return [
3030
'trim' => [['title', 'slug', 'created_at'], 'trim'],
31-
'required' => [['title', 'category_id', 'active'], 'required'],
3231
'category_id_integer' => [['category_id'], 'integer'],
3332
'category_id_exist' => [['category_id'], 'exist', 'targetRelation' => 'Category'],
3433
'created_by_id_integer' => [['created_by_id'], 'integer'],
@@ -40,6 +39,7 @@ public function rules()
4039
'active_boolean' => [['active'], 'boolean'],
4140
'active_default' => [['active'], 'default', 'value' => false],
4241
'created_at_date' => [['created_at'], 'date', 'format' => 'php:Y-m-d'],
42+
'required' => [['title', 'category_id', 'active'], 'required'],
4343
];
4444
}
4545

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public function rules()
2525
{
2626
return [
2727
'trim' => [['username', 'email', 'password', 'role', 'created_at'], 'trim'],
28-
'required' => [['username', 'email', 'password'], 'required'],
2928
'username_unique' => [['username'], 'unique'],
3029
'email_unique' => [['email'], 'unique'],
3130
'username_string' => [['username'], 'string', 'max' => 200],
@@ -37,6 +36,7 @@ public function rules()
3736
'flags_integer' => [['flags'], 'integer'],
3837
'flags_default' => [['flags'], 'default', 'value' => 0],
3938
'created_at_datetime' => [['created_at'], 'datetime', 'format' => 'php:Y-m-d H:i:s'],
39+
'required' => [['username', 'email', 'password'], 'required'],
4040
];
4141
}
4242
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ public function rules()
2323
{
2424
return [
2525
'trim' => [['title', 'cover'], 'trim'],
26-
'required' => [['title', 'cover', 'active'], 'required'],
2726
'title_string' => [['title'], 'string', 'max' => 100],
2827
'cover_string' => [['cover'], 'string'],
2928
'active_boolean' => [['active'], 'boolean'],
29+
'required' => [['title', 'cover', 'active'], 'required'],
3030
];
3131
}
3232

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public function rules()
2626
{
2727
return [
2828
'trim' => [['message', 'meta_data', 'created_at'], 'trim'],
29-
'required' => [['post_id', 'message', 'created_at'], 'required'],
3029
'post_id_integer' => [['post_id'], 'integer'],
3130
'post_id_exist' => [['post_id'], 'exist', 'targetRelation' => 'Post'],
3231
'user_id_integer' => [['user_id'], 'integer'],
@@ -35,6 +34,7 @@ public function rules()
3534
'meta_data_string' => [['meta_data'], 'string', 'min' => 1, 'max' => 300],
3635
'meta_data_default' => [['meta_data'], 'default', 'value' => ''],
3736
'created_at_datetime' => [['created_at'], 'datetime', 'format' => 'php:Y-m-d H:i:s'],
37+
'required' => [['post_id', 'message', 'created_at'], 'required'],
3838
];
3939
}
4040

0 commit comments

Comments
 (0)