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

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

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

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

Ippei Sumida

July 15, 2017
Tweet

More Decks by Ippei Sumida

Other Decks in Programming

Transcript

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

    2017-07-15

    View full-size slide

  2. ࣗݾ঺հ
    • ֯ాɹҰฏʢ͢Έͩɹ͍ͬ΃͍ʣ
    • ϑϦʔϥϯεΤϯδχΞ

    ˠ͓࢓ࣄઈࢍืूதʂ
    • CoderDojoຕํɹ୅ද

    View full-size slide

  3. ࠓ೔ͷ໨ඪ
    • Codeceptionʹ͍ͭͯ஌ͬͯ΋Β͏
    • CodeceptionͷςετͷྲྀΕΛ஌ͬͯ΋Β͏
    • ʰCodeceptionͱҰॹʹ

    ɹςετͱ஥ྑ͘ͳΖ͏ʱͱࢥͬͯ΋Β͏

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  7. ୯ମςετ
    ػೳςετ
    γεςϜɾडೖςετ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  11. Codeceptionͱ͸

    View full-size slide

  12. 1.Codeceptionͱ͸
    ςεςΟϯάϑϨʔϜϫʔΫ

    (PHP੡)

    View full-size slide

  13. PHPer Readableͳ

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

    View full-size slide

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

    View full-size slide

  15. ςετͷ؅ཧָ͕
    1.Codeceptionͱ͸

    View full-size slide

  16. 1.Codeceptionͱ͸
    6OJU
    w ֤Ϋϥεɺϝιου
    w 1)16OJUΠϯετʔϧ

    ෆཁ
    1)16OJUΛར༻ͨ͠

    ୯ମςετ
    'VODUJPOBM
    w ػೳ୯Ґ
    w ϦΫΤετʹର͢Δ

    ݁ՌΛ֬ೝ
    w ֤'8ରԠ
    8FCαʔόΛհ͞ͳ
    ͍'8ςετ
    "DDFQUBODF
    w ػೳ୯Ґ
    w ը໘্ͷಈ࡞֬ೝ
    w ϒϥ΢βґଘ
    ϒϥ΢βΛར༻ͨ͠
    डೖςετ

    View full-size slide

  17. Codeception͚ͩͰ

    ֤छςετΛҰׅ؅ཧɺ࣮ߦ
    1.Codeceptionͱ͸

    View full-size slide

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

    View full-size slide

  19. 1.Codeceptionͱ͸
    And more…

    View full-size slide

  20. ͦͷ΄͔
    • REST APIςετՄ
    • ϨεϙϯγϒαΠτͷςετՄ
    • ֤छCIͱ࿈ܞՄ
    • Ωϟϓνϟऔಘ
    • ίʔυΧόϨοδऔಘ

    View full-size slide

  21. ଟػೳɾ؆୯
    1.Codeceptionͱ͸
    ςετͱ஥ྑ͘Ͱ͖ͦ͏ʂ

    View full-size slide

  22. Conclusion
    • Codeception͸ςεςΟϯάϑϨʔϜϫʔΫ
    • PHPer͕ಡΈ΍͍͢ςετίʔυ
    • ֤छςετΛҰׅ؅ཧɺ࣮ߦՄೳ
    • ֤छϑϨʔϜϫʔΫରԠ
    • ͦͷଞॾʑ༻ҙ͞ΕͯΔͷͰ஥ྑ͘ͳΕͦ͏

    View full-size slide

  23. CodeceptionͰͷςετ࣮૷

    View full-size slide

  24. 2.CodeceptionͰͷςετ࣮૷
    6OJU
    w ֤Ϋϥεɺϝιου
    w 1)16OJUΠϯετʔϧ

    ෆཁ
    1)16OJUΛར༻ͨ͠

    ୯ମςετ
    'VODUJPOBM
    w ػೳ୯Ґ
    w ϦΫΤετʹର͢Δ

    ݁ՌΛ֬ೝ
    w ֤'8ରԠ
    8FCαʔόΛհ͞ͳ
    ͍'8ςετ
    "DDFQUBODF
    w ػೳ୯Ґ
    w ը໘্ͷಈ࡞֬ೝ
    w ϒϥ΢βґଘ
    ϒϥ΢βΛར༻ͨ͠
    डೖςετ

    View full-size slide

  25. Unit
    ϝιου࣮ߦ
    ϝιουΛ࣮ߦͯ͠

    ࣮ߦ݁Ռʹରͯ͠ςετɻ

    2.CodeceptionͰͷςετ࣮૷

    View full-size slide

  26. Functional
    ϦΫΤετ
    FWʢϓϩάϥϜʣʹϦΫΤετΛ౉ͯ͠ɺ

    ࣮ߦ݁Ռʹରͯ͠ςετɻ

    = WebαʔόΛհ͞ͳ͍
    2.CodeceptionͰͷςετ࣮૷

    View full-size slide

  27. Acceptance
    ϒϥ΢βΛ੍ޚͯ͠ɺ

    ϒϥ΢βදࣔ݁Ռʹରͯ͠ςετɻ

    㲈ਓͷखʹΑΔϒϥ΢βςετ
    2.CodeceptionͰͷςετ࣮૷
    ϦΫΤετ

    View full-size slide

  28. ࣮ߦ଎౓͸

    Unit > Functional > Acceptance
    2.CodeceptionͰͷςετ࣮૷

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  31. Πϯετʔϧ

    ؀ڥ४උ
    ࣮ߦ
    2.CodeceptionͰͷςετ࣮૷

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  36. 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ʣ

    View full-size slide

  37. 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ʣ

    View full-size slide

  38. 2.CodeceptionͰͷςετ࣮૷
    ---------
    1) InquiryCest: Test ొ࿥ςετ
    Test tests/acceptance/InquiryCest.php:registerTest
    Failed asserting that any element by '#title' on page /inquiry/
    + ͓໰͍߹Θͤ
    contains text 'a͓໰͍߹Θͤ'
    ࣮ߦ݁ՌʢNGʣ
    ͲͷςετͰΤϥʔʹͳ͔ͬͨग़ྗ

    View full-size slide

  39. 2.CodeceptionͰͷςετ࣮૷
    ࣮ߦ݁ՌʢNGʣ
    Τϥʔ࣌ʹͲͷΑ͏ͳ݁Ռ͕ग़ྗ͞Ε͔ͨอଘ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  42. 2.CodeceptionͰͷςετ࣮૷
    unit.suite.yml
    # Codeception Test Suite Configuration
    #
    # Suite for unit or integration tests.
    actor: UnitTester
    modules:
    enabled:
    - Asserts
    - \Helper\Unit

    View full-size slide

  43. 2.CodeceptionͰͷςετ࣮૷
    generate:test - testϑΝΠϧ࡞੒
    $ vendor/bin/codecept generate:test unit HogeTest

    View full-size slide

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

    View full-size slide

  45. 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'

    View full-size slide

  46. 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

    View full-size slide

  47. 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

    View full-size slide

  48. 2.CodeceptionͰͷςετ࣮૷
    generate:cept - ceptϑΝΠϧ࡞੒
    generate:cest - cestϑΝΠϧ࡞੒
    $ vendor/bin/codecept generate:cept functional HogeCept
    $ vendor/bin/codecept generate:cest functional HogeCest

    View full-size slide

  49. Acceptance Test
    2.CodeceptionͰͷςετ࣮૷

    View full-size slide

  50. 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

    View full-size slide

  51. 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
    ϒϥ΢βͷઃఆ

    View full-size slide

  52. 2.CodeceptionͰͷςετ࣮૷
    1)1#SPXTFS 1IBOUPN+4
    pSFGPY
    DISPNF
    +BWB4DSJQU º ˚ ̋
    #BTJDೝূ ̋ ˚ ̋
    ࣮ߦ଎౓ ̋ ˚ º

    View full-size slide

  53. 2.CodeceptionͰͷςετ࣮૷
    1)1

    #SPXTFS
    1IBOUPN+4 'JSFGPY $ISPNF
    4FMFOJVN4UBOEBMPOF
    4FSWFS
    ̋ ̋ ̋
    1IBOUPN+4 ̋
    DISPNFESJWFS ̋
    Required

    View full-size slide

  54. ϒϥ΢βࢦఆ
    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

    View full-size slide

  55. 2.CodeceptionͰͷςετ࣮૷
    generate:cept - ceptϑΝΠϧ࡞੒
    generate:cest - cestϑΝΠϧ࡞੒
    $ vendor/bin/codecept generate:cept acceptance HogeCept
    $ vendor/bin/codecept generate:cest acceptance HogeCest

    View full-size slide

  56. ςετ࣮૷
    2.CodeceptionͰͷςετ࣮૷

    View full-size slide

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

    View full-size slide

  58. 2.CodeceptionͰͷςετ࣮૷
    $FQU
    w ্͔Βॱʹ࣮ߦ
    w ϑΝΠϧγφϦΦ
    w ؆୯ͳγφϦΦ޲͖
    γφϦΦϑΝΠϧ
    $FTU
    w 1)16OJUͷ༷ʹهड़
    w ϝιουγφϦΦ
    w ෳࡶͳγφϦΦ0,
    γφϦΦΫϥε

    View full-size slide

  59. 2.CodeceptionͰͷςετ࣮૷
    Cept
    $I = new FunctionalTester($scenario);
    $I->wantTo('͓໰͍߹Θͤొ࿥ςετ');
    $I->amOnPage('/inquiry');
    $I->canSee('͓໰͍߹Θͤ', '#title');
    $I->fillField('#inquiry_name', '͢Έͩɹ͍ͬ΃͍');
    $I->fillField('#inquiry_email', '[email protected]');
    $I->fillField('#inquiry_question', '͓໰͍߹Θͤ಺༰');
    $I->click('ૹ৴');
    $I->canSee('͓໰͍߹Θͤ׬ྃ͠·ͨ͠ɻ', '#title');

    View full-size slide

  60. 2.CodeceptionͰͷςετ࣮૷
    Cest
    class InquiryFunctionalCest
    {
    // tests
    public function registrationTest(FunctionalTester $I)
    {
    $I->amOnPage('/inquiry');
    $I->canSee('͓໰͍߹Θͤ', '#title');
    $I->fillField('#inquiry_name', '͢Έͩɹ͍ͬ΃͍');
    $I->fillField('#inquiry_email', '[email protected]');
    $I->fillField('#inquiry_question', '͓໰͍߹Θͤ಺༰');
    $I->click('ૹ৴');
    $I->canSee('͓໰͍߹Θͤ׬ྃ͠·ͨ͠ɻ', '#title');
    }
    }

    View full-size slide

  61. class InquiryFunctionalCest
    {
    public function _before(FunctionalTester $I)
    {
    }
    public function _after(FunctionalTester $I)
    {
    }
    // tests
    }
    2.CodeceptionͰͷςετ࣮૷
    Cest
    લॲཧʢ@CFGPSF

    ޙॲཧʢ@BGUFS

    View full-size slide

  62. 2.CodeceptionͰͷςετ࣮૷
    $FQU
    w ্͔Βॱʹ࣮ߦ
    w ϑΝΠϧγφϦΦ
    w ؆୯ͳγφϦΦ޲͖
    γφϦΦϑΝΠϧ
    $FTU
    w 1)16OJUͷ༷ʹهड़
    w ϝιουγφϦΦ
    w ෳࡶͳγφϦΦ0,
    γφϦΦΫϥε
    ɹ
    Φ
    ε
    ε
    ϝ
    ʂ
    ɹ

    View full-size slide

  63. ϝιου උߟ
    ࢦఆͷϖʔδʹҠಈ *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Ͱࢦఆ
    Α͘࢖͏ϝιου

    View full-size slide

  64. ϝιου උߟ
    ςΩετϘοΫεʹॻ͘
    *pMM'JFME lOBNFz
    lWBMVFz

    *pMM'JFME lOBNFz
    lWBMVFz

    ϑΟʔϧυ
    ໊ 9QBUI $444FMFDUPS
    Ͱࢦఆ
    ϥδΦϘλϯબ୒
    *
    DIFDL0QUJPO lOBNFz
    lWBMVFz

    *
    ϑΟʔϧυ
    ໊ 9QBUI $444FMFDUPS
    Ͱࢦఆ
    ηϨΫτϘοΫεɺ
    νΣοΫϘοΫεબ୒
    *
    TFMFDU0QUJPO lOBNFz
    lWBMVFz

    *
    ϑΟʔϧυ
    ໊ 9QBUI $444FMFDUPS
    Ͱࢦఆ
    ·ͱΊͯϑΥʔϜૹ৴
    *
    TVCNJU'PSN bGPSN`


    ϑΟʔϧυ
    ໊ 9QBUI $444FMFDUPS
    Ͱࢦఆ
    Α͘࢖͏ϝιουʢFormʣ

    View full-size slide

  65. ϝιου උߟ
    %#ʹࢦఆͷσʔλ͕͋
    Δ͔֬ೝ
    *TFF*O%BUBCBTF bςʔϒϧ
    ໊`

    DBOΛ͚ͭΔͱݟ͔ͭΒ
    ͳͯ͘΋ςετ͕ࢭ·Β
    ͳ͍
    %#ʹࢦఆͷσʔλ͕ͳ
    ͍͔֬ೝ
    *EPOU4FF*O%BUBCBTF bςʔ
    ϒϧ໊`

    DBOΛ͚ͭΔͱݟ͔ͭͬ
    ͯ΋ςετ͕ࢭ·Βͳ͍
    σʔλΛొ࿥͢Δ *IBWF*O%BUBCBTF bςʔϒϧ
    ໊`

    ςετσʔλ࡞੒࣌ʹ
    σʔλΛऔಘ͢Δ
    *HSBC'SPN%BUBCBTF
    bςʔϒϧ໊` bऔಘϑΟʔϧυ໊`


    Α͘࢖͏ϝιουʢDBʣ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  69. /**
    * ొ࿥ςετ
    *
    * @param AcceptanceTester $I
    */
    public function registerTest(AcceptanceTester $I)
    {
    $I->wantToTest('ొ࿥ςετ');
    $I->canSee('͓໰͍߹Θͤ', '#title');
    $I->fillField('#inquiry_name', '͢Έͩɹ͍ͬ΃͍');
    $I->fillField('#inquiry_email', '[email protected]');
    $I->fillField('#inquiry_question', '͓໰͍߹Θͤ಺༰');
    $I->click('ૹ৴');
    $I->canSee('͓໰͍߹Θͤ׬ྃ͠·ͨ͠ɻ', '#title');
    $I->canSeeInDatabase('inquiry', [
    'name' => '͢Έͩɹ͍ͬ΃͍',
    'email' => '[email protected]',
    'question' => '͓໰͍߹Θͤ಺༰',
    ]);
    }
    2.CodeceptionͰͷςετ࣮૷
    l*ORVJSZzςʔϒϧʹ
    ࢦఆͷ಺༰Ͱొ࿥͞Εͨ

    σʔλ͕͋Δ͔֬ೝ

    View full-size slide

  70. id, classΛద੾ʹηοτ
    2.CodeceptionͰͷςετ࣮૷
    CodeceptionͰͷςετָ͕ʹʂ

    View full-size slide

  71. Conclusion
    • ઃఆϑΝΠϧͰɺFWɾϒϥ΢βͳͲΛઃఆ
    • Functional, Acceptance͸ςετͷॻ͖ํతʹ͸΄΅ಉ͡
    • Functional͸WebαʔόΛհ͞ͳ͍
    • ϒϥ΢βʹΑΓͰ͖ͳ͍͜ͱ΋͋Δ
    • CeptΑΓ΋Cest͕Φεεϝ
    • class, idΛద੾ʹηοτ͢Δͱςετ͠΍͍͢

    View full-size slide

  72. Codeception Tips
    ΋ͬͱ஥ྑ͘͢ΔͨΊͷ

    View full-size slide

  73. env
    3.Codeception Tips

    View full-size slide

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

    View full-size slide

  75. 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

    View full-size slide

  76. $ vendor/bin/codecept run acceptance —env=firefox
    ؀ڥ੾Γସ͑
    3.Codeception Tips

    View full-size slide

  77. /**
    * @param AcceptanceTester $I
    * @env firefox
    * @env chrome
    */
    public function tryToTest(AcceptanceTester $I)
    {
    // env=firefox or chrome͚ͩςετ
    }
    ΞϊςʔγϣϯͰ؀ڥΛࢦఆ
    3.Codeception Tips

    View full-size slide

  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
    window_size: 1024x768
    3.Codeception Tips
    ΢Οϯυ΢αΠζมߋ

    View full-size slide

  79. disabled
    3.Codeception Tips

    View full-size slide

  80. 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

    View full-size slide

  81. 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

    View full-size slide

  82. 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

    View full-size slide

  83. CSSηϨΫλͷௐ΂ํ
    3.Codeception Tips

    View full-size slide

  84. 3.Codeception Tips

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  89. /**
    * ॏෳొ࿥ςετ
    * @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', '[email protected]');
    $I->fillField('#inquiry_question', '͓໰͍߹Θͤ಺༰');
    $I->click('ૹ৴');
    $I->canSee('͜ͷϝʔϧΞυϨε͸͢Ͱʹ࢖༻͞Ε͍ͯ·͢');
    }
    3.Codeception Tips

    View full-size slide

  90. /**
    * ॏෳςετ༻ͷσʔλΛ࡞੒͢Δ
    *
    * @param AcceptanceTester $I
    */
    protected function createData(AcceptanceTester $I)
    {
    $I->haveInDatabase('inquiry', [
    'name' => '͢Έͩɹ͍ͬ΃͍',
    'email' => '[email protected]',
    'question' => '͓໰͍߹Θͤ಺༰',
    'created_at' => \Carbon\Carbon::now()
    ]);
    }
    3.Codeception Tips
    લɾޙॲཧ༻ϝιου͸”protected”

    View full-size slide

  91. @CFGPSF

    !CFGPSFͭΊ
    !BGUFSͭΊ
    3.Codeception Tips
    @BGUFS

    !CFGPSFͭΊ
    !BGUFSͭΊ
    ςετϝιου

    View full-size slide

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

    View full-size slide

  93. CodeceptionͱҰॹʹ

    ςετͱ஥ྑ͘͠Α͏ʂ

    View full-size slide

  94. ͝੩ௌ

    ͋Γ͕ͱ͏͍͟͝·ͨ͠

    View full-size slide