首页 > 解决方案 > 无法在 CircleCi 中生成代码覆盖率

问题描述

下面是我的配置文件

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

      # 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
      - image: circleci/mysql:8.0.20-ram
        command: mysqld --default-authentication-plugin=mysql_native_password
        environment:
          WITH_XDEBUG: 1
          MYSQL_USER: root
          MYSQL_DATABASE: furahasms_testing
          MYSQL_ROOT_PASSWORD: ''
          MYSQL_PASSWORD: ''

    steps:
      - checkout
      - run:
          name: Install MySQL driver
          command: |
            sudo docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd
            sudo docker-php-ext-install zip bcmath pdo_mysql
            sudo apt-get install -y libzip-dev
            sudo apt-get update && sudo apt-get install -y \
                 libfreetype6-dev \
                 libjpeg62-turbo-dev \
                 libpng-dev \
                 && sudo docker-php-ext-configure gd --with-freetype --with-jpeg \
                 && sudo docker-php-ext-install -j$(nproc) gd

      # composer cache
      - restore_cache:
          keys:
          # "composer.json" can be used if "composer.json"
          # is not committed to the repository.
          - composer-v1-{{ checksum "composer.lock" }}
          # fallback to using the latest cache if no exact match is found
          - composer-v1-
      - run: composer install -n --prefer-dist
      - run: composer require --dev php-coveralls/php-coveralls
      - save_cache:
          key: composer-v1-{{ checksum "composer.lock" }}
          paths:
            - vendor

      # prepare the database
      - run: cp .env.travis .env
      - run: cp .env.testing.travis .env.testing
      - run: touch storage/furahasms_testing.sqlite
      - run: php artisan migrate --env=testing --database=mysql --force

      # run tests with phpunit
      # - run: php artisan test --coverage-html tests/coverage 
      - run: 
          command: sudo php -d memory_limit=-1 ./vendor/bin/phpunit --coverage-clover tests/coverage/clover.xml
          environment: 
            XDEBUG_MODE: coverage
      - run: ./vendor/bin/php-coveralls -v
      
      - store_test_results:
          path: tests/coverage
      - store_artifacts:
          path: tests/coverage

workflows:
  version: 2
  workflow:
    jobs:
    - test

除了生成代码覆盖率之外,构建成功。如果我删除以下行,则构建成功但没有覆盖

environment: 
   XDEBUG_MODE: coverage

如果我添加上面的行,我会在构建中收到以下错误

#!/bin/bash -eo pipefail
./vendor/bin/phpunit
PHPUnit 9.5.4 by Sebastian Bergmann and contributors.

...............................................................  63 / 381 ( 16%)
............................................................... 126 / 381 ( 33%)
............................................................... 189 / 381 ( 49%)
............................................................... 252 / 381 ( 66%)
............................................................... 315 / 381 ( 82%)
............................................................... 378 / 381 ( 99%)
...                                                             381 / 381 (100%)

Time: 00:41.454, Memory: 122.50 MB

OK (381 tests, 808 assertions)

Generating code coverage report in Clover XML format ... 
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /home/circleci/project/vendor/nikic/php-parser/lib/PhpParser/Parser/Php7.php on line 1732

Fatal error: Uncaught ErrorException: Function must be enabled in php.ini by setting 'xdebug.mode' to 'develop' in /home/circleci/project/vendor/symfony/error-handler/Error/FatalError.php:37
Stack trace:
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'Function must b...', '/home/circleci/...', 37)
#1 /home/circleci/project/vendor/symfony/error-handler/Error/FatalError.php(37): xdebug_get_function_stack()
#2 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(143): Symfony\Component\ErrorHandler\Error\FatalError->__construct('Allowed memory ...', 0, Array, 0)
#3 /home/circleci/project/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(130): Illuminate\Foundation\Bootstrap\HandleExceptions->fatalErrorFromPhpError(Array, 0)
#4 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleShutdown()
#5 {main}
  thrown in /home/circleci/project/vendor/symfony/error-handler/Error/FatalError.php on line 37

Exited with code exit status 255
CircleCI received exit code 255

构建传递除了 ./vendor/bin/phpunit

我该如何解决这个错误

更新

我已经设法解决了内存问题,但现在我在下面

#!/bin/bash -eo pipefail
./vendor/bin/php-coveralls -v

In Configurator.php line 152:
                                                                                 
  [Symfony\Component\Config\Definition\Exception\InvalidConfigurationException]  
  coverage_clover XML file is not readable: /home/circleci/project/tests/cove    
  rage/clover.xml                                                                
                                                                                 

Exception trace:
  at /home/circleci/project/vendor/php-coveralls/php-coveralls/src/Bundle/CoverallsBundle/Config/Configurator.php:152
 PhpCoveralls\Bundle\CoverallsBundle\Config\Configurator->getGlobPaths() at /home/circleci/project/vendor/php-coveralls/php-coveralls/src/Bundle/CoverallsBundle/Config/Configurator.php:178
 PhpCoveralls\Bundle\CoverallsBundle\Config\Configurator->getGlobPathsFromStringOption() at /home/circleci/project/vendor/php-coveralls/php-coveralls/src/Bundle/CoverallsBundle/Config/Configurator.php:128
 PhpCoveralls\Bundle\CoverallsBundle\Config\Configurator->ensureCloverXmlPaths() at /home/circleci/project/vendor/php-coveralls/php-coveralls/src/Bundle/CoverallsBundle/Config/Configurator.php:106
 PhpCoveralls\Bundle\CoverallsBundle\Config\Configurator->createConfiguration() at /home/circleci/project/vendor/php-coveralls/php-coveralls/src/Bundle/CoverallsBundle/Config/Configurator.php:36
 PhpCoveralls\Bundle\CoverallsBundle\Config\Configurator->load() at /home/circleci/project/vendor/php-coveralls/php-coveralls/src/Bundle/CoverallsBundle/Command/CoverallsJobsCommand.php:182
 PhpCoveralls\Bundle\CoverallsBundle\Command\CoverallsJobsCommand->loadConfiguration() at /home/circleci/project/vendor/php-coveralls/php-coveralls/src/Bundle/CoverallsBundle/Command/CoverallsJobsCommand.php:150
 PhpCoveralls\Bundle\CoverallsBundle\Command\CoverallsJobsCommand->execute() at /home/circleci/project/vendor/symfony/console/Command/Command.php:256
 Symfony\Component\Console\Command\Command->run() at /home/circleci/project/vendor/symfony/console/Application.php:971
 Symfony\Component\Console\Application->doRunCommand() at /home/circleci/project/vendor/symfony/console/Application.php:290
 Symfony\Component\Console\Application->doRun() at /home/circleci/project/vendor/symfony/console/Application.php:166
 Symfony\Component\Console\Application->run() at /home/circleci/project/vendor/php-coveralls/php-coveralls/bin/php-coveralls:22

coveralls:v1:jobs [-c|--config [CONFIG]] [--dry-run] [--exclude-no-stmt] [-e|--env [ENV]] [-x|--coverage_clover COVERAGE_CLOVER] [-o|--json_path JSON_PATH] [--entry_point ENTRY_POINT] [-r|--root_dir [ROOT_DIR]] [-k|--insecure]


Exited with code exit status 1
CircleCI received exit code 1

标签: phplaravelcircleci

解决方案


推荐阅读