在gitlab ci composer上进行php测试

时间:2017-02-26 19:53:17

标签: php testing build gitlab gitlab-ci

我正在尝试使用我的小PHP代码进行一些基本的静态分析。 我想用: phploc phpcpd phpcs

我的项目文件夹结构如下:

    .
    |-- ci
    |   `-- docker_install.sh
    |-- css
    |   `-- css.css
    |-- index.php
    |-- js
    |   |-- icons.json
    |   `-- script.js
    `-- process.php

我使用以下代码创建了shell脚本docker_install.sh:

# Install git (the php image doesn't have it) and other tools
apt-get update -yqq
apt-get install git phploc phpcpd phpmd php-pear -yqq

#install composer
curl -s https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer  

和我的构建文件:

  image: php:7.0
  before_script:
    #insatll needed packeges
    - bash ci/docker_install.sh > /dev/null
  test:app:
    script:
      #Static analysis
      - phploc .
      #phpmd check coding style
      - phpmd . text naming
      #checking Coding Standards with PHP Code Sniffer
      - phpcpd .
      #Viewing Coding Standards Violations
      - phpcs --standard=PEAR --report=summaryy

构建文件,出现以下错误:

  ....
  $ phpcpd .

  Warning: require_once(Symfony/Component/ClassLoader/ClassLoader.php): failed to open stream: No such file or directory in /usr/share/php/SebastianBergmann/PHPCPD/autoload.php on line 2

  Fatal error: require_once(): Failed opening required 'Symfony/Component/ClassLoader/ClassLoader.php' (include_path='.:/usr/local/lib/php') in /usr/share/php/SebastianBergmann/PHPCPD/autoload.php on line 2
  ERROR: Build failed: exit code 1

我的问题: 如何增强这一点,以及如何使其有效?

谢谢!

1 个答案:

答案 0 :(得分:0)

您已经安装了作曲家,但您从未运行composer install。只需将其添加到docker_install.sh文件的末尾即可。