yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.23k stars 6.91k forks source link

Calling unknown method: yii\mongodb\Connection::beginTransaction() #13394

Closed tianmingxing closed 7 years ago

tianmingxing commented 7 years ago

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.

#] codecept run unit --no-ansi --html
Codeception PHP Testing Framework v2.2.5
Powered by PHPUnit 5.7.5 by Sebastian Bergmann and contributors.

Unit Tests (1) ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  [yii\base\UnknownMethodException]
  Calling unknown method: yii\mongodb\Connection::beginTransaction()

run [--report] [--html [HTML]] [--xml [XML]] [--tap [TAP]] [--json [JSON]] [--colors] [--no-colors] [--silent] [--steps] [-d|--debug] [--coverage [COVERAGE]] [--coverage-html [COVERAGE-HTML]] [--coverage-xml [C
OVERAGE-XML]] [--coverage-text [COVERAGE-TEXT]] [--no-exit] [-g|--group GROUP] [-s|--skip SKIP] [-x|--skip-group SKIP-GROUP] [--env ENV] [-f|--fail-fast] [--no-rebuild] [--] [<suite>] [<test>]
cebe commented 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.

yii-bot commented 7 years ago

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.

tianmingxing commented 7 years ago

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.

TerraSkye commented 7 years ago

this still doesnt clarify the usecase when this happens. did you write a test where this happens in?

tianmingxing commented 7 years ago

You can see that this is just a very simple test. It should not trigger any operations that connect to the database. qq 20170116151625

samdark commented 7 years ago

Are there any rules like unique or exists?

tianmingxing commented 7 years ago

In the Model, only inherited Model, field rules verify the following:

qq 20170116155453

samdark commented 7 years ago

Could you turn on trace and check what's the query about?

tianmingxing commented 7 years ago

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
cebe commented 7 years ago

Looks like a problem in codeception module:

https://github.com/Codeception/Codeception/blob/54ac1488ec250c14532fc6277e8512dcc0fbd9a9/src/Codeception/Module/Yii2.php#L188

They assume that db is instance of DB connection. That should be checked there.

cebe commented 7 years ago

Please report this problem at codeception repository, it can not be fixed from Yii side.

koiosoft commented 7 years ago

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.