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
69
AIで生成したものをAIでチェックしてる話
ippey
0
2k
『WordPressコミュニティで学ぶ』OSS貢献の多様性
ippey
0
750
25分で理解する!Symfonyの魅力とその実践的活用法
ippey
1
6.7k
素早いバリュー提供のための DROBEの新戦略
ippey
0
1.3k
Symfony 6.3のおすすめ新機能まとめ
ippey
1
1.8k
PhpStorm + GitHub Copilotはいいぞ
ippey
0
2.4k
それぞれの特徴から考えるフレームワーク選び
ippey
1
900
なるべくJavaScriptを書かないで SymfonyのUIをリッチにする Symfony UX
ippey
1
1.9k
Other Decks in Programming
See All in Programming
PicoRubyと暮らす、シェアハウスハック
ryosk7
0
250
AWSマネコンに複数のアカウントで入れるようになりました
yuhta28
2
130
“あなた” の開発を支援する AI エージェント Bedrock Engineer / introducing-bedrock-engineer
gawa
9
1k
2025.01.17_Sansan × DMM.swift
riofujimon
2
620
Linux && Docker 研修/Linux && Docker training
forrep
15
2.8k
ESLintプラグインを使用してCDKのセオリーを適用する
yamanashi_ren01
2
260
HTML/CSS超絶浅い説明
yuki0329
0
200
ある日突然あなたが管理しているサーバーにDDoSが来たらどうなるでしょう?知ってるようで何も知らなかったDDoS攻撃と対策 #phpcon.2024
akase244
2
7.8k
rails newと同時に型を書く
aki19035vc
6
730
DevFest - Serverless 101 with Google Cloud Functions
tunmise
0
140
「とりあえず動く」コードはよい、「読みやすい」コードはもっとよい / Code that 'just works' is good, but code that is 'readable' is even better.
mkmk884
6
1.5k
Amazon Bedrock Multi Agentsを試してきた
tm2
1
180
Featured
See All Featured
Unsuck your backbone
ammeep
669
57k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
20
2.4k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
174
51k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
5
200
A Modern Web Designer's Workflow
chriscoyier
693
190k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
7
590
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
33
2.7k
Making the Leap to Tech Lead
cromwellryan
133
9k
KATA
mclloyd
29
14k
Agile that works and the tools we love
rasmusluckow
328
21k
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ͱҰॹʹ ςετͱྑ͘͠Α͏ʂ
͝੩ௌ ͋Γ͕ͱ͏͍͟͝·ͨ͠