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.6k
自作してみよう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
Practical Monitoring for Knative Serving / KubeCon + CloudNativeCon Japan 2025
hgsgtk
0
28
Cell-Based Architecture Design in AWS
hgsgtk
1
120
インフラコストとセキュリティ課題解決のためのリアーキテクチャリング / srekaigi2025
hgsgtk
3
6.3k
Design of a Stateful system for Robust Deployment and Observability
hgsgtk
0
1.3k
A guide to joining operational work in your new DevOps team
hgsgtk
1
1.4k
HTTP Tunneling in Go
hgsgtk
0
1.5k
ブラウザ自動操作技術の深層へ、直接触れて学ぶ WebDriver と Chrome DevTools Protocol
hgsgtk
3
6.7k
HTTP Server on random available port in Go
hgsgtk
0
1k
Agile Testingを夢見たテスト自動化 〜ATDDへの挑戦から始まる 1年間の試行錯誤〜 / dreaming agile testing at basebank
hgsgtk
14
8k
Other Decks in Technology
See All in Technology
~宇宙最速~2025年AWS Summit レポート
satodesu
1
1.8k
Observability в PHP без боли. Олег Мифле, тимлид Altenar
lamodatech
0
340
Claude Code Actionを使ったコード品質改善の取り組み
potix2
PRO
6
2.2k
Amazon Bedrockで実現する 新たな学習体験
kzkmaeda
2
540
TechLION vol.41~MySQLユーザ会のほうから来ました / techlion41_mysql
sakaik
0
180
Node-REDのFunctionノードでMCPサーバーの実装を試してみた / Node-RED × MCP 勉強会 vol.1
you
PRO
0
110
フィンテック養成勉強会#54
finengine
0
180
2025-06-26_Lightning_Talk_for_Lightning_Talks
_hashimo2
2
100
AIエージェント最前線! Amazon Bedrock、Amazon Q、そしてMCPを使いこなそう
minorun365
PRO
14
5.1k
あなたの声を届けよう! 女性エンジニア登壇の意義とアウトプット実践ガイド #wttjp / Call for Your Voice
kondoyuko
4
440
生成AI時代の開発組織・技術・プロセス 〜 ログラスの挑戦と考察 〜
itohiro73
0
140
ハノーバーメッセ2025座談会.pdf
iotcomjpadmin
0
160
Featured
See All Featured
Stop Working from a Prison Cell
hatefulcrawdad
270
20k
Optimising Largest Contentful Paint
csswizardry
37
3.3k
Optimizing for Happiness
mojombo
379
70k
Raft: Consensus for Rubyists
vanstee
140
7k
Building a Modern Day E-commerce SEO Strategy
aleyda
42
7.3k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
48
5.4k
Writing Fast Ruby
sferik
628
61k
A Modern Web Designer's Workflow
chriscoyier
694
190k
The Invisible Side of Design
smashingmag
299
51k
StorybookのUI Testing Handbookを読んだ
zakiyama
30
5.8k
Art, The Web, and Tiny UX
lynnandtonic
299
21k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
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!