Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
テストと仲良くするためのCodeceptionのはじめかた #phpkansai
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Ippei Sumida
July 15, 2017
Programming
4.4k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
テストと仲良くするためのCodeceptionのはじめかた #phpkansai
PHPカンファレンス関西 2017の発表資料です。
Ippei Sumida
July 15, 2017
More Decks by Ippei Sumida
See All by Ippei Sumida
DROBEの生成AI活用事例 with AWS
ippey
0
330
みんなでQAしてる話
ippey
0
190
AIで生成したものをAIでチェックしてる話
ippey
0
2.4k
『WordPressコミュニティで学ぶ』OSS貢献の多様性
ippey
0
1.4k
25分で理解する!Symfonyの魅力とその実践的活用法
ippey
1
7.9k
素早いバリュー提供のための DROBEの新戦略
ippey
0
1.5k
Symfony 6.3のおすすめ新機能まとめ
ippey
1
2.2k
PhpStorm + GitHub Copilotはいいぞ
ippey
0
3.2k
それぞれの特徴から考えるフレームワーク選び
ippey
1
1.2k
Other Decks in Programming
See All in Programming
thread_parallel_with_free-threaded_Python_and_NumPy.pdf
riku_sakamoto
0
340
Heart of Swift Concurrency
koher
0
890
モバイル交通系ICへのチャージ実例から考える、クロスプラットフォーム開発におけるiOS実機テスト設計とCI運用
yusuga
1
490
AWS Step Functions 大規模並列の壁を越える / jaws-sonic-2026-niigata-step-functions
kasacchiful
PRO
1
480
Building an Out-of-Order CPU
latte72
1
790
フロントエンドUIフレームワークのこれまでとこれから
ssssota
5
2.8k
AWS DevOps Agentで インシデント対応をAIに任せたい
honmarkhunt
7
3k
GKE で Pod の見方を変えたら、スケールアウト時の挙動を真に捉えられた話
stkk
0
130
Go × SIMDで高速化するベクトル検索 ~ルーフラインモデルでSIMDが効く境界を探れ! ~
po3rin
1
1.6k
ゲームコントローラやキーボードのファームウェアをSwiftで書く
kishikawakatsumi
1
240
MVNOの申込からeSIM開通までをiOSアプリでつなぐ- 本人確認・MNP・通信事業者基盤をまたぐ実装
satotakeshi
0
430
XHTMLが残したもの
yosuke_furukawa
PRO
2
810
Featured
See All Featured
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
56
3.5k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
670
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
46k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
280
Are puppies a ranking factor?
jonoalderson
2
3.9k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.4k
Building Adaptive Systems
keathley
44
3.2k
Producing Creativity
orderedlist
PRO
348
41k
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
230
The SEO Collaboration Effect
kristinabergwall1
1
570
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.6k
The Curse of the Amulet
leimatthew05
3
15k
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ͱҰॹʹ ςετͱྑ͘͠Α͏ʂ
͝੩ௌ ͋Γ͕ͱ͏͍͟͝·ͨ͠