Codeception: Class 'MongoClient' not found
What are you trying to achieve?
I am using MongoDB when the module error, it occurred in the connection initialization place. I would like to use this module to initialize the test data so that the test results are always correct.
I look at the initial connection of the source code and found the following code to return false.
$this->legacy = extension_loaded('mongodb') === false &&
class_exists('\\MongoClient') &&
strpos(\MongoClient::VERSION, 'mongofill') === false;
I modified its results, hoping to enter this method, but there was no class to find the error. It is the php tool class, should not appear less than the case.
/**
* Connect to the Mongo server using the legacy mongo extension.
*/
protected function setupMongo($dsn, $options)
{
try {
$this->client = new \MongoClient($dsn, $options);
$this->dbh = $this->client->selectDB($this->dbName);
} catch (\MongoConnectionException $e) {
throw new ModuleException($this, sprintf('Failed to open Mongo connection: %s', $e->getMessage()));
}
}
Codeception PHP Testing Framework v2.3.3
Powered by PHPUnit 5.7.21 by Sebastian Bergmann and contributors.
Fatal error: Uncaught Error: Class 'MongoClient' not found in /www/xxx/xxx/vendor/codeception/base/src/Codeception/Lib/Driver/MongoDb.php:99
Stack trace:
#0 /www/xxx/xxx/vendor/codeception/base/src/Codeception/Lib/Driver/MongoDb.php(148): Codeception\Lib\Driver\MongoDb->__construct('mongodb://xx.xx...','mongouser', 'xxxxxxxxxxxxxxx...')
#1 /www/xxx/xxx/vendor/codeception/base/src/Codeception/Module/MongoDb.php(98): Codeception\Lib\Driver\MongoDb::create('mongodb://xx.xx...', 'mongouser', 'xxxxxxxxxxxx...')
#2 /www/xxx/xxx/vendor/codeception/base/src/Codeception/SuiteManager.php(80): Codeception\Module\MongoDb->_initialize()
#3 /www/xxx/.composer/vendor/codeception/codeception/src/Codeception/Codecept.php(182): Codeception\SuiteManager->initialize()
#4 /www/xxx/.composer/vendor/codeception/codeception/src/Codeception/Codecept.php(153): Codeception\Codecept->runSuite(Array, 'api', 'ApiControllerTe...')
#5 /www/xxx/.composer/vendor/codeception/cod in /www/xxx/xxx/vendor/codeception/base/src/Codeception/Lib/Driver/MongoDb.php on line 99
You can see that this is two questions.
What do you get instead?
Provide console output if related. Use
-vvv
mode for more details.
[xxx@VM_xx_centos editor]$ codecept -vvv run api ApiControllerTest:testActionArticle4
Codeception PHP Testing Framework v2.3.3
Powered by PHPUnit 5.7.21 by Sebastian Bergmann and contributors.
exception: login failed
Rebuilding ApiTester...
Api Tests (1) -----------------------------------------------------------------------------------------------------------------------------------------------------
Modules: Yii2, MongoDb, \Helper\Api, REST, PhpBrowser
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
✔ ApiControllerTest: Action article4 (0.00s)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Time: 221 ms, Memory: 10.00MB
OK (1 test, 0 assertions)
Provide test source code if related
public function testActionArticle4()
{
//empty
}
Details
- Codeception version: v2.3.3
- PHP Version: 7.1.9
- Operating System: centos6
- Installation type: Composer
- List of installed packages (
composer show
)
behat/gherkin v4.4.5 Gherkin DSL parser for PHP 5.3
bower-asset/bootstrap v3.3.7 The most popular front-end framework for developing responsive, mobile first projects on the web.
bower-asset/jquery 2.2.4
bower-asset/jquery.inputmask 3.3.8 Inputmask is a javascript library which creates an input mask. Inputmask can run against vanilla javascript, jQuer...
bower-asset/punycode v1.3.2
bower-asset/typeahead.js v0.11.1
bower-asset/yii2-pjax v2.0.6
cebe/markdown 1.1.2 A super fast, highly extensible markdown parser for PHP
codeception/base 2.3.5 BDD-style testing framework
codeception/specify 0.4.6 BDD code blocks for PHPUnit and Codeception
codeception/verify 0.3.3 BDD assertion library for PHPUnit
curl/curl 1.6.1 cURL class for PHP
doctrine/instantiator 1.0.5 A small, lightweight utility to instantiate objects in PHP without invoking their constructors
ezyang/htmlpurifier v4.9.3 Standards compliant HTML filter written in PHP
flow/jsonpath 0.3.4 JSONPath implementation for parsing, searching and flattening arrays
fzaninotto/faker v1.7.1 Faker is a PHP library that generates fake data for you.
guzzlehttp/guzzle 6.3.0 Guzzle is a PHP HTTP client library
guzzlehttp/promises v1.3.1 Guzzle promises library
guzzlehttp/psr7 1.4.2 PSR-7 message implementation that also provides common utility methods
myclabs/deep-copy 1.6.1 Create deep copies (clones) of your objects
ogheo/yii2-htmlcompress 1.1.0 Compress HTML output into a single line
phar-io/manifest 1.0.1 Component for reading phar.io manifest information from a PHP Archive (PHAR)
phar-io/version 1.0.1 Library for handling version information and constraints
phpdocumentor/reflection-common 1.0.1 Common reflection classes used by phpdocumentor to reflect the code structure
phpdocumentor/reflection-docblock 4.1.1 With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information ...
phpdocumentor/type-resolver 0.4.0
phpspec/php-diff v1.1.0 A comprehensive library for generating differences between two hashable objects (strings or arrays).
phpspec/prophecy v1.7.2 Highly opinionated mocking framework for PHP 5.3+
phpunit/php-code-coverage 5.2.2 Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator 1.4.2 FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-text-template 1.2.1 Simple template engine.
phpunit/php-timer 1.0.9 Utility class for timing
phpunit/php-token-stream 2.0.1 Wrapper around PHP's tokenizer extension.
phpunit/phpunit 6.2.4 The PHP Unit Testing framework.
phpunit/phpunit-mock-objects 4.0.4 Mock Object library for PHPUnit
psr/http-message 1.0.1 Common interface for HTTP messages
psr/log 1.0.2 Common interface for logging libraries
sebastian/code-unit-reverse-lookup 1.0.1 Looks up which function or method a line of code belongs to
sebastian/comparator 2.0.0 Provides the functionality to compare PHP values for equality
sebastian/diff 1.4.3 Diff implementation
sebastian/environment 3.1.0 Provides functionality to handle HHVM/PHP environments
sebastian/exporter 3.1.0 Provides the functionality to export PHP variables for visualization
sebastian/global-state 2.0.0 Snapshotting of global state
sebastian/object-enumerator 3.0.3 Traverses array structures and object graphs to enumerate all referenced objects
sebastian/object-reflector 1.1.1 Allows reflection of object attributes, including inherited and non-public ones
sebastian/recursion-context 3.0.0 Provides functionality to recursively process PHP variables
sebastian/resource-operations 1.0.0 Provides a list of PHP built-in functions that operate on resources
sebastian/version 2.0.1 Library that helps with managing the version number of Git-hosted PHP projects
stecman/symfony-console-completion 0.7.0 Automatic BASH completion for Symfony Console Component based applications.
swiftmailer/swiftmailer v5.4.8 Swiftmailer, free feature-rich PHP mailer
symfony/browser-kit v3.3.9 Symfony BrowserKit Component
symfony/console v3.3.9 Symfony Console Component
symfony/css-selector v3.3.9 Symfony CssSelector Component
symfony/debug v3.3.9 Symfony Debug Component
symfony/dom-crawler v3.3.9 Symfony DomCrawler Component
symfony/event-dispatcher v3.3.9 Symfony EventDispatcher Component
symfony/finder v3.3.9 Symfony Finder Component
symfony/polyfill-mbstring v1.5.0 Symfony polyfill for the Mbstring extension
symfony/yaml v3.3.9 Symfony Yaml Component
tencentyun/php-sdk 2.0.2 php sdk for app.qcloud.com image service
theseer/tokenizer 1.1.0 A small library for converting tokenized PHP source code into XML and potentially other formats
webmozart/assert 1.2.0 Assertions to validate method input/output with nice error messages.
whitemerry/phpkin 1.2.6 PHP Zipkin implementation
yiisoft/yii2 2.0.12 Yii PHP Framework Version 2
yiisoft/yii2-bootstrap 2.0.6 The Twitter Bootstrap extension for the Yii framework
yiisoft/yii2-composer 2.0.5 The composer plugin for Yii extension installer
yiisoft/yii2-debug 2.0.11 The debugger extension for the Yii framework
yiisoft/yii2-faker 2.0.3 Fixture generator. The Faker integration for the Yii framework.
yiisoft/yii2-gii 2.0.5 The Gii extension for the Yii framework
yiisoft/yii2-mongodb 2.1.3 MongoDB extension for the Yii framework
yiisoft/yii2-swiftmailer 2.0.7 The SwiftMailer integration for the Yii framework
- Suite configuration:
actor: ApiTester
modules:
enabled:
- Yii2:
part: [orm, fixtures]
- MongoDb:
dsn: 'mongodb://xxx.xxx.xxx.xxx:27017/xxx_dev_tests?authSource=admin&readPreference=secondaryPreferred'
user: 'mongouser'
password: 'xxxxxxxxxxxxxxxxx'
dump: 'tests/_data/dump.js'
populate: true # run populator before all tests
cleanup: true # run populator before each test
- \Helper\Api
- REST:
url: http://xxx-dev.xxx.com
depends: PhpBrowser
part: Json
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 16 (8 by maintainers)
It looks like you are missing some extension. Please run
php -m|grep mongo
Have you got mongo or mongodb installed? If mongodb, then you have to install mongodb/mongodb library.