Laravel SQLite migrates but doesn't test

When a new job starts, the application builds okay and migrates successfully, however, when the automated tests run, they all fail with a PDOException, no driver found.

They all worked when I last committed to the code a month ago, but seem to have broken now. I’ve tried updating the PHP docker image but that hasn’t helped.

My config.yml file

# PHP CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-php/ for more details
#
version: 2
jobs:
  build:
    docker:
      # Specify the version you desire here
      - image: circleci/php:7.4-apache-node-browsers

      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at https://circleci.com/docs/2.0/circleci-images/
      # Using the RAM variation mitigates I/O contention
      # for database intensive operations.
      # - image: circleci/mysql:5.7-ram
      #
      # - image: redis:3

    steps:
      - checkout

      - run: sudo apt update && sudo apt install zlib1g-dev libsqlite3-dev
      - run: sudo docker-php-ext-install zip
      - run: sudo docker-php-ext-install pdo_sqlite
      - run: sudo docker-php-ext-enable pdo_sqlite

      # Download and cache dependencies

      # composer cache
      - restore_cache:
          keys:
          # "composer.json" can be used if "composer.json"
          # is not committed to the repository.
          - v1-dependencies-{{ checksum "composer.lock" }}
          # fallback to using the latest cache if no exact match is found
          - v1-dependencies-

      - run: composer install -n --prefer-dist

      - save_cache:
          key: composer-v1-{{ checksum "composer.lock" }}
          paths:
            - vendor

      # node cache

      - restore_cache:
          keys:
            - node-v4-{{ checksum "package.json" }}
            - node-v4-
      - run: npm install
      - save_cache:
          key: node-v4-{{ checksum "package.json" }}
          paths:
            - node_modules
            - ~/.yarn

      # Prepare the environment
      - run: mv .env.testing .env
      - run: php artisan key:generate

      # prepare the database
      - run: touch storage/testing.sqlite
      - run: php artisan migrate --env=testing --database=sqlite_testing

  test_functional:
    requires:
      - build

    docker:
      # Specify the version you desire here
      - image: circleci/php:7.4-apache-node-browsers

      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at https://circleci.com/docs/2.0/circleci-images/
      # Using the RAM variation mitigates I/O contention
      # for database intensive operations.
      # - image: circleci/mysql:5.7-ram
      #
      # - image: redis:3

    steps:
      - checkout

      - run: sudo apt update && sudo apt install zlib1g-dev libsqlite3-dev
      - run: sudo docker-php-ext-install zip
      - run: sudo docker-php-ext-install pdo_sqlite
      - run: sudo docker-php-ext-enable pdo_sqlite

      # Download and cache dependencies

      # composer cache
      - restore_cache:
          keys:
            # "composer.json" can be used if "composer.json"
            # is not committed to the repository.
            - v1-dependencies-{{ checksum "composer.lock" }}
            # fallback to using the latest cache if no exact match is found
            - v1-dependencies-

      - run: composer install -n --prefer-dist

      - save_cache:
          key: composer-v1-{{ checksum "composer.lock" }}
          paths:
            - vendor

      # node cache

      - restore_cache:
          keys:
            - node-v4-{{ checksum "package.json" }}
            - node-v4-
      - run: npm install
      - save_cache:
          key: node-v4-{{ checksum "package.json" }}
          paths:
            - node_modules
            - ~/.yarn

      # Prepare the environment
      - run: mv .env.testing .env
      - run: php artisan key:generate

      # prepare the database
      - run: touch storage/testing.sqlite
      - run: php artisan migrate --env=testing --database=sqlite_testing

      # run tests with phpunit or codecept
      #- run: ./vendor/bin/phpunit
      # this example uses codecept but you're not limited to it
      - run: ./vendor/bin/codecept build
      - run: ./vendor/bin/codecept run functional --xml result.xml
      - store_test_results:
          path: tests/_output
      - store_artifacts:
          path: tests/_output

  test_unit:
    requires:
      - build

    docker:
      # Specify the version you desire here
      - image: circleci/php:7.4-apache-node-browsers

      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at https://circleci.com/docs/2.0/circleci-images/
      # Using the RAM variation mitigates I/O contention
      # for database intensive operations.
      # - image: circleci/mysql:5.7-ram
      #
      # - image: redis:3

    steps:
      - checkout

      - run: sudo apt update && sudo apt install zlib1g-dev libsqlite3-dev
      - run: sudo docker-php-ext-install zip
      - run: sudo docker-php-ext-install pdo_sqlite
      - run: sudo docker-php-ext-enable pdo_sqlite

      # Download and cache dependencies

      # composer cache
      - restore_cache:
          keys:
            # "composer.json" can be used if "composer.json"
            # is not committed to the repository.
            - v1-dependencies-{{ checksum "composer.lock" }}
            # fallback to using the latest cache if no exact match is found
            - v1-dependencies-

      - run: composer install -n --prefer-dist

      - save_cache:
          key: composer-v1-{{ checksum "composer.lock" }}
          paths:
            - vendor

      # node cache

      - restore_cache:
          keys:
            - node-v4-{{ checksum "package.json" }}
            - node-v4-
      - run: npm install
      - save_cache:
          key: node-v4-{{ checksum "package.json" }}
          paths:
            - node_modules
            - ~/.yarn

      # Prepare the environment
      - run: mv .env.testing .env
      - run: php artisan key:generate

      # prepare the database
      - run: touch storage/testing.sqlite
      - run: php artisan migrate --env=testing --database=sqlite_testing

      # run tests with phpunit or codecept
      #- run: ./vendor/bin/phpunit
      # this example uses codecept but you're not limited to it
      - run: ./vendor/bin/codecept build
      - run: ./vendor/bin/codecept run functional --xml result.xml
      - store_test_results:
          path: tests/_output
      - store_artifacts:
          path: tests/_output

  test_coverage:
    requires:
      - build

    docker:
      # Specify the version you desire here
      - image: circleci/php:7.3-stretch-node-browsers

      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at https://circleci.com/docs/2.0/circleci-images/
      # Using the RAM variation mitigates I/O contention
      # for database intensive operations.
      # - image: circleci/mysql:5.7-ram
      #
      # - image: redis:3

    steps:
      - checkout

      - run: sudo apt update && sudo apt install zlib1g-dev libsqlite3-dev
      - run: sudo docker-php-ext-install zip
      - run: sudo docker-php-ext-install pdo_sqlite
      - run: sudo docker-php-ext-enable pdo_sqlite

      # Download and cache dependencies

      # composer cache
      - restore_cache:
          keys:
            # "composer.json" can be used if "composer.json"
            # is not committed to the repository.
            - v1-dependencies-{{ checksum "composer.lock" }}
            # fallback to using the latest cache if no exact match is found
            - v1-dependencies-

      - run: composer install -n --prefer-dist

      - save_cache:
          key: composer-v1-{{ checksum "composer.lock" }}
          paths:
            - vendor

      # node cache

      - restore_cache:
          keys:
            - node-v4-{{ checksum "package.json" }}
            - node-v4-
      - run: npm install
      - save_cache:
          key: node-v4-{{ checksum "package.json" }}
          paths:
            - node_modules
            - ~/.yarn

      # Prepare the environment
      - run: mv .env.testing .env
      - run: php artisan key:generate

      # prepare the database
      - run: touch storage/testing.sqlite
      - run: php artisan migrate --env=testing --database=sqlite_testing

      # run tests with phpunit or codecept
      #- run: ./vendor/bin/phpunit
      # this example uses codecept but you're not limited to it
      - run: ./vendor/bin/codecept build
      - run: ./vendor/bin/codecept run --coverage --coverage-html --xml results.xml
      - store_test_results:
          path: tests/_output
      - store_artifacts:
          path: tests/_output

  deploy_dev:
    docker:
      - image: circleci/php:7.3-stretch-node-browsers
    working_directory: ~/laravel
    steps:
      - checkout
      - add_ssh_keys:
          fingerprints:
            - 
      - run: ssh-keyscan -H rl-test-1.vesula.com >> ~/.ssh/known_hosts
      - run:
          name: Install Deployer
          command: |
            curl -LO https://deployer.org/deployer.phar
            sudo mv deployer.phar /usr/local/bin/dep
            sudo chmod +x /usr/local/bin/dep
      - run:
          name: Deploy
          command: |
            dep deploy testing -vvv
      - store_artifacts:
          path: tests/_output

workflows:
  version: 2
  test_new_code:
    jobs:
      - test_functional:
          filters:
            branches:
              ignore:
                - master
                - /release/*/
      - test_unit:
          filters:
            branches:
              ignore:
                - master
                - /release/*/
  test_deploy_nightly:
    triggers:
      - schedule:
          cron: "0 0 * * *"
          filters:
            branches:
              only:
                - develop
    jobs:
      - test_coverage:
          filters:
            branches:
              only:
                - develop
      - deploy_dev:
          requires:
            - test_coverage
          filters:
            branches:
              only:
                - develop

PHP artisan:migrate output:

#!/bin/bash -eo pipefail 
php artisan migrate --env=testing --database=sqlite_testing 
Migration table created successfully.

(migration confirmations)
 
CircleCI received exit code 0 

Test output:

#!/bin/bash -eo pipefail 
./vendor/bin/codecept run functional --xml result.xml 
Codeception PHP Testing Framework v4.1.6
 
Powered by PHPUnit 7.5.20 by Sebastian Bergmann and contributors.
 
Running with seed: 
 

 

 
Functional Tests (20) --------------------------------------
 
E LogsCest: View all logs 
 
E LogsCest: Create log 
 
E NoAuthCest: Check default home page 
 
E NoAuthCest: Navigate to register 
 
E NoAuthCest: Navigate to sign in 
 
E NoAuthCest: Check url permissions 
 
E NoSubCest: Check default home page 
 
E NoSubCest: Check url permissions 
 
E NoSubCest: Try login with auth 
 
E RegistrationCest: Register user correctly 
 
E RegistrationCest: Test a user can't register with not matching passwords 
 
E RegistrationCest: Try short password 
 
E RegistrationCest: Try used email 
 
E StockViewCest: Check multiple unit list 
 
E StockViewCest: Check locomotive list 
 
E SubCest: Check default homepage 
 
E SubCest: Check blank homepage 
 
E SubCest: Check unit homepage 
 
E SubCest: Try login with sub 
 
E SubCest: Try register with sub 
 
------------------------------------------------------------
 

 

 
Time: 366 ms, Memory: 24.00 MB
 

 
There were 20 errors:
 

 
---------
 
1) LogsCest: View all logs
 
 Test  tests/functional/LogsCest.php:viewAllLogs
 
                                        
 
  [PDOException] could not find driver  
 
                                        
 
#1  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
 
#2  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:46
 
#3  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php:24
 
#4  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php:182
 
#5  Illuminate\Database\Connectors\ConnectionFactory->Illuminate\Database\Connectors\{closure}
 
#6  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:924
 
#7  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php:123
 
#8  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php:105
 
#9  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php:349
 
#10 /home/circleci/project/vendor/symfony/event-dispatcher/EventDispatcher.php:264
 

 
---------
 
2) LogsCest: Create log
 
 Test  tests/functional/LogsCest.php:createLog
 
                                        
 
  [PDOException] could not find driver  
 
                                        
 
#1  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
 
#2  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:46
 
#3  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php:24
 
#4  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php:182
 
#5  Illuminate\Database\Connectors\ConnectionFactory->Illuminate\Database\Connectors\{closure}
 
#6  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:924
 
#7  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php:123
 
#8  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php:105
 
#9  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php:349
 
#10 /home/circleci/project/vendor/symfony/event-dispatcher/EventDispatcher.php:264
 

 
---------
 
3) NoAuthCest: Check default home page
 
 Test  tests/functional/NoAuthCest.php:checkDefaultHomePage
 
                                        
 
  [PDOException] could not find driver  
 
                                        
 
#1  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
 
#2  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:46
 
#3  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php:24
 
#4  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php:182
 
#5  Illuminate\Database\Connectors\ConnectionFactory->Illuminate\Database\Connectors\{closure}
 
#6  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:924
 
#7  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php:123
 
#8  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php:105
 
#9  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php:349
 
#10 /home/circleci/project/vendor/symfony/event-dispatcher/EventDispatcher.php:264
 

 
---------
 
4) NoAuthCest: Navigate to register
 
 Test  tests/functional/NoAuthCest.php:navigateToRegister
 
                                        
 
  [PDOException] could not find driver  
 
                                        
 
#1  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
 
#2  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:46
 
#3  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php:24
 
#4  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php:182
 
#5  Illuminate\Database\Connectors\ConnectionFactory->Illuminate\Database\Connectors\{closure}
 
#6  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:924
 
#7  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php:123
 
#8  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php:105
 
#9  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php:349
 
#10 /home/circleci/project/vendor/symfony/event-dispatcher/EventDispatcher.php:264
 

 
---------
 
5) NoAuthCest: Navigate to sign in
 
 Test  tests/functional/NoAuthCest.php:navigateToSignIn
 
                                        
 
  [PDOException] could not find driver  
 
                                        
 
#1  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
 
#2  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:46
 
#3  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php:24
 
#4  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php:182
 
#5  Illuminate\Database\Connectors\ConnectionFactory->Illuminate\Database\Connectors\{closure}
 
#6  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Connection.php:924
 
#7  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php:123
 
#8  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php:105
 
#9  /home/circleci/project/vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php:349
 
#10 /home/circleci/project/vendor/symfony/event-dispatcher/EventDispatcher.php:264
 
 
ERRORS!
 
Tests: 20, Assertions: 0, Errors: 20.
 
- XML report generated in file:///home/circleci/project/tests/_output/result.xml
 
 
Exited with code exit status 1 
CircleCI received exit code 1 

(Log repeats for each test, I’ve removed some of it due to forum character limitations)

Any help would be greatly appreciated.

I have to make a lot of assumptions here cause I can’t see your jobs, so bear with me here.

      - run: sudo apt update && sudo apt install zlib1g-dev libsqlite3-dev
      - run: sudo docker-php-ext-install zip
      - run: sudo docker-php-ext-install pdo_sqlite
      - run: sudo docker-php-ext-enable pdo_sqlite

Do you see any error messages in these steps? I suspect something may have changed with the dependencies. If you re-run an old passing job does it pass again, or does it fail? Also try removing the v1-dependencies- key from your caches, so there’s no chance of old caches being loaded. Do this for your node cache as well. If you ssh into the container are you able to run the commands manually? is there a way for you to manually check and make sure the PDO driver is installed from the command line?

1 Like

Thank you for your reply.

I’ve removed the cache to no joy, also tried running the test over SSH which didn’t work either. However, the migrations continue to work as normal.

- run: sudo docker-php-ext-install pdo_sqlite
- run: sudo docker-php-ext-enable pdo_sqlite

When I checked the output of these commands, it shows warning: pdo_sqlite (pdo_sqlite.so) is already loaded! However, on the working build, it also has that output.

The tests had previously broken on my workstation (same error), and PHP required a version bump to 7.4. However, on CircleCI bumping the version doesn’t seem to have made a difference.

Using php -m I can see that PDO, sqlite3 and pdo_sqlite are loaded. Running the same command on my workstation, I can see that those are the only PDO/sqlite related extensions loaded.

Thanks.

Ok well that’s a bit sad. Can you submit a support ticket with the links to the recent jobs you ran and the las t working jobs? and reference this post. I can take a closer look at the logs.