Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Codeceptionを利用したWordPressプラグインテストことはじめ

 Codeceptionを利用したWordPressプラグインテストことはじめ

WordBench京都2016年3月号で発表したCodeceptionについてのスライドです。
スライド内で利用したサンプルプラグインやテストは以下に公開しています。

https://github.com/Ippey/cc-plugin

Ippei Sumida

March 19, 2016
Tweet

More Decks by Ippei Sumida

Other Decks in Programming

Transcript

  1. ࠓճ࢖༻͢Δ΋ͷ • WordPress (Apache, MySQL, PHP>=5.4, wp-cli) • PhpStorm •

    Codeception • Selenium standalone-server • Firefox
  2. MySQLηοτΞοϓ mysql -uroot -p*** mysql
 create database wordpress;
 create database

    wordpress_test
 CREATE USER wordpress IDENTIFIED BY 'wordpress';
 CREATE USER wordpress@localhost IDENTIFIED BY 'wordpress';
 GRANT ALL PRIVILEGES ON *.* TO wordpress@localhost;
 GRANT ALL PRIVILEGES ON *.* TO wordpress;
 flush privileges;
  3. VCCWΠϯετʔϧ vagrant box add miya0001/vccw
 wget https://github.com/vccw-team/vccw/archive/2.19.0.zip
 unzip 2.19.0.zip
 cd

    vccw-2.19.0
 vagrant up
 
 ※ผϓϩδΣΫτͰvccw.devΛ࢖͍ͬͯΔ৔߹͸ɺϗετ໊Λม ߋ͍ͯͩ͘͠͞ɻ
  4. CodeceptionηοτΞοϓ class_name: AcceptanceTester
 modules:
 enabled:
 - PhpBrowser:
 url: http://vccw.dev
 -

    \Helper\Acceptance
 
 env:
 firefox:
 modules:
 enabled:
 - WebDriver:
 url: http://vccw.dev
 browser: firefox
 - \Helper\Acceptance
 tests/acceptance.suite.yml
  5. ςετϓϩάϥϜ࡞੒ɹ UnitTest /**
 * ϓϥΠϕʔτϝιουΛݺͿͨΊͷReflectionMethodΛฦ͢
 *
 * @param $obj
 *

    @param $name
 *
 * @return ReflectionMethod
 */
 private function getPrivateMethod($obj, $name) {
 $method = new ReflectionMethod($obj, $name);
 $method->setAccessible(true);
 return $method;
 }
  6. ςετϓϩάϥϜ࡞੒ɹ UnitTest /**
 * getListByPrefectureͷςετ
 */
 public function testGetListByPrefecture() {


    $pref = "ژ౎෎";
 $method = $this->getPrivateMethod($this->manager, "getListByPrefecture");
 $list = $method->invoke($this->manager, array($pref));
 foreach ($list as $row) {
 $this->assertEquals($pref, $row["prefecture"]);
 }
 }
  7. ςετϓϩάϥϜ࡞੒ɹ AcceptanceTest public function testShowAkiyoshiShopList(AcceptanceTester $I)
 {
 $I->canSeeElement("#akiyoshi-list");
 }
 


    public function testShowKawaramachi(AcceptanceTester $I) {
 $I->canSee("Տݪொళ", "#akiyoshi-list");
 }