$30 off During Our Annual Pro Sale. View Details »
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
57
AIで生成したものをAIでチェックしてる話
ippey
0
1.9k
『WordPressコミュニティで学ぶ』OSS貢献の多様性
ippey
0
680
25分で理解する!Symfonyの魅力とその実践的活用法
ippey
1
6.5k
素早いバリュー提供のための DROBEの新戦略
ippey
0
1.3k
Symfony 6.3のおすすめ新機能まとめ
ippey
1
1.7k
PhpStorm + GitHub Copilotはいいぞ
ippey
0
2.3k
それぞれの特徴から考えるフレームワーク選び
ippey
1
870
なるべくJavaScriptを書かないで SymfonyのUIをリッチにする Symfony UX
ippey
1
1.8k
Other Decks in Programming
See All in Programming
N.E.X.T LEVEL
pluu
2
270
React への依存を最小にするフロントエンド設計
takonda
21
8.9k
第5回日本眼科AI学会総会_AIコンテスト_3位解法
neilsaw
0
140
これが俺の”自分戦略” プロセスを楽しんでいこう! - Developers CAREER Boost 2024
niftycorp
PRO
0
110
似たもの同士のPerlとPHP
uzulla
1
110
カンファレンスの「アレ」Webでなんとかしませんか? / Conference “thing” Why don't you do something about it on the Web?
dero1to
2
160
イマのCSSでできる インタラクション最前線 + CSS最新情報
clockmaker
5
3.8k
デザインパターンで理解するLLMエージェントの作り方 / How to develop an LLM agent using agentic design patterns
rkaga
11
3.4k
ソフトウェアの振る舞いに着目し 複雑な要件の開発に立ち向かう
rickyban
0
810
14 Years of iOS: Lessons and Key Points
seyfoyun
1
680
Arm移行タイムアタック
qnighy
0
410
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
940
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
32
6.3k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Automating Front-end Workflow
addyosmani
1366
200k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Statistics for Hackers
jakevdp
796
220k
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
What's in a price? How to price your products and services
michaelherold
243
12k
How to Think Like a Performance Engineer
csswizardry
21
1.2k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.2k
Visualization
eitanlees
145
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ͱҰॹʹ ςετͱྑ͘͠Α͏ʂ
͝੩ௌ ͋Γ͕ͱ͏͍͟͝·ͨ͠