Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
テストと仲良くするためのCodeceptionのはじめかた #phpkansai
Search
Ippei Sumida
July 15, 2017
Programming
2
3.8k
テストと仲良くするためのCodeceptionのはじめかた #phpkansai
PHPカンファレンス関西 2017の発表資料です。
Ippei Sumida
July 15, 2017
Tweet
Share
More Decks by Ippei Sumida
See All by Ippei Sumida
みんなでQAしてる話
ippey
0
59
AIで生成したものをAIでチェックしてる話
ippey
0
2k
『WordPressコミュニティで学ぶ』OSS貢献の多様性
ippey
0
700
25分で理解する!Symfonyの魅力とその実践的活用法
ippey
1
6.6k
素早いバリュー提供のための DROBEの新戦略
ippey
0
1.3k
Symfony 6.3のおすすめ新機能まとめ
ippey
1
1.8k
PhpStorm + GitHub Copilotはいいぞ
ippey
0
2.4k
それぞれの特徴から考えるフレームワーク選び
ippey
1
880
なるべくJavaScriptを書かないで SymfonyのUIをリッチにする Symfony UX
ippey
1
1.8k
Other Decks in Programming
See All in Programming
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
260
Recoilを剥がしている話
kirik
5
7.2k
PSR-15 はあなたのための ものではない? - phpcon2024
myamagishi
0
180
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
570
Mermaid x AST x 生成AI = コードとドキュメントの完全同期への道
shibuyamizuho
1
270
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
暇に任せてProxmoxコンソール 作ってみました
karugamo
2
730
Stackless и stackful? Корутины и асинхронность в Go
lamodatech
0
960
fs2-io を試してたらバグを見つけて直した話
chencmd
0
240
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
960
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
230
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
350
Featured
See All Featured
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.2k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
The Cult of Friendly URLs
andyhume
78
6.1k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
17
2.3k
Typedesign – Prime Four
hannesfritz
40
2.4k
GitHub's CSS Performance
jonrohan
1031
460k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
4 Signs Your Business is Dying
shpigford
182
21k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Transcript
ςετͱྑ͘͢ΔͨΊͷ Codeceptionͷ͡Ί͔ͨ PHP Conference Kansai 2017 2017-07-15
ࣗݾհ • ֯ాɹҰฏʢ͢Έͩɹ͍͍ͬʣ • ϑϦʔϥϯεΤϯδχΞ ˠ͓ࣄઈࢍืूதʂ • CoderDojoຕํɹද
ࠓͷඪ • Codeceptionʹ͍ͭͯͬͯΒ͏ • CodeceptionͷςετͷྲྀΕΛͬͯΒ͏ • ʰCodeceptionͱҰॹʹ ɹςετͱྑ͘ͳΖ͏ʱͱࢥͬͯΒ͏
ΞδΣϯμ • Codeceptionͱ • CodeceptionͰͷςετ࣮ • Codeception Tips
ςετॻ͍ͯ·͔͢ʁ
–ݪాɹ߁ੜ “ςετͷਫ࣭ௐࠪͩͱࢥͬͨΒ͍͍ Ͱ͢Α”
ւˡ
None
None
୯ମςετ ػೳςετ γεςϜɾडೖςετ
γεςϜςετ ػೳςετ ୯ମςετ
దࡐదॴͳςετΛ༻ҙ
దࡐదॴͷςετ… • ෆ۩߹ൃݟ͕༰қʹ • ఆ֎ͷӨڹΛૣظൃݟ • ֎෦ύοέʔδΛ҆৺ͯ͠ߋ৽
Codeceptionͱ
1.Codeceptionͱ ςεςΟϯάϑϨʔϜϫʔΫ (PHP)
PHPer Readableͳ ςεςΟϯάϑϨʔϜϫʔΫ 1.Codeceptionͱ
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ͱ
ςετͷཧָ͕ 1.Codeceptionͱ
1.Codeceptionͱ 6OJU w ֤Ϋϥεɺϝιου w 1)16OJUΠϯετʔϧ ෆཁ 1)16OJUΛར༻ͨ͠ ୯ମςετ 'VODUJPOBM
w ػೳ୯Ґ w ϦΫΤετʹର͢Δ ݁ՌΛ֬ೝ w ֤'8ରԠ 8FCαʔόΛհ͞ͳ ͍'8ςετ "DDFQUBODF w ػೳ୯Ґ w ը໘্ͷಈ࡞֬ೝ w ϒϥβґଘ ϒϥβΛར༻ͨ͠ डೖςετ
Codeception͚ͩͰ ֤छςετΛҰׅཧɺ࣮ߦ 1.Codeceptionͱ
֤छϑϨʔϜϫʔΫαϙʔτ 1.Codeceptionͱ
1.Codeceptionͱ And more…
ͦͷ΄͔ • REST APIςετՄ • ϨεϙϯγϒαΠτͷςετՄ • ֤छCIͱ࿈ܞՄ • Ωϟϓνϟऔಘ
• ίʔυΧόϨοδऔಘ
ଟػೳɾ؆୯ 1.Codeceptionͱ ςετͱྑ͘Ͱ͖ͦ͏ʂ
Conclusion • CodeceptionςεςΟϯάϑϨʔϜϫʔΫ • PHPer͕ಡΈ͍͢ςετίʔυ • ֤छςετΛҰׅཧɺ࣮ߦՄೳ • ֤छϑϨʔϜϫʔΫରԠ •
ͦͷଞॾʑ༻ҙ͞ΕͯΔͷͰྑ͘ͳΕͦ͏
CodeceptionͰͷςετ࣮
2.CodeceptionͰͷςετ࣮ 6OJU w ֤Ϋϥεɺϝιου w 1)16OJUΠϯετʔϧ ෆཁ 1)16OJUΛར༻ͨ͠ ୯ମςετ 'VODUJPOBM
w ػೳ୯Ґ w ϦΫΤετʹର͢Δ ݁ՌΛ֬ೝ w ֤'8ରԠ 8FCαʔόΛհ͞ͳ ͍'8ςετ "DDFQUBODF w ػೳ୯Ґ w ը໘্ͷಈ࡞֬ೝ w ϒϥβґଘ ϒϥβΛར༻ͨ͠ डೖςετ
Unit ϝιου࣮ߦ ϝιουΛ࣮ߦͯ͠ ࣮ߦ݁Ռʹରͯ͠ςετɻ 2.CodeceptionͰͷςετ࣮
Functional ϦΫΤετ FWʢϓϩάϥϜʣʹϦΫΤετΛͯ͠ɺ ࣮ߦ݁Ռʹରͯ͠ςετɻ = WebαʔόΛհ͞ͳ͍ 2.CodeceptionͰͷςετ࣮
Acceptance ϒϥβΛ੍ޚͯ͠ɺ ϒϥβදࣔ݁Ռʹରͯ͠ςετɻ 㲈ਓͷखʹΑΔϒϥβςετ 2.CodeceptionͰͷςετ࣮ ϦΫΤετ
࣮ߦ Unit > Functional > Acceptance 2.CodeceptionͰͷςετ࣮
શͯΛAcceptanceͰ ߦΘͳ͍ 2.CodeceptionͰͷςετ࣮
Acceptance = Ϧϋʔαϧ 2.CodeceptionͰͷςετ࣮
Πϯετʔϧ ڥ४උ ࣮ߦ 2.CodeceptionͰͷςετ࣮
2.CodeceptionͰͷςετ࣮ $ composer require —dev codeception/codeception Πϯετʔϧ
2.CodeceptionͰͷςετ࣮ bootstrap - ڥ࡞ build - ઃఆө $ vendor/bin/codecept bootstrap
$ vendor/bin/codecept build
2.CodeceptionͰͷςετ࣮ $ vendor/bin/codecept run ςετ࣮ߦʢҰׅʣ
2.CodeceptionͰͷςετ࣮ $ vendor/bin/codecept run acceptance HogeCest:hogeTest ςετ࣮ߦʢҰ෦ʣ TVJUF ςετϑΝΠϧɺϝιου
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ʣ
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ʣ
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ʣ ͲͷςετͰΤϥʔʹͳ͔ͬͨग़ྗ
2.CodeceptionͰͷςετ࣮ ࣮ߦ݁ՌʢNGʣ Τϥʔ࣌ʹͲͷΑ͏ͳ݁Ռ͕ग़ྗ͞Ε͔ͨอଘ
֤ઃఆ 2.CodeceptionͰͷςετ࣮
Unit Test 2.CodeceptionͰͷςετ࣮
2.CodeceptionͰͷςετ࣮ unit.suite.yml # Codeception Test Suite Configuration # # Suite
for unit or integration tests. actor: UnitTester modules: enabled: - Asserts - \Helper\Unit
2.CodeceptionͰͷςετ࣮ generate:test - testϑΝΠϧ࡞ $ vendor/bin/codecept generate:test unit HogeTest
Functional Test 2.CodeceptionͰͷςετ࣮
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'
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
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
2.CodeceptionͰͷςετ࣮ generate:cept - ceptϑΝΠϧ࡞ generate:cest - cestϑΝΠϧ࡞ $ vendor/bin/codecept generate:cept
functional HogeCept $ vendor/bin/codecept generate:cest functional HogeCest
Acceptance Test 2.CodeceptionͰͷςετ࣮
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
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 ϒϥβͷઃఆ
2.CodeceptionͰͷςετ࣮ 1)1#SPXTFS 1IBOUPN+4 pSFGPY DISPNF +BWB4DSJQU º ˚ ̋ #BTJDೝূ
̋ ˚ ̋ ࣮ߦ ̋ ˚ º
2.CodeceptionͰͷςετ࣮ 1)1 #SPXTFS 1IBOUPN+4 'JSFGPY $ISPNF 4FMFOJVN4UBOEBMPOF 4FSWFS ̋
̋ ̋ 1IBOUPN+4 ̋ DISPNFESJWFS ̋ Required
ϒϥβࢦఆ 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
2.CodeceptionͰͷςετ࣮ generate:cept - ceptϑΝΠϧ࡞ generate:cest - cestϑΝΠϧ࡞ $ vendor/bin/codecept generate:cept
acceptance HogeCept $ vendor/bin/codecept generate:cest acceptance HogeCest
ςετ࣮ 2.CodeceptionͰͷςετ࣮
CeptͱCest 2.CodeceptionͰͷςετ࣮
2.CodeceptionͰͷςετ࣮ $FQU w ্͔Βॱʹ࣮ߦ w ϑΝΠϧγφϦΦ w ؆୯ͳγφϦΦ͖ γφϦΦϑΝΠϧ $FTU
w 1)16OJUͷ༷ʹهड़ w ϝιουγφϦΦ w ෳࡶͳγφϦΦ0, γφϦΦΫϥε
2.CodeceptionͰͷςετ࣮ Cept <?php $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');
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', '
[email protected]
'); $I->fillField('#inquiry_question', '͓͍߹Θͤ༰'); $I->click('ૹ৴'); $I->canSee('͓͍߹Θͤྃ͠·ͨ͠ɻ', '#title'); } }
<?php class InquiryFunctionalCest { public function _before(FunctionalTester $I) { }
public function _after(FunctionalTester $I) { } // tests } 2.CodeceptionͰͷςετ࣮ Cest લॲཧʢ@CFGPSF ޙॲཧʢ@BGUFS
2.CodeceptionͰͷςετ࣮ $FQU w ্͔Βॱʹ࣮ߦ w ϑΝΠϧγφϦΦ w ؆୯ͳγφϦΦ͖ γφϦΦϑΝΠϧ $FTU
w 1)16OJUͷ༷ʹهड़ w ϝιουγφϦΦ w ෳࡶͳγφϦΦ0, γφϦΦΫϥε ɹ Φ ε ε ϝ ʂ ɹ
ϝιου උߟ ࢦఆͷϖʔδʹҠಈ *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Ͱࢦఆ Α͘͏ϝιου
ϝιου උߟ ςΩετϘοΫεʹॻ͘ *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ʣ
ϝιου උߟ %#ʹࢦఆͷσʔλ͕͋ Δ͔֬ೝ *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ʣ
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' => '͓͍߹Θͤ༰', ]); }
/** * ొςετ * * @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ʹʰ͓͍߹Θͤʱ ͱग़ྗ͞Ε͍ͯΔ͔ʁ
/** * ొςετ * * @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ʹʰ͢Έͩɹ͍͍ͬʱ Λೖྗ͢Δ
/** * ొςετ * * @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ςʔϒϧʹ ࢦఆͷ༰Ͱొ͞Εͨ σʔλ͕͋Δ͔֬ೝ
id, classΛదʹηοτ 2.CodeceptionͰͷςετ࣮ CodeceptionͰͷςετָ͕ʹʂ
Conclusion • ઃఆϑΝΠϧͰɺFWɾϒϥβͳͲΛઃఆ • Functional, Acceptanceςετͷॻ͖ํతʹ΄΅ಉ͡ • FunctionalWebαʔόΛհ͞ͳ͍ • ϒϥβʹΑΓͰ͖ͳ͍͜ͱ͋Δ
• CeptΑΓCest͕Φεεϝ • class, idΛదʹηοτ͢Δͱςετ͍͢͠
Codeception Tips ͬͱྑ͘͢ΔͨΊͷ
env 3.Codeception Tips
envͰ࣮ߦڥΛΓସ͑
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
$ vendor/bin/codecept run acceptance —env=firefox ڥΓସ͑ 3.Codeception Tips
/** * @param AcceptanceTester $I * @env firefox * @env
chrome */ public function tryToTest(AcceptanceTester $I) { // env=firefox or chrome͚ͩςετ } ΞϊςʔγϣϯͰڥΛࢦఆ 3.Codeception Tips
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 ΟϯυαΠζมߋ
disabled 3.Codeception Tips
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
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
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
CSSηϨΫλͷௐํ 3.Codeception Tips
3.Codeception Tips
3.Codeception Tips ͜͜ͷCSSηϨΫλ͕Θ͔Βͳ͍
3.Codeception Tips CSSηϨΫλͷίϐʔ͕Մೳ
3.Codeception Tips $$(‘[ηϨΫλ]’); Ͱݕূ
લɾޙॲཧϝιου 3.Codeception Tips
/** * ॏෳొςετ * @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
/** * ॏෳςετ༻ͷσʔλΛ࡞͢Δ * * @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”
@CFGPSF !CFGPSFͭΊ !BGUFSͭΊ 3.Codeception Tips @BGUFS !CFGPSFͭΊ !BGUFSͭΊ ςετϝιου
Conclusion • envΛࢦఆ͢Δ͜ͱͰɺϒϥβͳͲڥΛ Γସ͑ • @before, @afterΛઃఆͯ͠ɺಠࣗͷલɾޙॲ ཧΛૠೖ • CSSηϨΫλͰࠔͬͨΒChrome։ൃπʔϧʂ
CodeceptionͱҰॹʹ ςετͱྑ͘͠Α͏ʂ
͝੩ௌ ͋Γ͕ͱ͏͍͟͝·ͨ͠