【问题标题】:How to test laravel 5.2 projects with Travis CI如何使用 Travis CI 测试 laravel 5.2 项目
【发布时间】:2016-06-24 16:39:07
【问题描述】:

我在 Laravel 5.2 中做了一个项目,它的源代码部署在 github here。我在使用 PHPUnit 测试项目并与 Travis-CI 集成时遇到问题。

这是我的 Travis-CI 配置文件:

language: php

php:
  - 5.6

before_script:
  - cp .env.travis .env
  - mysql -e 'create database homestead_test;'
  - composer self-update
  - composer install --no-interaction
  - php artisan key:generate

script:
  - vendor/bin/phpunit

这是我的 PHPUnit.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
         backupStaticAttributes="false"
         bootstrap="bootstrap/autoload.php"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false">
    <testsuites>
        <testsuite name="Application Test Suite">
            <directory suffix="Test.php">./tests</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./app</directory>
            <exclude>
                <file>./app/Http/routes.php</file>
            </exclude>
        </whitelist>
    </filter>
    <php>
        <env name="APP_ENV" value="testing"/>
        <env name="CACHE_DRIVER" value="array"/>
        <env name="SESSION_DRIVER" value="array"/>
        <env name="QUEUE_DRIVER" value="sync"/>
    </php>
</phpunit>

其他文件可以在我的存储库中看到。如果您需要任何说明,请在下方评论。

我的 travis Build 可以看到here

这是我在 Travis 构建中遇到的错误:

PHP Warning:  require(/home/travis/build/TheOpenBlog/TheOpenBlog/bootstrap/../vendor/autoload.php): failed to open stream: No such file or directory in /home/travis/build/TheOpenBlog/TheOpenBlog/bootstrap/autoload.php on line 17

【问题讨论】:

    标签: php database laravel-5.2 travis-ci


    【解决方案1】:

    我自己想通了。我创建的数据库错误。

    正确的 .travis.yml 文件是

    language: php
    
    php:
      - 5.6
    
    before_script:
      - cp .env.travis .env
      - mysql -e 'create database TheOpenBlog_tests;'
      - composer self-update
      - composer install --no-interaction
      - php artisan key:generate
    
    script:
      - vendor/bin/phpunit
    

    更正了 .env.travis 文件

    APP_ENV=TheOpenBlog_testing
    APP_KEY=SomeRandomString
    
    DB_CONNECTION=TheOpenBlog_testing
    DB_DATABASE=TheOpenBlog_tests
    DB_USERNAME=root
    DB_PASSWORD=
    
    CACHE_DRIVER=array
    SESSION_DRIVER=array
    QUEUE_DRIVER=sync
    

    最后加上这个

    <env name="APP_ENV" value="TheOpenBlog_testing"/>
    

    并删除它

    <env name="DB_CONNECTION" value="TheOpenBlog_testing"/>
    

    【讨论】:

      猜你喜欢
      • 2015-01-04
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多