LoginSignup
6
6

More than 5 years have passed since last update.

PhalconのユニットテストをCircleCIで実行する

Last updated at Posted at 2015-05-21

PHPの(自称)最速フレームワークのPhalconは、PHPのエクステンションとして組み込まれるというその性質上、CircleCIでのユニットテスト実行にはテスト用ホストへのインストールが必要です。悪戦苦闘の末にインストール用の設定ファイルを整えたのでメモ。

実行環境

  • PHP 5.5.21 (CircleCIで指定可能な5.5系の最新バージョン)
  • Phalcon 1.3.5

Composerの設定ファイル

incubatorを使うかどうかは必要に応じてですが、バージョンを合わせておいたほうが安全です。Mockeryはユニットテストでモックを使うときに利用します。

composer.json
{
    "require": {
        "phalcon/incubator": "v1.3.5"
    },
    "require-dev": {
        "phpunit/phpunit": "4.*",
        "mockery/mockery": "dev-master"
    }
}

CircleCIの設定ファイル

apt-getでインストール可能なphp5-phalconはPHP5.3での実行が前提になっているため、CircleCIでPHPのバージョンを指定するとインストール時にエラーが発生します。そのためGithubからソースコードを落としてきて手動でビルドしますが、sudo実行するときのphpizeとphp-configのパスが指定バージョンのPHPに向いていないため、インストールスクリプトを書き換えてから実行する必要があります。

またPHPUnitの実行時はComposerでインストールしたバイナリを指定してあげないとMockeryの名前解決ができませんでしたので、テスト実行のコマンドを上書きしています。

circle.yml
machine:
  timezone: Asia/Tokyo
  php:
    version: 5.5.21

dependencies:
  pre:
    - sudo apt-get update
    - sudo apt-get install -y gcc libpcre3-dev
    - git clone -b 1.3.5 --depth 1 git@github.com:phalcon/cphalcon.git:
    - sed -i "s/phpize /\/home\/ubuntu\/.phpenv\/shims\/phpize /g" cphalcon/build/install
    - sed -i "s/configure /configure --with-php-config=\/home\/ubuntu\/.phpenv\/shims\/php-config /g" cphalcon/build/install
    - sudo ./install:
        pwd: cphalcon/build
    - sudo sh -c "echo 'extension=phalcon.so' > /home/ubuntu/.phpenv/versions/5.5.21/etc/conf.d/phalcon.ini"
    - sudo composer self-update

test:
  override:
    - ../vendor/phpunit/phpunit/phpunit:
        pwd: tests
6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6