Closed ustrugany closed 8 years ago
If you just want to run the ODM test suite against the adapter, check out the changes I have made in composer.json
in order to test this: https://github.com/alcaeus/mongodb-odm/commit/93c3f067fe4a3a20cc4577bf99cd55d43f3ef0e2.
If you want to use mongodb-odm in a project running on PHP 7 (on PHP 5.x, please use ext-mongo directly) the changes will be different and need to be made in your package only. Unfortunately, I haven't found a way for this library to specify that it is replacing or providing ext-mongo
. This is why the root package needs to include a provide
block in composer.json
telling composer that it is providing the extension by other means. In most cases, it's also that package that should be specifying the requirement to mongo-php-adapter since it should not matter to libraries lower down in the dependency tree.
Quick example: let's say you have the following composer.json:
{
"name": "vendor/package",
"require": {
"doctrine/mongodb-odm": "^1.0.0"
}
}
After all changes, composer.json
should look like this:
{
"name": "vendor/package",
"provide": { "ext-mongo": "1.6.12" },
"require": {
"doctrine/mongodb": "dev-master",
"doctrine/mongodb-odm": "dev-master",
"alcaeus/mongo-php-adapter": "dev-master"
}
}
Please note that the dev-master
dependency for doctrine/mongodb and doctrine/mongodb-odm is only temporary until the new versions (1.3 and 1.1, respectively) are released.
As for getting errors while running tests, I'm going to guess it's due to gravitational waves. I'm more than happy to provide a more thorough explanation if you tell me what errors you're getting.
As for getting errors while running tests, I'm going to guess it's due to gravitational waves.
Damn you Einstein :P
@alcaeus thanks for info, gravitational waves just hilarious :P. This is my composer.json config on fresh symfony 2.8 installtion:
...
"provide": { "ext-mongo": "1.6.12" },
"require": {
"php": ">=5.3.9",
"phpunit/phpunit": "5.2.*",
"symfony/symfony": "2.8.*",
"doctrine/orm": "^2.4.8",
"doctrine/doctrine-bundle": "~1.4",
"symfony/swiftmailer-bundle": "~2.3",
"symfony/monolog-bundle": "~2.4",
"sensio/distribution-bundle": "~5.0",
"sensio/framework-extra-bundle": "^3.0.2",
"incenteev/composer-parameter-handler": "~2.0",
"alcaeus/mongo-php-adapter": "dev-master",
"doctrine/mongodb-odm": "^1.0.0",
"doctrine/mongodb-odm-bundle": "^3.0.0"
},
...
I've managed to install all vendors without composer complaining about ext-mongo
missing dependency.
But wanted to double check if ODM will work fine, so I run test included doctrine/mongodb-odm
tests: ~/www/symfony (searcher-bundle-mongodb)$ vendor/phpunit/phpunit/phpunit --configuration vendor/doctrine/mongodb-odm/phpunit.xml
expected result as here: https://twitter.com/alcaeus/status/697659616172359680 but instead got:
PHPUnit 5.2.4 by Sebastian Bergmann and contributors.
EEPHP Fatal error: Cannot use 'String' as class name as it is reserved in ~/www/symfony/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/String.php on line 23
PHP Stack trace:
PHP 1. {main}() ~/www/symfony/vendor/phpunit/phpunit/phpunit:0
PHP 2. PHPUnit_TextUI_Command::main() ~/www/symfony/vendor/phpunit/phpunit/phpunit:47
PHP 3. PHPUnit_TextUI_Command->run() ~/www/symfony/vendor/phpunit/phpunit/src/TextUI/Command.php:109
PHP 4. PHPUnit_TextUI_TestRunner->doRun() ~/www/symfony/vendor/phpunit/phpunit/src/TextUI/Command.php:158
PHP 5. PHPUnit_Framework_TestSuite->run() ~/www/symfony/vendor/doctrine/mongodb-odm/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:432
PHP 6. PHPUnit_Framework_TestSuite->run() ~/www/symfony/vendor/doctrine/mongodb-odm/vendor/phpunit/phpunit/src/Framework/TestSuite.php:747
PHP 7. PHPUnit_Framework_TestCase->run() ~/www/symfony/vendor/doctrine/mongodb-odm/vendor/phpunit/phpunit/src/Framework/TestSuite.php:747
PHP 8. PHPUnit_Framework_TestResult->run() ~/www/symfony/vendor/doctrine/mongodb-odm/vendor/phpunit/phpunit/src/Framework/TestCase.php:800
PHP 9. PHPUnit_Framework_TestCase->runBare() ~/www/symfony/vendor/doctrine/mongodb-odm/vendor/phpunit/phpunit/src/Framework/TestResult.php:685
PHP 10. PHPUnit_Framework_TestCase->runTest() ~/www/symfony/vendor/doctrine/mongodb-odm/vendor/phpunit/phpunit/src/Framework/TestCase.php:844
PHP 11. ReflectionMethod->invokeArgs() ~/www/symfony/vendor/doctrine/mongodb-odm/vendor/phpunit/phpunit/src/Framework/TestCase.php:984
PHP 12. Doctrine\ODM\MongoDB\Tests\DocumentManagerTest->testCustomRepositoryMappedsuperclassChild() ~/www/symfony/vendor/doctrine/mongodb-odm/vendor/phpunit/phpunit/src/Framework/TestCase.php:984
PHP 13. Doctrine\ODM\MongoDB\DocumentManager->getRepository() ~/www/symfony/vendor/doctrine/mongodb-odm/tests/Doctrine/ODM/MongoDB/Tests/DocumentManagerTest.php:26
PHP 14. Doctrine\ODM\MongoDB\Repository\DefaultRepositoryFactory->getRepository() ~/www/symfony/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/DocumentManager.php:510
PHP 15. Doctrine\ODM\MongoDB\Repository\DefaultRepositoryFactory->createRepository() ~/www/symfony/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Repository/DefaultRepositoryFactory.php:30
PHP 16. Doctrine\ODM\MongoDB\DocumentManager->getClassMetadata() ~/www/symfony/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Repository/DefaultRepositoryFactory.php:47
PHP 17. Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor() ~/www/symfony/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/DocumentManager.php:288
PHP 18. Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata() ~/www/symfony/vendor/doctrine/mongodb-odm/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:225
PHP 19. Doctrine\ODM\MongoDB\Mapping\ClassMetadataFactory->doLoadMetadata() ~/www/symfony/vendor/doctrine/mongodb-odm/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:332
PHP 20. Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver->loadMetadataForClass() ~/www/symfony/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataFactory.php:155
PHP 21. Doctrine\Common\Annotations\AnnotationReader->getPropertyAnnotations() ~/www/symfony/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Mapping/Driver/AnnotationDriver.php:154
PHP 22. Doctrine\Common\Annotations\DocParser->parse() ~/www/symfony/vendor/doctrine/mongodb-odm/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationReader.php:226
PHP 23. Doctrine\Common\Annotations\DocParser->Annotations() ~/www/symfony/vendor/doctrine/mongodb-odm/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php:334
PHP 24. Doctrine\Common\Annotations\DocParser->Annotation() ~/www/symfony/vendor/doctrine/mongodb-odm/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php:641
PHP 25. Doctrine\Common\Annotations\DocParser->classExists() ~/www/symfony/vendor/doctrine/mongodb-odm/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php:707
PHP 26. Doctrine\Common\Annotations\AnnotationRegistry::loadAnnotationClass() ~/www/symfony/vendor/doctrine/mongodb-odm/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php:447
PHP 27. call_user_func:{~/www/symfony/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationRegistry.php:145}() ~/www/symfony/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationRegistry.php:145
PHP 28. class_exists() ~/www/symfony/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationRegistry.php:145
PHP 29. spl_autoload_call() ~/www/symfony/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationRegistry.php:145
PHP 30. Composer\Autoload\ClassLoader->loadClass() ~/www/symfony/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationRegistry.php:145
PHP 31. Composer\Autoload\includeFile() ~/www/symfony/vendor/composer/ClassLoader.php:301
But I've seen already this issue related with PHP7 types declaration compatibility in mongodb-odm repo, so I will look for solution there. Thanks.
UPDATE
I've seen that you merged PR with fixing PHP7 incompat. issues: https://github.com/doctrine/mongodb-odm/commit/f66da89b9b9103532c01081c4d8a95d141d15c35
So I switched to master branch for doctrine/mongodb-odm
run the tests again but now im getting: https://gist.github.com/ustrugany/75917e780ba9ae733d0d
Ah, yeah. I've played around with this stuff for too long.
ext-mongo
to decide whether to use the Mongo
or MongoClient
class. This check is removed in the upcoming 1.3 release, so you'll have to use dev-master
for now - I forgot to add this to composer.json
(I've added it now).dev-master
for doctrine/mongodb-odm as well (which I forgot to change in the composer.json
example above; I've added it in the meantime) to avoid issues running in PHP 7.String
, Integer
, Boolean
and Float
classes can't be loaded in PHP 7 since the type names are now reserved words and can't be used. This is one reason why they have been deprecated for the upcoming 1.1 release. Instead of using them, please use the Field
annotation:/**
* This won't work
* @ODM\String
*/
protected $notWorkingField;
/**
* Use this in the future
* @ODM\Field(type="string")
*/
protected $workingField;
I've written all of these issues down to add them to the official documentation once the time comes.
@alcaeus I ended up with this composer.json
:
10 "provide": { "ext-mongo": "1.6.12" },
11 "require": {
12 "php": ">=5.3.9",
13 "phpunit/phpunit": "5.2.*",
14 "symfony/symfony": "2.8.*",
15 "doctrine/orm": "^2.4.8",
16 "doctrine/doctrine-bundle": "~1.4",
17 "symfony/swiftmailer-bundle": "~2.3",
18 "symfony/monolog-bundle": "~2.4",
19 "sensio/distribution-bundle": "~5.0",
20 "sensio/framework-extra-bundle": "^3.0.2",
21 "incenteev/composer-parameter-handler": "~2.0",
22 "alcaeus/mongo-php-adapter": "dev-master",
23 "doctrine/mongodb": "dev-master",
24 "doctrine/mongodb-odm": "dev-master",
25 "doctrine/mongodb-odm-bundle": "dev-master"
26 },
I have setup quickly simple CRUD application and for now it seems to be working.
Wondering though why doctrine/mongodb-odm
tests are still failing when try to run:
piotras@:~/www/symfony (searcher-bundle-mongodb)$ vendor/phpunit/phpunit/phpunit --configuration vendor/doctrine/mongodb-odm/phpunit.xml --stop-on-error --stop-on-failure
PHPUnit 5.2.4 by Sebastian Bergmann and contributors.
E
Time: 785 ms, Memory: 18.00Mb
There was 1 error:
1) Doctrine\ODM\MongoDB\Tests\DocumentManagerTest::testCustomRepository
MongoDB\Driver\Exception\RuntimeException: can't drop system ns
/home/piotras/www/symfony/vendor/doctrine/mongodb-odm/vendor/mongodb/mongodb/src/Operation/DropCollection.php:59
/home/piotras/www/symfony/vendor/doctrine/mongodb-odm/vendor/mongodb/mongodb/src/Collection.php:364
/home/piotras/www/symfony/vendor/doctrine/mongodb-odm/vendor/alcaeus/mongo-php-adapter/lib/Mongo/MongoCollection.php:236
/home/piotras/www/symfony/vendor/doctrine/mongodb-odm/tests/Doctrine/ODM/MongoDB/Tests/BaseTest.php:38
/home/piotras/www/symfony/vendor/phpunit/phpunit/src/TextUI/Command.php:158
/home/piotras/www/symfony/vendor/phpunit/phpunit/src/TextUI/Command.php:109
FAILURES!
Tests: 1, Assertions: 1, Errors: 1.
Notes: I am using Mongo 3.2.
I had a similar error when running a large MongoDB project against the adapter, so I'm going to be checking that out as well. Quite weird though since the ODM test suite still runs fine for me here. I'll let you know once I find something, thanks for the report!
Maybe this is matter of Mongo version. Thanks for help!
It shouldn't since I'm running 3.2 here as well.
@ustrugany Since I can't reproduce this here, could you run the following in the mongo shell and paste the output?
use doctrine_odm_tests
show collections
Never mind - I've found the issue. System collections weren't properly filtered out so on databases migrated from older versions you would have the system.indexes
or system.namespaces
collections present which the adapter listed as well. Working on a fix now.
The issue with system collections was fixed in #59, should work for you now.
@alcaeus thanks for quick reaction. Yes tearDown()
phpunit method was trying to drop system*
collections. I bypassed it by filtering out names of collections, but even though i still was getting some tests failures. I will double check it.
Using this:
foreach ($collections as $collection) {
if (!preg_match('/system\..*/', $collection->getName())) {
$collection->drop();
}
}
Gave me result:
piotras@:~/www/symfony (searcher-bundle-mongodb)$ vendor/phpunit/phpunit/phpunit --configuration vendor/doctrine/mongodb-odm/phpunit.xml --stop-on-error --stop-on-failure
PHPUnit 5.2.4 by Sebastian Bergmann and contributors.
............................................................. 61 / 1045 ( 5%)
............................................................. 122 / 1045 ( 11%)
............................................................. 183 / 1045 ( 17%)
............................................................. 244 / 1045 ( 23%)
............................................................. 305 / 1045 ( 29%)
............................................................. 366 / 1045 ( 35%)
............................................................. 427 / 1045 ( 40%)
............................................................. 488 / 1045 ( 46%)
............................................................. 549 / 1045 ( 52%)
............................................................. 610 / 1045 ( 58%)
............................................................. 671 / 1045 ( 64%)
............................................................. 732 / 1045 ( 70%)
............................................................. 793 / 1045 ( 75%)
............................................................. 854 / 1045 ( 81%)
............................................................. 915 / 1045 ( 87%)
..........................................S.................. 976 / 1045 ( 93%)
............................................................. 1037 / 1045 ( 99%)
........ 1045 / 1045 (100%)
Time: 25.99 seconds, Memory: 130.00Mb
OK, but incomplete, skipped, or risky tests!
Tests: 1045, Assertions: 4132, Skipped: 1.
Yeah and your fix actually do similar thing. Nice. Thanks again for help. I think that this thread can be closed.
Glad to hear it worked for you!
Is it possible to configure doctrine/mongodb-odm to work with ext-mongodb instead of ext-mongo using alcaeus/mongo-php-adapter? I followed instructions included your adapter in doctrine/mongodb-odm@dev-master but yet while running tests, i've got plenty of errors...
modified doctrine/mongodb-odm composer.json: