Skip to content

Commit 3720768

Browse files
committed
Refactor + complete the test
1 parent 424a6c1 commit 3720768

File tree

7 files changed

+108
-16
lines changed

7 files changed

+108
-16
lines changed

src/lib/items/ActionHelperTrait.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,10 @@
99

1010
trait ActionHelperTrait
1111
{
12-
/**
13-
* @var ?string
14-
*/
15-
public $xRoute;
12+
public ?string $xRoute;
1613

17-
/**
18-
* @var array list of module this action is part of. 'key' is module ID and 'value' is path where Module.php file must be generated
19-
*/
20-
public $modulesList = [];
14+
# list of module this action is part of. 'key' is module ID and 'value' is path where Module.php file must be generated
15+
public array $modulesList = [];
2116

2217
public function getOptionsRoute():string
2318
{
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
/**
3+
* OpenAPI UrlRules
4+
*
5+
* This file is auto generated.
6+
*/
7+
return [
8+
'GET ' => 'fruit/mango/alphonso/view',
9+
'' => 'fruit/alphonso/options',
10+
];
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace app\fruit;
4+
5+
class Module extends \yii\base\Module
6+
{
7+
8+
public function init()
9+
{
10+
parent::init();
11+
$this->modules = [
12+
'mango' => [
13+
// you should consider using a shorter namespace here!
14+
'class' => \app\fruit\mango\Module::class,
15+
],
16+
];
17+
}
18+
19+
20+
}
21+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace app\fruit\mango;
4+
5+
class Module extends \yii\base\Module
6+
{
7+
8+
public function init()
9+
{
10+
parent::init();
11+
}
12+
13+
14+
}
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace app\fruit\mango\controllers;
4+
5+
class AlphonsoController extends \app\fruit\mango\controllers\base\AlphonsoController
6+
{
7+
8+
public function checkAccess($action, $model = null, $params = [])
9+
{
10+
//TODO implement checkAccess
11+
}
12+
13+
public function actionView()
14+
{
15+
//TODO implement actionView
16+
}
17+
18+
19+
}
20+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace app\fruit\mango\controllers\base;
4+
5+
abstract class AlphonsoController extends \yii\rest\Controller
6+
{
7+
public function actions()
8+
{
9+
return [
10+
'options' => [
11+
'class' => \yii\rest\OptionsAction::class,
12+
],
13+
];
14+
}
15+
16+
/**
17+
* Checks the privilege of the current user.
18+
*
19+
* This method checks whether the current user has the privilege
20+
* to run the specified action against the specified data model.
21+
* If the user does not have access, a [[ForbiddenHttpException]] should be thrown.
22+
*
23+
* @param string $action the ID of the action to be executed
24+
* @param object $model the model to be accessed. If null, it means no specific model is being accessed.
25+
* @param array $params additional parameters
26+
* @throws \yii\web\ForbiddenHttpException if the user does not have access
27+
*/
28+
abstract public function checkAccess($action, $model = null, $params = []);
29+
30+
abstract public function actionView();
31+
32+
}

tests/unit/issues/Issue14Test.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use tests\DbTestCase;
66
use Yii;
7-
use yii\base\InvalidArgumentException;
87
use yii\helpers\FileHelper;
98

109
# https://github.com/php-openapi/yii2-openapi/issues/14
@@ -14,12 +13,12 @@ public function testNestedModuleInXRoute()
1413
{
1514
$testFile = Yii::getAlias("@specs/issue_fix/14_nested_module_in_x_route/index.php");
1615
$this->runGenerator($testFile);
17-
// $actualFiles = FileHelper::findFiles(Yii::getAlias('@app'), [
18-
// 'recursive' => true,
19-
// ]);
20-
// $expectedFiles = FileHelper::findFiles(Yii::getAlias("@specs/issue_fix/14_nested_module_in_x_route/mysql"), [
21-
// 'recursive' => true,
22-
// ]);
23-
// $this->checkFiles($actualFiles, $expectedFiles);
16+
$actualFiles = FileHelper::findFiles(Yii::getAlias('@app'), [
17+
'recursive' => true,
18+
]);
19+
$expectedFiles = FileHelper::findFiles(Yii::getAlias("@specs/issue_fix/14_nested_module_in_x_route/mysql"), [
20+
'recursive' => true,
21+
]);
22+
$this->checkFiles($actualFiles, $expectedFiles);
2423
}
2524
}

0 commit comments

Comments
 (0)