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
49
AIで生成したものをAIでチェックしてる話
ippey
0
1.9k
『WordPressコミュニティで学ぶ』OSS貢献の多様性
ippey
0
660
25分で理解する!Symfonyの魅力とその実践的活用法
ippey
1
6.4k
素早いバリュー提供のための DROBEの新戦略
ippey
0
1.2k
Symfony 6.3のおすすめ新機能まとめ
ippey
1
1.7k
PhpStorm + GitHub Copilotはいいぞ
ippey
0
2.3k
それぞれの特徴から考えるフレームワーク選び
ippey
1
860
なるべくJavaScriptを書かないで SymfonyのUIをリッチにする Symfony UX
ippey
1
1.8k
Other Decks in Programming
See All in Programming
as(型アサーション)を書く前にできること
marokanatani
9
2.6k
C++でシェーダを書く
fadis
6
4.1k
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
110
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
110
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.3k
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
6
1.1k
Quine, Polyglot, 良いコード
qnighy
4
640
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
190
Featured
See All Featured
A designer walks into a library…
pauljervisheath
203
24k
Rails Girls Zürich Keynote
gr2m
94
13k
4 Signs Your Business is Dying
shpigford
180
21k
The World Runs on Bad Software
bkeepers
PRO
65
11k
We Have a Design System, Now What?
morganepeng
50
7.2k
Thoughts on Productivity
jonyablonski
67
4.3k
Why Our Code Smells
bkeepers
PRO
334
57k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Visualization
eitanlees
145
15k
Automating Front-end Workflow
addyosmani
1366
200k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
Fireside Chat
paigeccino
34
3k
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ͱҰॹʹ ςετͱྑ͘͠Α͏ʂ
͝੩ௌ ͋Γ͕ͱ͏͍͟͝·ͨ͠