Closed tianmingxing closed 7 years ago
In which way is this a Yii issue? If you use mongodb, there is no transaction method. That only exists in the SQL database connection class.
Thanks for posting in our issue tracker. In order to properly assist you, we need additional information:
Thanks!
This is an automated comment, triggered by adding the label status:need more info
.
I would like to emphasize that I did not try to use the affairs, I do not know if there is any implication in the use of it. I did not use the test case.
this still doesnt clarify the usecase when this happens. did you write a test where this happens in?
You can see that this is just a very simple test. It should not trigger any operations that connect to the database.
Are there any rules like unique
or exists
?
In the Model, only inherited Model, field rules verify the following:
Could you turn on trace and check what's the query about?
Thanks for your good advice, I have printed out more information.
>codecept run unit --no-ansi --debug
Codeception PHP Testing Framework v2.2.5
Powered by PHPUnit 5.7.5 by Sebastian Bergmann and contributors.
Unit Tests (1) ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Modules: Asserts, Yii2
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[yii\base\UnknownMethodException]
Calling unknown method: yii\mongodb\Connection::beginTransaction()
Exception trace:
() at D:\PhpProjects\xxx\vendor\yiisoft\yii2\base\Component.php:285
yii\base\Component->__call() at D:\PhpProjects\xxx\vendor\codeception\base\src\Codeception\Module\Yii2.php:188
Codeception\Module\Yii2->_before() at D:\PhpProjects\xxx\vendor\codeception\base\src\Codeception\Subscriber\Module.php:58
Codeception\Subscriber\Module->before() at n/a:n/a
call_user_func() at D:\PhpProjects\xxx\vendor\symfony\event-dispatcher\EventDispatcher.php:174
Symfony\Component\EventDispatcher\EventDispatcher->doDispatch() at D:\PhpProjects\xxx\vendor\symfony\event-dispatcher\EventDispatcher.php:43
Symfony\Component\EventDispatcher\EventDispatcher->dispatch() at D:\PhpProjects\xxx\vendor\codeception\base\src\Codeception\PHPUnit\Listener.php:124
Codeception\PHPUnit\Listener->fire() at D:\PhpProjects\xxx\vendor\codeception\base\src\Codeception\PHPUnit\Listener.php:95
Codeception\PHPUnit\Listener->startTest() at D:\PhpProjects\xxx\vendor\phpunit\phpunit\src\Framework\TestResult.php:388
PHPUnit_Framework_TestResult->startTest() at D:\PhpProjects\xxx\vendor\phpunit\phpunit\src\Framework\TestResult.php:644
PHPUnit_Framework_TestResult->run() at C:\Users\Administrator\AppData\Roaming\Composer\vendor\phpunit\phpunit\src\Framework\TestCase.php:909
PHPUnit_Framework_TestCase->run() at D:\PhpProjects\xxx\vendor\phpunit\phpunit\src\Framework\TestSuite.php:728
PHPUnit_Framework_TestSuite->run() at D:\PhpProjects\xxx\vendor\codeception\base\src\Codeception\PHPUnit\Runner.php:98
Codeception\PHPUnit\Runner->doEnhancedRun() at D:\PhpProjects\xxx\vendor\codeception\base\src\Codeception\SuiteManager.php:162
Codeception\SuiteManager->run() at C:\Users\Administrator\AppData\Roaming\Composer\vendor\codeception\codeception\src\Codeception\Codecept.php:209
Codeception\Codecept->runSuite() at C:\Users\Administrator\AppData\Roaming\Composer\vendor\codeception\codeception\src\Codeception\Codecept.php:178
Codeception\Codecept->run() at C:\Users\Administrator\AppData\Roaming\Composer\vendor\codeception\codeception\src\Codeception\Command\Run.php:329
Codeception\Command\Run->runSuites() at C:\Users\Administrator\AppData\Roaming\Composer\vendor\codeception\codeception\src\Codeception\Command\Run.php:256
Codeception\Command\Run->execute() at C:\Users\Administrator\AppData\Roaming\Composer\vendor\symfony\console\Command\Command.php:256
Symfony\Component\Console\Command\Command->run() at C:\Users\Administrator\AppData\Roaming\Composer\vendor\symfony\console\Application.php:820
Symfony\Component\Console\Application->doRunCommand() at C:\Users\Administrator\AppData\Roaming\Composer\vendor\symfony\console\Application.php:187
Symfony\Component\Console\Application->doRun() at C:\Users\Administrator\AppData\Roaming\Composer\vendor\symfony\console\Application.php:118
Symfony\Component\Console\Application->run() at C:\Users\Administrator\AppData\Roaming\Composer\vendor\codeception\codeception\src\Codeception\Application.php:103
Codeception\Application->run() at C:\Users\Administrator\AppData\Roaming\Composer\vendor\codeception\codeception\codecept:33
Looks like a problem in codeception module:
They assume that db
is instance of DB connection. That should be checked there.
Please report this problem at codeception repository, it can not be fixed from Yii side.
It can be resolved temporarily by assigning a base configuration to DB:
'Db' => [ 'Class' => 'yii \ db \ Connection', / 'Dsn' => 'mysql: host = localhost; dbname = yii2advanced', 'Username' => 'root', 'Password' => '', 'Charset' => 'utf8', / ],
And then in the Codeception settings:
Modules: Enabled: - Asserts Config: Yii2: ConfigFile: 'config / test-local.php' Cleanup: false
The "cleanup" prevents Rollback code from running Relational Database (which is typically transactional).
The solution is to Extend this class and improve the code, detecting the DB Type, and based on that, enable or disable Transactional operations.
It would also be interesting to generate the mechanism that reverses the changes in DB. As it stands, an alternate BD would have to be used to run the tests.
I did use MongoDB as a store, but I do not know where to use the transaction triggered by the action. At least I have not used in the test category.