<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # Testing PHP projects > 原文:[https://docs.gitlab.com/ee/ci/examples/php.html](https://docs.gitlab.com/ee/ci/examples/php.html) * [Test PHP projects using the Docker executor](#test-php-projects-using-the-docker-executor) * [Test against different PHP versions in Docker builds](#test-against-different-php-versions-in-docker-builds) * [Custom PHP configuration in Docker builds](#custom-php-configuration-in-docker-builds) * [Test PHP projects using the Shell executor](#test-php-projects-using-the-shell-executor) * [Test against different PHP versions in Shell builds](#test-against-different-php-versions-in-shell-builds) * [Install custom extensions](#install-custom-extensions) * [Extend your tests](#extend-your-tests) * [Using atoum](#using-atoum) * [Using Composer](#using-composer) * [Access private packages or dependencies](#access-private-packages-or-dependencies) * [Use databases or other services](#use-databases-or-other-services) * [Testing things locally](#testing-things-locally) * [Example project](#example-project) # Testing PHP projects[](#testing-php-projects "Permalink") 本指南涵蓋了 PHP 項目的基本構建說明. 涵蓋了兩種測試方案:使用 Docker 執行程序和使用 Shell 執行程序. ## Test PHP projects using the Docker executor[](#test-php-projects-using-the-docker-executor "Permalink") 盡管可以在任何系統上測試 PHP 應用程序,但這都需要開發人員進行手動配置. 為了克服這個問題,我們將使用可在 Docker Hub 中找到的官方[PHP Docker 映像](https://hub.docker.com/_/php) . 這將使我們能夠針對不同版本的 PHP 測試 PHP 項目. 但是,并非所有事情都是即插即用的,您仍然需要手動配置一些東西. 與每項工作一樣,您需要創建一個描述構建環境的有效`.gitlab-ci.yml` . 首先,讓我們指定將用于作業過程的 PHP 映像(您可以在 Runner 的術語中閱讀有關[使用 Docker 映像的](../docker/using_docker_images.html#what-is-an-image)更多信息,以了解映像的含義). 首先將圖像添加到您的`.gitlab-ci.yml` : ``` image: php:5.6 ``` 官方圖片很棒,但是缺少一些有用的測試工具. 我們需要首先準備構建環境. 解決此問題的一種方法是創建一個腳本,該腳本在完成實際測試之前會安裝所有必備組件. Let’s create a `ci/docker_install.sh` file in the root directory of our repository with the following content: ``` #!/bin/bash # We need to install dependencies only for Docker [[ ! -e /.dockerenv ]] && exit 0 set -xe # Install git (the php image doesn't have it) which is required by composer apt-get update -yqq apt-get install git -yqq # Install phpunit, the tool that we will use for testing curl --location --output /usr/local/bin/phpunit https://phar.phpunit.de/phpunit.phar chmod +x /usr/local/bin/phpunit # Install mysql driver # Here you can install any other extension that you need docker-php-ext-install pdo_mysql ``` 您可能想知道`docker-php-ext-install`是什么. 簡而言之,它是官方 PHP Docker 映像提供的腳本,可用于輕松安裝擴展. 有關更多信息,請參閱[https://hub.docker.com/_/php 上](https://hub.docker.com/_/php)的文檔. 現在,我們創建了包含構建環境的所有先決條件的腳本,讓我們將其添加到`.gitlab-ci.yml` : ``` ... before_script: - bash ci/docker_install.sh > /dev/null ... ``` 最后一步,使用`phpunit`運行實際測試: ``` ... test:app: script: - phpunit --configuration phpunit_myapp.xml ... ``` 最后,提交文件并將其推送到 GitLab,以查看構建成功(或失敗). 最終的`.gitlab-ci.yml`應該類似于以下內容: ``` # Select image from https://hub.docker.com/_/php image: php:5.6 before_script: # Install dependencies - bash ci/docker_install.sh > /dev/null test:app: script: - phpunit --configuration phpunit_myapp.xml ``` ### Test against different PHP versions in Docker builds[](#test-against-different-php-versions-in-docker-builds "Permalink") 針對多個版本的 PHP 進行測試非常容易. 只需添加另一個具有不同 Docker 映像版本的作業,即可由跑步者完成其余工作: ``` before_script: # Install dependencies - bash ci/docker_install.sh > /dev/null # We test PHP5.6 test:5.6: image: php:5.6 script: - phpunit --configuration phpunit_myapp.xml # We test PHP7.0 (good luck with that) test:7.0: image: php:7.0 script: - phpunit --configuration phpunit_myapp.xml ``` ### Custom PHP configuration in Docker builds[](#custom-php-configuration-in-docker-builds "Permalink") 有時,您需要通過將`.ini`文件放入`/usr/local/etc/php/conf.d/`來自定義 PHP 環境. 為此,添加一個`before_script`動作: ``` before_script: - cp my_php.ini /usr/local/etc/php/conf.d/test.ini ``` 當然, `my_php.ini`必須存在于存儲庫的根目錄中. ## Test PHP projects using the Shell executor[](#test-php-projects-using-the-shell-executor "Permalink") Shell 執行程序在服務器上的終端會話中運行您的作業. 因此,為了測試您的項目,您首先需要確保已安裝所有依賴項. 例如,在運行 Debian 8 的 VM 中,我們首先更新緩存,然后安裝`phpunit`和`php5-mysql` : ``` sudo apt-get update -y sudo apt-get install -y phpunit php5-mysql ``` 接下來,將以下代碼段添加到`.gitlab-ci.yml` : ``` test:app: script: - phpunit --configuration phpunit_myapp.xml ``` 最后,推送到 GitLab 并開始測試! ### Test against different PHP versions in Shell builds[](#test-against-different-php-versions-in-shell-builds "Permalink") [phpenv](https://github.com/phpenv/phpenv)項目使您可以輕松管理不同版本的 PHP,每個版本都有自己的配置. 當使用 Shell 執行程序測試 PHP 項目時,這特別有用. 您必須按照[上游安裝指南](https://github.com/phpenv/phpenv#installation)在`gitlab-runner`用戶下將其安裝在構建計算機[上](https://github.com/phpenv/phpenv#installation) . 使用 phpenv 還可以通過以下方式輕松配置 PHP 環境: ``` phpenv config-add my_config.ini ``` ***重要說明:**似乎`phpenv/phpenv` [被放棄了](https://github.com/phpenv/phpenv/issues/57) . [madumlao / phpenv](https://github.com/madumlao/phpenv)上有一個分叉,試圖使該項目[復活](https://github.com/madumlao/phpenv) . [CHH / phpenv](https://github.com/CHH/phpenv)似乎也是一個不錯的選擇. 選擇任何提到的工具將與基本 phpenv 命令一起使用. 指導您選擇正確的 phpenv 不在本教程的范圍內.* ### Install custom extensions[](#install-custom-extensions "Permalink") 由于這是 PHP 環境的裸機安裝,因此您可能需要一些構建機器上當前不存在的擴展. 要安裝其他擴展,只需執行以下命令: ``` pecl install <extension> ``` 不建議將其添加到`.gitlab-ci.yml` . 您應該只執行一次此命令,僅用于設置構建環境. ## Extend your tests[](#extend-your-tests "Permalink") ### Using atoum[](#using-atoum "Permalink") 除了 PHPUnit,您可以使用任何其他工具來運行單元測試. 例如,您可以使用[atoum](https://github.com/atoum/atoum) : ``` before_script: - wget http://downloads.atoum.org/nightly/mageekguy.atoum.phar test:atoum: script: - php mageekguy.atoum.phar ``` ### Using Composer[](#using-composer "Permalink") 大多數 PHP 項目使用 Composer 來管理其 PHP 軟件包. 為了在運行測試之前執行 Composer,只需在`.gitlab-ci.yml`添加以下`.gitlab-ci.yml` : ``` ... # Composer stores all downloaded packages in the vendor/ directory. # Do not use the following if the vendor/ directory is committed to # your git repository. cache: paths: - vendor/ before_script: # Install composer dependencies - wget https://composer.github.io/installer.sig -O - -q | tr -d '\n' > installer.sig - php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" - php -r "if (hash_file('SHA384', 'composer-setup.php') === file_get_contents('installer.sig')) { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" - php composer-setup.php - php -r "unlink('composer-setup.php'); unlink('installer.sig');" - php composer.phar install ... ``` ## Access private packages or dependencies[](#access-private-packages-or-dependencies "Permalink") 如果您的測試套件需要訪問私有存儲庫,則需要配置[SSH 密鑰](../ssh_keys/README.html)才能克隆它. ## Use databases or other services[](#use-databases-or-other-services "Permalink") 大多數時候,您將需要一個正在運行的數據庫才能運行測試. 如果您使用的是 Docker 執行器,則可以利用 Docker 鏈接到其他容器的功能. 使用 GitLab Runner,可以通過定義`service`來實現. [CI 服務](../services/README.html)文檔中涵蓋了此功能. ## Testing things locally[](#testing-things-locally "Permalink") 使用 GitLab Runner 1.0,您還可以在本地測試所有更改. 從您的終端執行: ``` # Check using docker executor gitlab-runner exec docker test:app # Check using shell executor gitlab-runner exec shell test:app ``` ## Example project[](#example-project "Permalink") 為了方便起見,我們建立了一個[示例 PHP 項目](https://gitlab.com/gitlab-examples/php) ,該[項目](https://gitlab.com/gitlab-examples/php)使用我們的公共[共享](../runners/README.html)運行器在[GitLab.com](https://gitlab.com)上運行. 想要破解嗎? 只需對其進行分叉,提交并推送您的更改. 稍后,公共跑步者將選擇更改并開始工作.
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看