Closed cyril-amar closed 1 year ago
Cannot reproduce in basic app.
Created a module using:
./yii gii/module --moduleClass 'app\modules\Test\Module' --moduleID test
Edited it to implement BootstrapInterface
and add custom url rules on bootstrap:
<?php
namespace app\modules\Test;
use yii\base\BootstrapInterface;
/**
* test module definition class
*/
class Module extends \yii\base\Module implements BootstrapInterface
{
/**
* {@inheritdoc}
*/
public $controllerNamespace = 'app\modules\Test\controllers';
/**
* {@inheritdoc}
*/
public function init()
{
parent::init();
// custom initialization code goes here
}
public function bootstrap($app)
{
$app->getUrlManager()->addRules([
[
'verb' => 'GET',
'pattern' => '/org/config/incident/severity',
'route' => '/incident/severity-level/index',
],
[
'verb' => 'GET,POST',
'pattern' => '/org/config/incident/severity/new',
'route' => '/incident/severity-level/create',
],
[
'verb' => 'GET,POST',
'pattern' => '/org/config/incident/severity/<id:[0-9]+>/<action:(update|delete)>',
'route' => '/incident/severity-level/<action>',
],
], false);
}
}
Added to config/test.php
:
'bootstrap' => [
'class' => app\modules\Test\Module::class,
],
'modules' => [
'admin' => [
'class' => app\modules\Test\Module::class
],
]
Tests run fine. (both unit tests and full test suites, including functional)
Any more info you can give? Or maybe a minimal reproduction project in a zip?
Edit: tested with current master version
codeception/codeception 5.0.x-dev 2f06902 BDD-style testing framework
codeception/lib-innerbrowser 4.0.0 Parent library for all Codeception framework modules and PhpBrowser
codeception/module-asserts 3.0.0 Codeception module containing various assertions
codeception/module-filesystem 3.0.0 Codeception module for testing local filesystem
codeception/module-yii2 1.1.9 Codeception module for Yii2 framework
codeception/verify 3.0.0 BDD assertion library for PHPUnit
symfony/browser-kit 6.4.x-dev 3f5752f Simulates the behavior of a web browser, allowing you to make requests, click on links and submit forms programmatically
yiisoft/yii2 dev-master ddf0f87 Yii PHP Framework Version 2
yiisoft/yii2-bootstrap5 dev-master cf7807d The Twitter Bootstrap v5 extension for the Yii framework
yiisoft/yii2-debug 2.1.25 The debugger extension for the Yii framework
yiisoft/yii2-faker dev-master 98e4e4c Fixture generator. The Faker integration for the Yii framework.
yiisoft/yii2-gii 2.2.6 The Gii extension for the Yii framework
yiisoft/yii2-symfonymailer 2.0.4 The SymfonyMailer integration for the Yii framework
Hi,
Thanks!
I should have had added something indeed, my bad :( The issue only occurs if pretty URLs are enabled
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing' => true,
'rules' => $urls, // Declared rules for the "core" app, without modules
],
Switching enablePrettyUrl
to false solves the issue and allows tests to run.
Commenting out all the rules definition in Module.php also works fine.
I'm running on
codeception/codeception 5.0.11 BDD-style testing framework
codeception/lib-asserts 2.1.0 Assertion methods used by Codeception core and Asserts module
codeception/lib-innerbrowser 3.1.3 Parent library for all Codeception framework modules and PhpBrowser
codeception/lib-web 1.0.2 Library containing files used by module-webdriver and lib-innerbrowser or module-phpbrowser
codeception/module-asserts 3.0.0 Codeception module containing various assertions
codeception/module-db 3.1.0 DB module for Codeception
codeception/module-filesystem 3.0.0 Codeception module for testing local filesystem
codeception/module-yii2 1.1.9 Codeception module for Yii2 framework
codeception/stub 4.1.1 Flexible Stub wrapper for PHPUnit's Mock Builder
codeception/verify 3.0.0 BDD assertion library for PHPUnit
phpunit/php-code-coverage 9.2.29 Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator 3.0.6 FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-invoker 3.1.1 Invoke callables with a timeout
phpunit/php-text-template 2.0.4 Simple template engine.
phpunit/php-timer 5.0.3 Utility class for timing
phpunit/phpunit 9.6.13 The PHP Unit Testing framework.
symfony/browser-kit v6.3.2 Simulates the behavior of a web browser, allowing you to make requests, click on links and submit forms programmatically
yiisoft/yii2 2.0.49.1 Yii PHP Framework Version 2
yiisoft/yii2-bootstrap4 2.0.11 The Twitter Bootstrap extension for the Yii framework
yiisoft/yii2-bootstrap5 2.0.4 The Twitter Bootstrap v5 extension for the Yii framework
yiisoft/yii2-composer 2.0.10 The composer plugin for Yii extension installer
yiisoft/yii2-debug 2.1.25 The debugger extension for the Yii framework
yiisoft/yii2-faker 2.0.5 Fixture generator. The Faker integration for the Yii framework.
yiisoft/yii2-gii 2.2.6 The Gii extension for the Yii framework
yiisoft/yii2-symfonymailer 3.0.0 The SymfonyMailer integration for the Yii framework
[...]
I'll try to reproduce in a brand new project and share it.
I cannot reproduce either in basic-app for now, seems I have something else elsewhere. I'm still working on identifying the culprit.
What steps will reproduce the problem?
yii\base\BootstrapInterface
and extending an abstract class itself extendingyii\base\Module
(only adding parameters/methods, not surcharging any)Module::bootstrap()
methodYii::$app->bootstrap
in the config file used by testing.$> vendor/bin/codecept run unit
What's expected?
Tests are run.
What do you get instead?
First test in run OK, all others are met with:
Additional info
Running the app while not in unit testing works fine. The custom module is only bootstrapped, not tested (yet!).
I determined that
UrlManager::buildRules()
inyii2/web/UrlManager.php:228
is called withtrue
instead of an array (viewed by dumping the value). DeclaringUrlManager::$rules
as an array onUrlManager.php:105
provokes indeed an error: