如何在GitHub Action中使用不同版本的PHP进行测试 [英] How to test with different versions of PHP in a GitHub Action

查看:60
本文介绍了如何在GitHub Action中使用不同版本的PHP进行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些PHP代码,其中的测试使用 PHPUnit 运行,并希望在 GitHub Actions 上进行测试.我在他们的文档中找不到测试PHP软件包的方法.我想使用不同版本的PHP进行测试,但它们仅安装了最新的 7.3 .

I have some PHP code with tests which run using PHPUnit and wanted to test it on GitHub Actions. I could not find a method in their documentation for testing PHP packages. I want to test using different versions of PHP, but they only have the latest one 7.3 installed.

推荐答案

您可以添加 setup-php操作.如果不存在,它将安装您指定的PHP版本以及所需的扩展名和各种工具(例如composer).它支持GitHub Actions和PHP版本> = 5.3 支持的所有虚拟环境.

You can add the setup-php action in your workflow. If not present, it installs the PHP version(s) you specify with required extensions and various tools like composer. It supports all the virtual environments supported by GitHub Actions and PHP versions >= 5.3.

例如,您可以拥有这样的工作流程

For example you can have a workflow like this

jobs:
  run:    
    runs-on: ${{ matrix.operating-system }}
    strategy:
      matrix:
        operating-system: [ubuntu-latest, windows-latest, macOS-latest]
        php-versions: ['7.2', '7.3']
    name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
    steps:
    - name: Checkout
      uses: actions/checkout@v2
    - name: Install PHP
      uses: shivammathur/setup-php@v2
      with:
        php-version: ${{ matrix.php-versions }}
        extensions: intl #optional
        ini-values: "post_max_size=256M" #optional
    - name: Check PHP Version
      run: php -v

注意:这将设置PHP,您需要添加步骤以使用 composer 安装依赖项,并添加另一步骤以使用 PHPUnit

Note: This will setup PHP, you need to add steps to install your dependencies using composer and another step to run your tests using PHPUnit

您可以在 ini-values 中所需的 extensions php.ini 配置中指定所需的扩展名.这两个输入都是可选的,并以CSV作为输入.必须输入 php-version .在上面的示例中,它将运行工作流程并使用 matrix.php-versions 中指定的版本(即 7.2 7.3 )设置PHP环境.可以根据您的要求进行调整.

You can specify the required extensions in the extensions and the php.ini configuration you want in ini-values. Both these inputs are optional and take a CSV as an input. The php-version input is required. In above example it will run the workflow and setup the PHP environment with the versions specified in matrix.php-versions i.e 7.2 and 7.3, you can adjust these as per your requirements.

这篇关于如何在GitHub Action中使用不同版本的PHP进行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆