LoginSignup
2
2

More than 5 years have passed since last update.

Codeception を使ってみた

Last updated at Posted at 2014-11-20

モダンな PHP テスティングフレームワーク、Codeception を使ってみました。

環境

  • MacOSX 10.8.5
  • PHP 5.4.35

インストール

Phar または Composer または Git から入手できます。
今回は Git を使ってみます。

git clone git@github.com:Codeception/Codeception.git

Codeception 2.0 は PHP 5.4 以上が必要です。
5.3 以下は Codeception 1.8.x を使えとのこと。

Composer

cd Codeception
curl -s http://getcomposer.org/installer | php
php composer.phar install

依存する輩がいろいろと入ります。

bootstrap

php codecept bootstrap /project

bootstrap の後に生成先のディレクトリを指定できるようです。

Initializing Codeception in /project

File codeception.yml created       <- global configuration
tests/unit created                 <- unit tests
tests/unit.suite.yml written       <- unit tests suite configuration
tests/functional created           <- functional tests
tests/functional.suite.yml written <- functional tests suite configuration
tests/acceptance created           <- acceptance tests
tests/acceptance.suite.yml written <- acceptance tests suite configuration
tests/_output was added to .gitignore
tests/_bootstrap.php written <- global bootstrap file
Building initial Tester classes
Building Actor classes for suites: acceptance, functional, unit
\AcceptanceTester includes modules: PhpBrowser, AcceptanceHelper
AcceptanceTester.php generated successfully. 48 methods added
\FunctionalTester includes modules: Filesystem, FunctionalHelper
FunctionalTester.php generated successfully. 13 methods added
\UnitTester includes modules: Asserts, UnitHelper
UnitTester.php generated successfully. 17 methods added

Bootstrap is done. Check out /project/tests directory

ひな形できたっぽい。

一旦テスト実行

php codecept run -c /project
Codeception PHP Testing Framework v2.0.8
Powered by PHPUnit 4.3.5 by Sebastian Bergmann.

Acceptance Tests (0) ------------------------
---------------------------------------------

Functional Tests (0) ------------------------
---------------------------------------------

Unit Tests (0) ------------------------------
---------------------------------------------


Time: 101 ms, Memory: 6.50Mb

まだテスト書いて無いですけどね。とりあえずは実行できる模様。

テストに使ったコマンドをまるごと alias にしとくと楽ですね。
.bashrc に

alias t='php codecept run -c /project'

と書いて

source ~/.bashrc

以降は t と叩けばテスト実行ですね。

次回以降で実際のテストを書いていきます。今日はおしまい。

2
2
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
2
2