doctrine / DoctrinePHPCRBundle

This bundle integrates Doctrine PHPCR ODM and PHPCR backends into Symfony
http://phpcr.github.com
MIT License
156 stars 66 forks source link

phpunit test fails to connect to existing DB @ specified DSN #321

Closed ghost closed 6 years ago

ghost commented 6 years ago

for

bin/console --version
    Symfony 4.0.5 (kernel: src, env: dev, debug: true)

composer show | egrep -i "doctrine|phpcr"
    Do not run Composer as root/super user! See https://getcomposer.org/root for details
    doctrine/annotations                     v1.6.0             Docblock Annotations Parser
    doctrine/cache                           v1.7.1             Caching library offering an object-oriented API for many cache backends
    doctrine/collections                     v1.5.0             Collections Abstraction library
    doctrine/common                          v2.8.1             Common Library for Doctrine projects
    doctrine/data-fixtures                   v1.3.0             Data Fixtures for all Doctrine Object Managers
    doctrine/dbal                            v2.6.3             Database Abstraction Layer
    doctrine/doctrine-bundle                 1.8.1              Symfony DoctrineBundle
    doctrine/doctrine-cache-bundle           1.3.2              Symfony Bundle for Doctrine Cache
    doctrine/doctrine-migrations-bundle      v1.3.1             Symfony DoctrineMigrationsBundle
    doctrine/inflector                       v1.3.0             Common String Manipulations with regard to casing and singular/plural rules.
    doctrine/instantiator                    1.1.0              A small, lightweight utility to instantiate objects in PHP without invoking their constructors
    doctrine/lexer                           v1.0.1             Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.
    doctrine/migrations                      v1.6.2             Database Schema migrations using Doctrine DBAL
    doctrine/orm                             v2.6.1             Object-Relational-Mapper for PHP
    doctrine/phpcr-bundle                    dev-master b265cdc Symfony DoctrinePHPCRBundle
    doctrine/phpcr-odm                       1.4.4              Object-Document-Mapper for PHPCR
    jackalope/jackalope                      1.3.5              Jackalope PHPCR library
    jackalope/jackalope-doctrine-dbal        1.3.2              Jackalope Transport library for Doctrine DBAL
    phpcr/phpcr                              2.1.4              PHP Content Repository interfaces
    phpcr/phpcr-utils                        1.4.0              PHP Content Repository implementation independant utilities
    sonata-project/doctrine-extensions       1.0.2              Doctrine2 behavioral extensions
    sonata-project/doctrine-orm-admin-bundle 3.4.2              Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
    symfony/doctrine-bridge                  v4.0.5             Symfony Doctrine Bridge
    symfony/orm-pack                         v1.0.5             A pack for the Doctrine ORM

clone to test

cd <project>/tests
git clone https://github.com/doctrine/DoctrinePHPCRBundle
cd DoctrinePHPCRBundle
composer update

set up & verify database

mysql \
 --user=testuser \
 --password=testpass \
 --host=127.0.0.1 \
 --database=testdb_phpcr \
-e "show tables;"

        +----------------------------+
        | Tables_in_testdb_phpcr     |
        +----------------------------+
        ...
        | phpcr_workspaces           |
        +----------------------------+

edit DSN in 'phpunit.xml.dist'

+   <env name="DATABASE_URL" value="mysql://testuser:testpass@127.0.0.1/testdb_phpcr" />

exec test fails at database connection

./vendor/bin/simple-phpunit
    ...
    1) Doctrine\Bundle\PHPCRBundle\Tests\Functional\Form\ChoiceList\PhpcrOdmQueryBuilderLoaderTest::testGetByIds
    PHPCR\RepositoryException: Unexpected error talking to the backend: An exception occurred while executing 'SELECT 1 FROM phpcr_workspaces WHERE name = ?' with params ["default"]:
    SQLSTATE[HY000]: General error: 1 no such table: phpcr_workspaces

current, parent project config includes

doctrine_phpcr.yaml
    doctrine_phpcr:
        session:
            backend:
                type: doctrinedbal
                connection: phpcr_main
                caches:
                    meta: doctrine_cache.providers.phpcr_meta
                    nodes: doctrine_cache.providers.phpcr_nodes
                logging: true
                profiling: true
                parameters:
                    jackalope.factory: Jackalope\Factory
                    jackalope.check_login_on_server: false
                    jackalope.disable_stream_wrapper: false
                    jackalope.auto_lastmodified: true
                    jackalope.disable_transactions: false

            workspace: default
            username: '%db_phpcr.user%'
            password: '%db_phpcr.pass%'
            options:
                jackalope.fetch_depth: 1

        odm:
            default_document_manager: default
            auto_generate_proxy_classes: '%kernel.debug%'
            proxy_dir: "%kernel.cache_dir%/doctrine/PHPCRProxies"
            proxy_namespace: PHPCRProxies
            locales:
                en: [de, fr]
            locale_fallback: hardcoded
            default_locale: en
            document_managers:
                default:
                    auto_mapping: true
                    mappings:
                        SonataMediaBundle:
                            prefix: App\Application\Sonata\MediaBundle\PHPCR
                        ApplicationSonataMediaBundle:
                            prefix: App\Application\Sonata\MediaBundle\PHPCR
                    metadata_cache_driver:
                        type: array

doctrine.yaml
    doctrine:
        dbal:
            default_connection: main
            connections:
                main:
                    dbname: '%db.name%'
                    user: '%db.user%'
                    password: '%db.pass%'
                    unix_socket: '%db.socket%'
                    driver: 'pdo_mysql'
                    server_version: '5.7'
                    charset: utf8mb4
                    default_table_options:
                        charset: utf8mb4
                        collate: utf8mb4_unicode_ci
                phpcr_main:
                    dbname: '%db_phpcr.name%'
                    user: '%db_phpcr.user%'
                    password: '%db_phpcr.pass%'
                    unix_socket: '%db_phpcr.socket%'
                    driver: 'pdo_mysql'
                    server_version: '5.7'
                    charset: utf8mb4
                    default_table_options:
                        charset: utf8mb4
                        collate: utf8mb4_unicode_ci
            types:
                json: Sonata\Doctrine\Types\JsonType
        orm:
            default_entity_manager: default
            auto_generate_proxy_classes: '%kernel.debug%'
            entity_managers:
                default:
                    naming_strategy: doctrine.orm.naming_strategy.underscore
                    auto_mapping: true
                    mappings:
                        App:
                            is_bundle: false
                            type: annotation
                            dir: '%kernel.project_dir%/src/Entity'
                            prefix: 'App\Entity'
                            alias: App
                        SonataUserBundle: ~
                        SonataPageBundle:
                        FOSUserBundle: ~
                        SonataNotificationBundle: ~
                        ApplicationSonataUserBundle:
                        ApplicationSonataPageBundle:
                        ApplicationSonataNotificationBundle:

                    metadata_cache_driver: redis
                    query_cache_driver: redis
                    result_cache_driver: redis
                    second_level_cache:
                        region_cache_driver:
                            type: service
                            id: snc_second_level_cache
                        enabled: true
                        log_enabled: true
                        region_lifetime: 86400
ElectricMaxxx commented 6 years ago

Ah there is more, thanks. I would have a look.

dbu commented 6 years ago

are you running the init commands? we do this for this bundle itself: https://github.com/doctrine/DoctrinePHPCRBundle/blob/b265cdca6f04206ac6a7ef771f9cb1bf8749ea30/.travis/phpcr_odm_doctrine_dbal.sh

ghost commented 6 years ago

Yes, the init's been run.

Otherwise, you wouldn't see:

        +----------------------------+
        | Tables_in_testdb_phpcr     |
        +----------------------------+
        ...
        | phpcr_workspaces           |
        +----------------------------+
dbu commented 6 years ago

hm, this is odd. could it be that the wrong database is initialized? i see that the db name is testdb, but is that the one configured in your config_test or the one from config_dev? i feel it must be something about the setup / bootstrapping, because its not fundamentally broken (tests of the packages work on travis-ci).

ghost commented 6 years ago

No, the db name is

testdb_phpcr

It's the only DB i'm referencing here.

dbu commented 6 years ago

well, as you see that the table exists, and then the test says it does not, either something destroys the table during your bootstrap, or its talking to different databases. the tests of this bundle work, so its not fundamentally broken and must be something in the bootstrap or setup

ghost commented 6 years ago

Which is exactly why I'd asked in #channnel for examples of running this specific test, and was subsequently asked to 1st provide documentation of this problem.

dbu commented 6 years ago

the tests do run here: https://travis-ci.org/doctrine/DoctrinePHPCRBundle

i unfortunately don't know what goes wrong with your test run, the configuration you pasted looks sane. and the error sounds so fundamental that i suspect that the setup / bootstrapping must be the problem.

dbu commented 6 years ago

i can't reproduce the problem, closing this issue for now. if you have further details that help to debug the issue, lets reopen this or discuss in slack.