1
votes

Im trying to use sqlite base in my behat tests in symfony2. As far as im am, behat in symfony2 finds my base, and can create fixtures in it. Problem is my test site cannot connect to this base.

This is my config_test.yml:

doctrine:
    dbal:
        driver:   pdo_sqlite
        host:     127.0.0.1
        dbname:   "%database_name%_test"
        path:     tests/eg_test.db

This is my config.yml:

doctrine:
    dbal:
        driver:   pdo_mysql
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8

This is my behat.yml:

default:
    suites:
        default:
            paths:
                features: '%paths.base%/features'
                bootstrap:  '%paths.base%/features/bootstrap'
            contexts:
                - FeatureContext: ~
                - EwidencjaContext:
                    userManager: '@fos_user.user_manager'
                    em: '@doctrine.orm.entity_manager'
                    packageManager: '@em.package_manager'
    extensions:
        Behat\Symfony2Extension: ~
        Behat\MinkExtension:
            base_url:  http://nginx/app_test.php
            goutte: ~
            selenium2:
                browser: "chrome"
                wd_host: http://selenium_chrome:4444/wd/hub
                capabilities: { "browserName": "chrome", "browser": "chrome"}
        Bex\Behat\ScreenshotExtension:
            image_drivers:
                local:
                    screenshot_directory: tests/features/images/
                    clear_screenshot_directory: true

This is log i get back after trying to log into my site. Doesn't matter if user exists or not. So its not fault of wrong password or something like that. Seems like site just dont connect to base.

[2017-03-27 10:22:09] request.INFO: Matched route "fos_user_security_check". {"route":"fos_user_security_check","route_parameters":{"_controller":"FOS\UserBundle\Controller\SecurityController::checkAction","_route":"fos_user_security_check"},"request_uri":"http://localhost/app_test.php/login_check","method":"POST"} [] [2017-03-27 10:22:10] security.INFO: Authentication request failed. {"exception":"[object] (Symfony\Component\Security\Core\Exception\AuthenticationServiceException(code: 0): An exception occured in driver: SQLSTATE[HY000] [14] unable to open database file at /var/www/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php:94, Doctrine\DBAL\Exception\ConnectionException(code: 0): An exception occured in driver: SQLSTATE[HY000] [14] unable to open database file at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php:82, Doctrine\DBAL\Driver\PDOException(code: 14): SQLSTATE[HY000] [14] unable to open database file at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:47, PDOException(code: 14): SQLSTATE[HY000] [14] unable to open database file at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43)"} [] [2017-03-27 10:22:10] security.DEBUG: Authentication failure, redirect triggered. {"failure_path":"/login"} [] [2017-03-27 10:22:10] request.INFO: Matched route "fos_user_security_login". {"route":"fos_user_security_login","route_parameters":{"_controller":"FOS\UserBundle\Controller\SecurityController::loginAction","_route":"fos_user_security_login"},"request_uri":"http://localhost/app_test.php/login","method":"GET"} [] [2017-03-27 10:22:10] security.INFO: Populated the TokenStorage with an anonymous Token. [] []

And this is error i get on my site when i try to log in from browser:

Authentication request could not be processed due to a system problem.

And error when I try to register new user:

An exception occured in driver: SQLSTATE[HY000] [14] unable to open database file

I created my sqlite database as close to standard mysql base im using on prod. After it I used bin/console doctrine:schema:update --force --env=test. My database got good file mod (-rwxrwxr-x) and is used by right user and group.

2

2 Answers

3
votes

Change your config_test.yml to this:

doctrine:
    dbal:
        connections:
            default:
                driver: pdo_sqlite
                path: %kernel.cache_dir%/default.db
                charset: UTF8

And then grant correct permissions show in here: Setting up or Fixing File Permissions You're going to run commands in either 2nd or 3rd depending on your operating system.

0
votes

If you go to your parameters.yml file you should see the path, something like this : database_path: '%kernel.project_dir%/var/data/data.sqlite', another advise : create a directory in /var and put your data.sqlite file in it

Hope it helps :)