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
自作してみようxUnitフレームワーク / try-to-self-made-xunit
Search
Kazuki Higashiguchi
December 01, 2019
Technology
0
1.5k
自作してみようxUnitフレームワーク / try-to-self-made-xunit
PHPカンファレンス2019にて発表する懇親会LTの資料です
Kazuki Higashiguchi
December 01, 2019
Tweet
Share
More Decks by Kazuki Higashiguchi
See All by Kazuki Higashiguchi
インフラコストとセキュリティ課題解決のためのリアーキテクチャリング / srekaigi2025
hgsgtk
3
5k
Design of a Stateful system for Robust Deployment and Observability
hgsgtk
0
1.2k
A guide to joining operational work in your new DevOps team
hgsgtk
1
1.4k
HTTP Tunneling in Go
hgsgtk
0
1.4k
ブラウザ自動操作技術の深層へ、直接触れて学ぶ WebDriver と Chrome DevTools Protocol
hgsgtk
3
6.5k
HTTP Server on random available port in Go
hgsgtk
0
980
Agile Testingを夢見たテスト自動化 〜ATDDへの挑戦から始まる 1年間の試行錯誤〜 / dreaming agile testing at basebank
hgsgtk
14
7.8k
Create Go WebDriver client from scratch
hgsgtk
1
2.2k
PHPでWeb Driver Clientを自作する〜己の手でブラウザ操作自動化を完全理解する方法〜 / phpcon2021
hgsgtk
2
2.5k
Other Decks in Technology
See All in Technology
スキルだけでは満たせない、 “組織全体に”なじむオンボーディング/Onboarding that fits “throughout the organization” and cannot be satisfied by skills alone
bitkey
0
180
AIエージェント元年@日本生成AIユーザ会
shukob
1
210
LINE NEWSにおけるバックエンド開発
lycorptech_jp
PRO
0
240
AWSを活用したIoTにおけるセキュリティ対策のご紹介
kwskyk
0
350
JAWS FESTA 2024「バスロケ」GPS×サーバーレスの開発と運用の舞台裏/jawsfesta2024-bus-gps-serverless
ma2shita
3
160
【5分でわかる】セーフィー エンジニア向け会社紹介
safie_recruit
0
19k
OPENLOGI Company Profile
hr01
0
60k
OPENLOGI Company Profile for engineer
hr01
1
20k
2/18 Making Security Scale: メルカリが考えるセキュリティ戦略 - Coincheck x LayerX x Mercari
jsonf
0
210
クラウド関連のインシデントケースを収集して見えてきたもの
lhazy
7
940
クラウド食堂とは?
hiyanger
0
110
入門 PEAK Threat Hunting @SECCON
odorusatoshi
0
150
Featured
See All Featured
Faster Mobile Websites
deanohume
306
31k
How STYLIGHT went responsive
nonsquared
98
5.4k
Optimising Largest Contentful Paint
csswizardry
34
3.1k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Automating Front-end Workflow
addyosmani
1368
200k
Code Review Best Practice
trishagee
67
18k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
4
370
Become a Pro
speakerdeck
PRO
26
5.2k
Optimizing for Happiness
mojombo
376
70k
Scaling GitHub
holman
459
140k
A Modern Web Designer's Workflow
chriscoyier
693
190k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
160
15k
Transcript
© - BASE, Inc. X \ ⾃作してみよう / xUnitフレームワーク .
. PHP Conference 懇親会LT - @hgsgtk - Let’s make xUnit framework -
© - BASE, Inc. About me BASE BANK, Inc. Dev
Division Tech Lead 『みんなのPHP 現場で役⽴つ最新 ノウハウ!』共著者 (PHPにおけるユニットテスト) https://www.amazon.co.jp/ gp/product/ @hgsgtk Kazuki Higashiguchi
© - BASE, Inc. Do you love PHPUnit?
© - BASE, Inc. I LOVE PHPUnit
© - BASE, Inc. But need more
© - BASE, Inc. If you make xUnit framework
© - BASE, Inc. You will love PHPUnit more!
© - BASE, Inc. Let’s make it!
© - BASE, Inc. By the way, PHPUnit is https://phpunit.de/
© - BASE, Inc. About xUnit Generic name of testing
framework Kent Beck: SUnit (Smalltalk) -> JUnit (Java) Sebastian Bergmann: PHPUnit (PHP) https://en.wikipedia.org/wiki/XUnit
© - BASE, Inc. Main features of xUnit family •
Test Method • Assertion Method • Test Suites • Run tests, Get report Refs:Meszaros, Gerard. xUnit Test Patterns: Refactoring Test Code』
© - BASE, Inc. Today’s topic • Test Method •
Assertion Method • Test Suites • Run tests, Get report Refs:Meszaros, Gerard. xUnit Test Patterns: Refactoring Test Code』
© - BASE, Inc. Let’s go
© - BASE, Inc. hgsgtk/mpunit https://github.com/hgsgtk/mpunit
© - BASE, Inc. The Goal is to execute this
test
© - BASE, Inc. • Test Method • Assertion Method
• Test Suites • Run tests, Get report Refs:Meszaros, Gerard. xUnit Test Patterns: Refactoring Test Code』 Today’s topic
© - BASE, Inc. Make executable command /bin/mpunit
© - BASE, Inc. Find test methods and execute them
.Find test files .Find test classes .Find test methods .Execute test methods
© - BASE, Inc. . Find test files /src/Command.php Collect
files “*Test.php”
© - BASE, Inc. . Find test classes /src/Command.php 定義済みクラスから、ユーザー定義型で
MPUnit\TestCaseを継承して いるを探し出す
© - BASE, Inc. . Find test classes /src/Command.php Get
declared classes
© - BASE, Inc. . Find test classes /src/Command.php Is
user defined?
© - BASE, Inc. . Find test classes /src/Command.php Is
extended MPUnit\TestCase?
© - BASE, Inc. (Tips)PHP feature to collect classes •
get_declared_classes() • 定義済みのクラスの名前を配列として返す • ReflectionClass::isUserDefined() • 内部クラスかどうかを検査 • ReflectionClass::getParentClass() • 親クラスの情報を取得 https://www.php.net/manual/ja/reflectionclass.isuserdefined.php https://www.php.net/manual/ja/function.get-declared-classes.php https://www.php.net/manual/ja/reflectionclass.getparentclass.php
© - BASE, Inc. . Find test methods /src/Command.php テストクラスのPUBLICメソッドから、先頭
が test で始まるメソッドを探す
© - BASE, Inc. . Find test methods /src/Command.php テストクラスのPUBLICメソッドから、先頭
が test で始まるメソッドを探す Find public method which name starts ʻtest’
© - BASE, Inc. (Tips)Gather functions • ReflectionClass::getMethods • クラスのメソッド名を取得
• ReflectionMethod::IS_PUBLIC etc https://www.php.net/manual/ja/reflectionclass.getmethods.php
© - BASE, Inc. . Execute test methods /src/Command.php If
AssertionError => Failed (F) Else => Success (.)
© - BASE, Inc. Understand xUnit • Two strategies to
find test functions • Test Discovery‧Test Enumeration • In Test Discovery, user does not need to register manually • Almost xUnit families’ strategy is Test Discovery
© - BASE, Inc. • Test Method • Assertion Method
• Test Suites • Run tests, Get report Refs:Meszaros, Gerard. xUnit Test Patterns: Refactoring Test Code』 Today’s topic
© - BASE, Inc. Ways to assert • assert function(PHP)
• (Choice it, because I want to implement with minimum dependencies) • beberlei/assert • webmozart/assert • hamcrest/hamcrest-php etc
© - BASE, Inc. Setting assertion options /bin/mpunit
© - BASE, Inc. (Tips)Setting directive for assertion • zend.assertions
(default: ) • assert()を⽣成するか‧実⾏するか • 1 の場合、コードは⽣成され実⾏される • assert.exception (default: ) • アサーション失敗に指定したオブジェクトをス ロー • 指定なしだとAssertionError https://www.php.net/manual/ja/function.assert.php https://www.php.net/manual/ja/class.assertionerror.php
© - BASE, Inc. (Tips)Options for assertion • 様々なassertフラグを設定できる •
ASSERT_ACTIVE • ASSERT_WARNING • ASSERT_BAIL • ASSERT_QUIET_EVAL • ASSERT_CALLBACK https://www.php.net/manual/ja/function.assert-options.php
© - BASE, Inc. assertion Make assertion method “assertSame”
© - BASE, Inc. • Test Method • Assertion Method
• Test Suites • Run tests, Get report Refs:Meszaros, Gerard. xUnit Test Patterns: Refactoring Test Code』 Today’s topic
© - BASE, Inc. Run tests, Get report TestCaseを継承したクラスから assertSame
が使えるように Use assertion method in test method
© - BASE, Inc. hgsgtk/mpunit https://github.com/hgsgtk/mpunit Demonstration
© - BASE, Inc. Get Report
© - BASE, Inc. By making xUnit, • PHPUnit has
a lot of features, it’s amazing!! • I also red internal implementations of PHPUnit to make it. I learned a lot.
© - BASE, Inc. LOVE to PHPUnit became STRONGER!! By
making xUnit,
© - BASE, Inc. X Thanks!