テストと仲良くするためのCodeceptionのはじめかた #phpkansai

テストと仲良くするためのCodeceptionのはじめかた #phpkansai

PHPカンファレンス関西 2017の発表資料です。

A73ed5cefbbd84abd2c5e14a5eb4a339?s=128

Ippei Sumida

July 15, 2017
Tweet

Transcript

  1. ςετͱ஥ྑ͘͢ΔͨΊͷ Codeceptionͷ͸͡Ί͔ͨ PHP Conference Kansai 2017
 2017-07-15

  2. ࣗݾ঺հ • ֯ాɹҰฏʢ͢Έͩɹ͍ͬ΃͍ʣ • ϑϦʔϥϯεΤϯδχΞ
 ˠ͓࢓ࣄઈࢍืूதʂ • CoderDojoຕํɹ୅ද

  3. ࠓ೔ͷ໨ඪ • Codeceptionʹ͍ͭͯ஌ͬͯ΋Β͏ • CodeceptionͷςετͷྲྀΕΛ஌ͬͯ΋Β͏ • ʰCodeceptionͱҰॹʹ
 ɹςετͱ஥ྑ͘ͳΖ͏ʱͱࢥͬͯ΋Β͏

  4. ΞδΣϯμ • Codeceptionͱ͸ • CodeceptionͰͷςετ࣮૷ • Codeception Tips

  5. ςετॻ͍ͯ·͔͢ʁ

  6. –ݪాɹ߁ੜ “ςετ͸઒ͷਫ࣭ௐࠪͩͱࢥͬͨΒ͍͍ Ͱ͢Α”

  7. ւˡ

  8. None
  9. None
  10. ୯ମςετ ػೳςετ γεςϜɾडೖςετ

  11. γεςϜςετ ػೳςετ ୯ମςετ

  12. దࡐదॴͳςετΛ༻ҙ

  13. దࡐదॴͷςετ͸… • ෆ۩߹ൃݟ͕༰қʹ • ૝ఆ֎ͷӨڹΛૣظൃݟ • ֎෦ύοέʔδΛ҆৺ͯ͠ߋ৽

  14. Codeceptionͱ͸

  15. 1.Codeceptionͱ͸ ςεςΟϯάϑϨʔϜϫʔΫ
 (PHP੡)

  16. PHPer Readableͳ
 ςεςΟϯάϑϨʔϜϫʔΫ 1.Codeceptionͱ͸

  17. public function registerTest(AcceptanceTester $I) { $I->wantToTest('ొ࿥ςετ'); $I->canSee('͓໰͍߹Θͤ', '#title'); $I->fillField('#inquiry_name', '͢Έͩɹ͍ͬ΃͍');

    $I->fillField('#inquiry_email', 'ippey.s@gmail.com'); $I->fillField('#inquiry_question', '͓໰͍߹Θͤ಺༰'); $I->click('ૹ৴'); $I->canSee('͓໰͍߹Θͤ׬ྃ͠·ͨ͠ɻ', '#title'); $I->canSeeInDatabase('inquiry', [ 'name' => '͢Έͩɹ͍ͬ΃͍', 'email' => 'ippey.s@gmail.com', 'question' => '͓໰͍߹Θͤ಺༰', ]); } 1.Codeceptionͱ͸
  18. ςετͷ؅ཧָ͕ 1.Codeceptionͱ͸

  19. 1.Codeceptionͱ͸ 6OJU w ֤Ϋϥεɺϝιου w 1)16OJUΠϯετʔϧ
 ෆཁ 1)16OJUΛར༻ͨ͠
 ୯ମςετ 'VODUJPOBM

    w ػೳ୯Ґ w ϦΫΤετʹର͢Δ
 ݁ՌΛ֬ೝ w ֤'8ରԠ 8FCαʔόΛհ͞ͳ ͍'8ςετ "DDFQUBODF w ػೳ୯Ґ w ը໘্ͷಈ࡞֬ೝ w ϒϥ΢βґଘ ϒϥ΢βΛར༻ͨ͠ डೖςετ
  20. Codeception͚ͩͰ
 ֤छςετΛҰׅ؅ཧɺ࣮ߦ 1.Codeceptionͱ͸

  21. ֤छϑϨʔϜϫʔΫαϙʔτ 1.Codeceptionͱ͸

  22. 1.Codeceptionͱ͸ And more…

  23. ͦͷ΄͔ • REST APIςετՄ • ϨεϙϯγϒαΠτͷςετՄ • ֤छCIͱ࿈ܞՄ • Ωϟϓνϟऔಘ

    • ίʔυΧόϨοδऔಘ
  24. ଟػೳɾ؆୯ 1.Codeceptionͱ͸ ςετͱ஥ྑ͘Ͱ͖ͦ͏ʂ

  25. Conclusion • Codeception͸ςεςΟϯάϑϨʔϜϫʔΫ • PHPer͕ಡΈ΍͍͢ςετίʔυ • ֤छςετΛҰׅ؅ཧɺ࣮ߦՄೳ • ֤छϑϨʔϜϫʔΫରԠ •

    ͦͷଞॾʑ༻ҙ͞ΕͯΔͷͰ஥ྑ͘ͳΕͦ͏
  26. CodeceptionͰͷςετ࣮૷

  27. 2.CodeceptionͰͷςετ࣮૷ 6OJU w ֤Ϋϥεɺϝιου w 1)16OJUΠϯετʔϧ
 ෆཁ 1)16OJUΛར༻ͨ͠
 ୯ମςετ 'VODUJPOBM

    w ػೳ୯Ґ w ϦΫΤετʹର͢Δ
 ݁ՌΛ֬ೝ w ֤'8ରԠ 8FCαʔόΛհ͞ͳ ͍'8ςετ "DDFQUBODF w ػೳ୯Ґ w ը໘্ͷಈ࡞֬ೝ w ϒϥ΢βґଘ ϒϥ΢βΛར༻ͨ͠ डೖςετ
  28. Unit ϝιου࣮ߦ ϝιουΛ࣮ߦͯ͠
 ࣮ߦ݁Ռʹରͯ͠ςετɻ
 2.CodeceptionͰͷςετ࣮૷

  29. Functional ϦΫΤετ FWʢϓϩάϥϜʣʹϦΫΤετΛ౉ͯ͠ɺ
 ࣮ߦ݁Ռʹରͯ͠ςετɻ
 = WebαʔόΛհ͞ͳ͍ 2.CodeceptionͰͷςετ࣮૷

  30. Acceptance ϒϥ΢βΛ੍ޚͯ͠ɺ
 ϒϥ΢βදࣔ݁Ռʹରͯ͠ςετɻ
 㲈ਓͷखʹΑΔϒϥ΢βςετ 2.CodeceptionͰͷςετ࣮૷ ϦΫΤετ

  31. ࣮ߦ଎౓͸
 Unit > Functional > Acceptance 2.CodeceptionͰͷςετ࣮૷

  32. શͯΛAcceptanceͰ ߦΘͳ͍ 2.CodeceptionͰͷςετ࣮૷

  33. Acceptance = Ϧϋʔαϧ 2.CodeceptionͰͷςετ࣮૷

  34. Πϯετʔϧ
 ؀ڥ४උ ࣮ߦ 2.CodeceptionͰͷςετ࣮૷

  35. 2.CodeceptionͰͷςετ࣮૷ $ composer require —dev codeception/codeception Πϯετʔϧ

  36. 2.CodeceptionͰͷςετ࣮૷ bootstrap - ؀ڥ࡞੒ build - ઃఆ൓ө $ vendor/bin/codecept bootstrap

    $ vendor/bin/codecept build
  37. 2.CodeceptionͰͷςετ࣮૷ $ vendor/bin/codecept run ςετ࣮ߦʢҰׅʣ

  38. 2.CodeceptionͰͷςετ࣮૷ $ vendor/bin/codecept run acceptance HogeCest:hogeTest ςετ࣮ߦʢҰ෦ʣ TVJUF ςετϑΝΠϧɺϝιου

  39. 2.CodeceptionͰͷςετ࣮૷ Acceptance (phpbrowser) Tests (2) --------------------------------------------------------------------- --------------------------------------------------------------------- --------------------- Testing acceptance

    (phpbrowser) ✔ InquiryCest: Test ొ࿥ςετ (1.30s) ✔ InquiryCest: Test ॏෳొ࿥ςετ (1.04s) --------------------------------------------------------------------- --------------------------------------------------------------------- ------------------------------------------------------- Time: 2.59 seconds, Memory: 17.00MB OK (2 tests, 5 assertions) ࣮ߦ݁ՌʢOKʣ
  40. 2.CodeceptionͰͷςετ࣮૷ Acceptance (phpbrowser) Tests (2) --------------------------------------------------------------------- --------------------------------------------------------------------- --------------------- Testing acceptance

    (phpbrowser) ✖ InquiryCest: Test ొ࿥ςετ ✔ InquiryCest: Test ొ࿥ςετ[F] (2.10s) ✔ InquiryCest: Test ॏෳొ࿥ςετ (1.30s) --------------------------------------------------------------------- --------------------------------------------------------------------- ------------------------------------------------------- Time: 3.7 seconds, Memory: 17.25MB There was 1 failure: ࣮ߦ݁ՌʢNGʣ
  41. 2.CodeceptionͰͷςετ࣮૷ --------- 1) InquiryCest: Test ొ࿥ςετ Test tests/acceptance/InquiryCest.php:registerTest Failed asserting

    that any element by '#title' on page /inquiry/ + <h1 id="title">͓໰͍߹Θͤ</h1> contains text 'a͓໰͍߹Θͤ' ࣮ߦ݁ՌʢNGʣ ͲͷςετͰΤϥʔʹͳ͔ͬͨग़ྗ
  42. 2.CodeceptionͰͷςετ࣮૷ ࣮ߦ݁ՌʢNGʣ Τϥʔ࣌ʹͲͷΑ͏ͳ݁Ռ͕ग़ྗ͞Ε͔ͨอଘ

  43. ֤ઃఆ 2.CodeceptionͰͷςετ࣮૷

  44. Unit Test 2.CodeceptionͰͷςετ࣮૷

  45. 2.CodeceptionͰͷςετ࣮૷ unit.suite.yml # Codeception Test Suite Configuration # # Suite

    for unit or integration tests. actor: UnitTester modules: enabled: - Asserts - \Helper\Unit
  46. 2.CodeceptionͰͷςετ࣮૷ generate:test - testϑΝΠϧ࡞੒ $ vendor/bin/codecept generate:test unit HogeTest

  47. Functional Test 2.CodeceptionͰͷςετ࣮૷

  48. 2.CodeceptionͰͷςετ࣮૷ functional.suite.yml actor: FunctionalTester modules: enabled: # add a framework

    module here - \Helper\Functional - Symfony: app_path: 'app' var_path: 'var' - Db: dsn: 'sqlite:var/data.sqlite' user: '' password: '' populate: true dump: 'tests/_data/dump.sql'
  49. actor: FunctionalTester modules: enabled: # add a framework module here

    - \Helper\Functional - Symfony: app_path: 'app' var_path: 'var' - Db: dsn: 'sqlite:var/data.sqlite' user: '' password: '' populate: true dump: 'tests/_data/dump.sql' 2.CodeceptionͰͷςετ࣮૷ ϑϨʔϜϫʔΫͷઃఆ functional.suite.yml
  50. actor: FunctionalTester modules: enabled: # add a framework module here

    - \Helper\Functional - Symfony: app_path: 'app' var_path: 'var' - Db: dsn: 'sqlite:var/data.sqlite' user: '' password: '' populate: true dump: 'tests/_data/dump.sql' 2.CodeceptionͰͷςετ࣮૷ %#ͷઃఆ functional.suite.yml
  51. 2.CodeceptionͰͷςετ࣮૷ generate:cept - ceptϑΝΠϧ࡞੒ generate:cest - cestϑΝΠϧ࡞੒ $ vendor/bin/codecept generate:cept

    functional HogeCept $ vendor/bin/codecept generate:cest functional HogeCest
  52. Acceptance Test 2.CodeceptionͰͷςετ࣮૷

  53. 2.CodeceptionͰͷςετ࣮૷ acceptance.suite.yml actor: AcceptanceTester modules: enabled: - WebDriver: url: http://localhost:8000

    browser: phantomjs - \Helper\Acceptance - Db: dsn: 'sqlite:var/data.sqlite' user: '' password: '' populate: true dump: 'tests/_data/dump.sql' env: firefox: modules: config: WebDriver: browser: firefox
  54. actor: AcceptanceTester modules: enabled: - WebDriver: url: http://localhost:8000 browser: phantomjs

    - \Helper\Acceptance - Db: dsn: 'sqlite:var/data.sqlite' user: '' password: '' populate: true dump: 'tests/_data/dump.sql' env: firefox: modules: config: WebDriver: browser: firefox 2.CodeceptionͰͷςετ࣮૷ acceptance.suite.yml ϒϥ΢βͷઃఆ
  55. 2.CodeceptionͰͷςετ࣮૷ 1)1#SPXTFS 1IBOUPN+4 pSFGPY DISPNF +BWB4DSJQU º ˚ ̋ #BTJDೝূ

    ̋ ˚ ̋ ࣮ߦ଎౓ ̋ ˚ º
  56. 2.CodeceptionͰͷςετ࣮૷ 1)1
 #SPXTFS 1IBOUPN+4 'JSFGPY $ISPNF 4FMFOJVN4UBOEBMPOF 4FSWFS  ̋

    ̋ ̋ 1IBOUPN+4  ̋   DISPNFESJWFS    ̋ Required
  57. ϒϥ΢βࢦఆ PHPBrowser PhantomJS firefox/chrome 2.CodeceptionͰͷςετ࣮૷ modules: enabled: - PhpBrowser: url:

    http://localhost:8000 modules: enabled: - WebDriver: url: http://localhost:8000 browser: phantomjs modules: enabled: - WebDriver: url: http://localhost:8000 browser: firefox
  58. 2.CodeceptionͰͷςετ࣮૷ generate:cept - ceptϑΝΠϧ࡞੒ generate:cest - cestϑΝΠϧ࡞੒ $ vendor/bin/codecept generate:cept

    acceptance HogeCept $ vendor/bin/codecept generate:cest acceptance HogeCest
  59. ςετ࣮૷ 2.CodeceptionͰͷςετ࣮૷

  60. CeptͱCest 2.CodeceptionͰͷςετ࣮૷

  61. 2.CodeceptionͰͷςετ࣮૷ $FQU w ্͔Βॱʹ࣮ߦ w ϑΝΠϧγφϦΦ w ؆୯ͳγφϦΦ޲͖ γφϦΦϑΝΠϧ $FTU

    w 1)16OJUͷ༷ʹهड़ w ϝιουγφϦΦ w ෳࡶͳγφϦΦ0, γφϦΦΫϥε
  62. 2.CodeceptionͰͷςετ࣮૷ Cept <?php $I = new FunctionalTester($scenario); $I->wantTo('͓໰͍߹Θͤొ࿥ςετ'); $I->amOnPage('/inquiry'); $I->canSee('͓໰͍߹Θͤ',

    '#title'); $I->fillField('#inquiry_name', '͢Έͩɹ͍ͬ΃͍'); $I->fillField('#inquiry_email', 'hogehoge@gmail.com'); $I->fillField('#inquiry_question', '͓໰͍߹Θͤ಺༰'); $I->click('ૹ৴'); $I->canSee('͓໰͍߹Θͤ׬ྃ͠·ͨ͠ɻ', '#title');
  63. 2.CodeceptionͰͷςετ࣮૷ Cest <?php class InquiryFunctionalCest { // tests public function

    registrationTest(FunctionalTester $I) { $I->amOnPage('/inquiry'); $I->canSee('͓໰͍߹Θͤ', '#title'); $I->fillField('#inquiry_name', '͢Έͩɹ͍ͬ΃͍'); $I->fillField('#inquiry_email', 'ippey.s@gmail.com'); $I->fillField('#inquiry_question', '͓໰͍߹Θͤ಺༰'); $I->click('ૹ৴'); $I->canSee('͓໰͍߹Θͤ׬ྃ͠·ͨ͠ɻ', '#title'); } }
  64. <?php class InquiryFunctionalCest { public function _before(FunctionalTester $I) { }

    public function _after(FunctionalTester $I) { } // tests } 2.CodeceptionͰͷςετ࣮૷ Cest લॲཧʢ@CFGPSF ޙॲཧʢ@BGUFS
  65. 2.CodeceptionͰͷςετ࣮૷ $FQU w ্͔Βॱʹ࣮ߦ w ϑΝΠϧγφϦΦ w ؆୯ͳγφϦΦ޲͖ γφϦΦϑΝΠϧ $FTU

    w 1)16OJUͷ༷ʹهड़ w ϝιουγφϦΦ w ෳࡶͳγφϦΦ0, γφϦΦΫϥε ɹ Φ ε ε ϝ ʂ ɹ
  66. ϝιου උߟ ࢦఆͷϖʔδʹҠಈ *BN0O1BHF l63-z  BDDFQUBODFTVJUFZNM ʹࢦఆͨ͠63-ʹ௥Ճ͞ ΕͯΞΫηεɻ ϖʔδʹࢦఆͷจࣈ͕͋

    Δ͔ *TFF lจࣈྻz  *TFF lจࣈྻz lཁ ૉz  *DBO4FF lจࣈྻz  DBOΛ͚ͭΔͱݟ͔ͭΒ ͳͯ͘΋ςετ͕ࢭ·Β ͳ͍ ϖʔδʹࢦఆͷจࣈ͕ͳ ͍͔ *EPOU4FF lจࣈྻz  *EPOU4FF lจࣈྻz  lཁૉz  *DBOU4FF lจࣈྻz  DBOΛ͚ͭΔͱݟ͔ͭΒ ͳͯ͘΋ςετ͕ࢭ·Β ͳ͍ ΫϦοΫ *DMJDL lϩάΠϯz  *DMJDL lMPHJOz  จࣈྻ 9QBUI $44 4FMFDUPSͰࢦఆ Α͘࢖͏ϝιου
  67. ϝιου උߟ ςΩετϘοΫεʹॻ͘ *pMM'JFME lOBNFz  lWBMVFz  *pMM'JFME lOBNFz

     lWBMVFz  ϑΟʔϧυ ໊ 9QBUI $444FMFDUPS Ͱࢦఆ ϥδΦϘλϯબ୒ * DIFDL0QUJPO lOBNFz  lWBMVFz  * ϑΟʔϧυ ໊ 9QBUI $444FMFDUPS Ͱࢦఆ ηϨΫτϘοΫεɺ νΣοΫϘοΫεબ୒ * TFMFDU0QUJPO lOBNFz  lWBMVFz  * ϑΟʔϧυ ໊ 9QBUI $444FMFDUPS Ͱࢦఆ ·ͱΊͯϑΥʔϜૹ৴ * TVCNJU'PSN bGPSN`  <bOBNF`bWBMVF`>  ϑΟʔϧυ ໊ 9QBUI $444FMFDUPS Ͱࢦఆ Α͘࢖͏ϝιουʢFormʣ
  68. ϝιου උߟ %#ʹࢦఆͷσʔλ͕͋ Δ͔֬ೝ *TFF*O%BUBCBTF bςʔϒϧ ໊` <bϑΟʔϧυ໊`b஋`>  DBOΛ͚ͭΔͱݟ͔ͭΒ

    ͳͯ͘΋ςετ͕ࢭ·Β ͳ͍ %#ʹࢦఆͷσʔλ͕ͳ ͍͔֬ೝ *EPOU4FF*O%BUBCBTF bςʔ ϒϧ໊` <bϑΟʔϧυ໊`b஋`>  DBOΛ͚ͭΔͱݟ͔ͭͬ ͯ΋ςετ͕ࢭ·Βͳ͍ σʔλΛొ࿥͢Δ *IBWF*O%BUBCBTF bςʔϒϧ ໊` <bϑΟʔϧυ໊`b஋`>  ςετσʔλ࡞੒࣌ʹ σʔλΛऔಘ͢Δ *HSBC'SPN%BUBCBTF  bςʔϒϧ໊` bऔಘϑΟʔϧυ໊`  <bϑΟʔϧυ໊`b஋`>  Α͘࢖͏ϝιουʢDBʣ
  69. 2.CodeceptionͰͷςετ࣮૷ /** * ొ࿥ςετ * * @param AcceptanceTester $I */

    public function registerTest(AcceptanceTester $I) { $I->wantToTest('ొ࿥ςετ'); $I->canSee('͓໰͍߹Θͤ', '#title'); $I->fillField('#inquiry_name', '͢Έͩɹ͍ͬ΃͍'); $I->fillField('#inquiry_email', 'ippey.s@gmail.com'); $I->fillField('#inquiry_question', '͓໰͍߹Θͤ಺༰'); $I->click('ૹ৴'); $I->canSee('͓໰͍߹Θͤ׬ྃ͠·ͨ͠ɻ', '#title'); $I->canSeeInDatabase('inquiry', [ 'name' => '͢Έͩɹ͍ͬ΃͍', 'email' => 'ippey.s@gmail.com', 'question' => '͓໰͍߹Θͤ಺༰', ]); }
  70. /** * ొ࿥ςετ * * @param AcceptanceTester $I */ public

    function registerTest(AcceptanceTester $I) { $I->wantToTest('ొ࿥ςετ'); $I->canSee('͓໰͍߹Θͤ', '#title'); $I->fillField('#inquiry_name', '͢Έͩɹ͍ͬ΃͍'); $I->fillField('#inquiry_email', 'ippey.s@gmail.com'); $I->fillField('#inquiry_question', '͓໰͍߹Θͤ಺༰'); $I->click('ૹ৴'); $I->canSee('͓໰͍߹Θͤ׬ྃ͠·ͨ͠ɻ', '#title'); $I->canSeeInDatabase('inquiry', [ 'name' => '͢Έͩɹ͍ͬ΃͍', 'email' => 'ippey.s@gmail.com', 'question' => '͓໰͍߹Θͤ಺༰', ]); } 2.CodeceptionͰͷςετ࣮૷ JElUJUMFzʹʰ͓໰͍߹Θͤʱ ͱग़ྗ͞Ε͍ͯΔ͔ʁ
  71. /** * ొ࿥ςετ * * @param AcceptanceTester $I */ public

    function registerTest(AcceptanceTester $I) { $I->wantToTest('ొ࿥ςετ'); $I->canSee('͓໰͍߹Θͤ', '#title'); $I->fillField('#inquiry_name', '͢Έͩɹ͍ͬ΃͍'); $I->fillField('#inquiry_email', 'ippey.s@gmail.com'); $I->fillField('#inquiry_question', '͓໰͍߹Θͤ಺༰'); $I->click('ૹ৴'); $I->canSee('͓໰͍߹Θͤ׬ྃ͠·ͨ͠ɻ', '#title'); $I->canSeeInDatabase('inquiry', [ 'name' => '͢Έͩɹ͍ͬ΃͍', 'email' => 'ippey.s@gmail.com', 'question' => '͓໰͍߹Θͤ಺༰', ]); } 2.CodeceptionͰͷςετ࣮૷ JElJORVJSZ@OBNFzʹʰ͢Έͩɹ͍ͬ΃͍ʱ Λೖྗ͢Δ
  72. /** * ొ࿥ςετ * * @param AcceptanceTester $I */ public

    function registerTest(AcceptanceTester $I) { $I->wantToTest('ొ࿥ςετ'); $I->canSee('͓໰͍߹Θͤ', '#title'); $I->fillField('#inquiry_name', '͢Έͩɹ͍ͬ΃͍'); $I->fillField('#inquiry_email', 'ippey.s@gmail.com'); $I->fillField('#inquiry_question', '͓໰͍߹Θͤ಺༰'); $I->click('ૹ৴'); $I->canSee('͓໰͍߹Θͤ׬ྃ͠·ͨ͠ɻ', '#title'); $I->canSeeInDatabase('inquiry', [ 'name' => '͢Έͩɹ͍ͬ΃͍', 'email' => 'ippey.s@gmail.com', 'question' => '͓໰͍߹Θͤ಺༰', ]); } 2.CodeceptionͰͷςετ࣮૷ l*ORVJSZzςʔϒϧʹ ࢦఆͷ಺༰Ͱొ࿥͞Εͨ
 σʔλ͕͋Δ͔֬ೝ
  73. id, classΛద੾ʹηοτ 2.CodeceptionͰͷςετ࣮૷ CodeceptionͰͷςετָ͕ʹʂ

  74. Conclusion • ઃఆϑΝΠϧͰɺFWɾϒϥ΢βͳͲΛઃఆ • Functional, Acceptance͸ςετͷॻ͖ํతʹ͸΄΅ಉ͡ • Functional͸WebαʔόΛհ͞ͳ͍ • ϒϥ΢βʹΑΓͰ͖ͳ͍͜ͱ΋͋Δ

    • CeptΑΓ΋Cest͕Φεεϝ • class, idΛద੾ʹηοτ͢Δͱςετ͠΍͍͢
  75. Codeception Tips ΋ͬͱ஥ྑ͘͢ΔͨΊͷ

  76. env 3.Codeception Tips

  77. envͰ࣮ߦ؀ڥΛ੾Γସ͑

  78. actor: AcceptanceTester modules: enabled: - WebDriver: url: http://localhost:8000 browser: phantomjs

    - \Helper\Acceptance - Db: dsn: 'sqlite:var/data.sqlite' user: '' password: '' populate: true dump: 'tests/_data/dump.sql' env: firefox: modules: config: WebDriver: browser: firefox ࢦఆͨ͠಺༰Ͱ্ॻ͖ ͜͜Ͱ͸CSPXTFSΛpSFGPYʹ্ॻ͖ 3.Codeception Tips
  79. $ vendor/bin/codecept run acceptance —env=firefox ؀ڥ੾Γସ͑ 3.Codeception Tips

  80. /** * @param AcceptanceTester $I * @env firefox * @env

    chrome */ public function tryToTest(AcceptanceTester $I) { // env=firefox or chrome͚ͩςετ } ΞϊςʔγϣϯͰ؀ڥΛࢦఆ 3.Codeception Tips
  81. actor: AcceptanceTester modules: enabled: - WebDriver: url: http://localhost:8000 browser: phantomjs

    - \Helper\Acceptance - Db: dsn: 'sqlite:var/data.sqlite' user: '' password: '' populate: true dump: 'tests/_data/dump.sql' env: firefox: modules: config: WebDriver: browser: firefox window_size: 1024x768 3.Codeception Tips ΢Οϯυ΢αΠζมߋ
  82. disabled 3.Codeception Tips

  83. actor: AcceptanceTester modules: enabled: - WebDriver: url: http://localhost:8000 browser: phantomjs

    - \Helper\Acceptance env: firefox: modules: config: WebDriver: browser: firefox phpbrowser: modules: enabled: - PhpBrowser: url: http://localhost:8000 ͜Εͩͱ--env=phpbrowserͰΤϥʔʂ 3.Codeception Tips
  84. actor: AcceptanceTester modules: enabled: - WebDriver: url: http://localhost:8000 browser: phantomjs

    - \Helper\Acceptance env: firefox: modules: config: WebDriver: browser: firefox phpbrowser: modules: enabled: - PhpBrowser: url: http://localhost:8000 ͜Εͩͱ--env=phpbrowserͰΤϥʔʂ ͲͪΒͷϒϥ΢βͰςετ͢Ε͹
 Α͍͔Θ͔Βͳ͘ͳ͍ͬͯΔɻ 3.Codeception Tips
  85. actor: AcceptanceTester modules: enabled: - WebDriver: url: http://localhost:8000 browser: phantomjs

    - \Helper\Acceptance env: firefox: modules: config: WebDriver: browser: firefox phpbrowser: modules: disabled: - WebDriver enabled: - PhpBrowser: url: http://localhost:8000 EJTBCMFEͰແޮԽ 3.Codeception Tips
  86. CSSηϨΫλͷௐ΂ํ 3.Codeception Tips

  87. 3.Codeception Tips

  88. 3.Codeception Tips ͜͜ͷCSSηϨΫλ͕Θ͔Βͳ͍

  89. 3.Codeception Tips CSSηϨΫλͷίϐʔ͕Մೳ

  90. 3.Codeception Tips $$(‘[ηϨΫλ]’); Ͱݕূ

  91. લɾޙॲཧϝιου 3.Codeception Tips

  92. /** * ॏෳొ࿥ςετ * @param AcceptanceTester $I * @before createData

    * @after afterMethod */ public function duplicateTest(AcceptanceTester $I) { $I->wantToTest('ॏෳొ࿥ςετ'); $I->canSee('͓໰͍߹Θͤ', '#title'); $I->fillField('#inquiry_name', '͢Έͩɹ͍ͬ΃͍'); $I->fillField('#inquiry_email', 'ippey.s@gmail.com'); $I->fillField('#inquiry_question', '͓໰͍߹Θͤ಺༰'); $I->click('ૹ৴'); $I->canSee('͜ͷϝʔϧΞυϨε͸͢Ͱʹ࢖༻͞Ε͍ͯ·͢'); } 3.Codeception Tips
  93. /** * ॏෳςετ༻ͷσʔλΛ࡞੒͢Δ * * @param AcceptanceTester $I */ protected

    function createData(AcceptanceTester $I) { $I->haveInDatabase('inquiry', [ 'name' => '͢Έͩɹ͍ͬ΃͍', 'email' => 'ippey.s@gmail.com', 'question' => '͓໰͍߹Θͤ಺༰', 'created_at' => \Carbon\Carbon::now() ]); } 3.Codeception Tips લɾޙॲཧ༻ϝιου͸”protected”
  94. @CFGPSF !CFGPSFͭΊ !BGUFSͭΊ 3.Codeception Tips @BGUFS !CFGPSFͭΊ !BGUFSͭΊ ςετϝιου

  95. Conclusion • envΛࢦఆ͢Δ͜ͱͰɺϒϥ΢βͳͲ؀ڥΛ੾ Γସ͑ • @before, @afterΛઃఆͯ͠ɺಠࣗͷલɾޙॲ ཧΛૠೖ • CSSηϨΫλͰࠔͬͨΒChrome։ൃπʔϧʂ

  96. CodeceptionͱҰॹʹ
 ςετͱ஥ྑ͘͠Α͏ʂ

  97. ͝੩ௌ
 ͋Γ͕ͱ͏͍͟͝·ͨ͠