Upgrade to Pro — share decks privately, control downloads, hide ads and more …

データベースを利用したテストを軽〜く実行したい時の味方: vimeo/php-mysql-en...

データベースを利用したテストを軽〜く実行したい時の味方: vimeo/php-mysql-engine / phperkaigi2021-lightning-talk

PHPerKaigi2021でのLTの資料です。
https://fortee.jp/phperkaigi-2021/proposal/e1e0ebd8-d60c-42ed-b6e6-9a7602258d42

★デモ動画
vimeo/php-mysql-engine を使ってテスト叩く様子 #phperkaigi - YouTube https://www.youtube.com/watch?v=PFNpLbBprb4

hideki kinjyo

March 28, 2021
Tweet

More Decks by hideki kinjyo

Other Decks in Programming

Transcript

  1. ࣗݾ঺հ • ⾦城秀樹 / きんじょうひでき • GitHub: @o0h / Twitter:

    @o0h_ • 好きなFWはCakePHP • アイコンは 美味しい鮭親⼦丼の写真です
  2. DBΛ࢖͏ςετԿ͕ਏ͍͚ͬʁ Q. ͲΜͳࣄʹ͓ࠔΓͰ͔͢ʁ => A. ४උɾ؅ཧɾ࣌ؒ 1. Ϧιʔε໘ • ʮDBΛཱͯΔʯඞཁ͕͋Δ

    • ϩʔΧϧ΍CI্ͰͷϝϞϦফඅͱ͔ઃఆͱ͔ԯ߷͔΋ʁ 2. ύϑΥʔϚϯε໘ • DB͸ʮେن໛ͳσʔλΛѻ͏ʯͷʹదͨ͠ςΫϊϩδʔ • ςετ࣌ͷσʔλ͸ɺʮগྔΛʯʮසൟʹʯೖΕସ͑Δͷ͕ओ
  3. ςετͱDBͷ޲͖߹͍ํɾر๬ฤ Q. Ͳ͏͠·͠ΐ͏͔ʁ => A. ͍͔ͭ͘Ξϓϩʔν͕͋Δ 1. ͦ΋ͦ΋ʮ୯ମςετͰDBΛ࢖͏ͳʯͱߟ͑Δ • ʮϨϙδτϦύλʔϯΛ༻͍ͯϞοΫ͢ΔʯͳͲ

    • μϛʔͷ݁ՌΛ༻ҙͯ͠(֎෦ϑΝΠϧԽͯ͠)࢖͏ͱ͔ 2. ΠϯϝϞϦDBΛ࢖͏ • SQLite࢖ͬͨΓ • ʮσʔλ͕গͳ͍ʯͳΒMySQLͷϝϞϦετϨʔδ΋͋Γ·͢͠
  4. ςετͱDBͷ޲͖߹͍ํɾࣄ݅ฤ Q. ͡Ό͋ͦΕͰղܾͰ͢Ͷʁ => A. ʮ׬ᘳʯͳΜͯ΋ͷͰ͸ͳ͍ɾɾɾ 1. ͦ΋ͦ΋ʮ୯ମςετͰDBΛ࢖͏ͳʯ • ϓϩμΫτίʔυ͕ʮͦ͏͍͏ઃܭʯʹͳ͍ͬͯΔ͔ʁͱ͍͏໰୊

    • ʮϞοΫͩΒ͚ʯΞϯνύλʔϯ 2. ΠϯϝϞϦDBΛ࢖͏ • ରԠ͍ͯ͠Δߏจ΍ػೳ͕ϓϩμΫγϣϯͱมΘ͍͍ͬͯͷʁ • ʮORMͰٵऩͰ͖Δ͔Βʯͱ͍͏൑அ͸ΞϦ͔΋͚ͩͲ • MySQLʹͯ͠΋ɺαʔόʔ(ͳ͍͠ϓϩηε)ͷ༻ҙɾ؅ཧͷඞཁੑ͕ੜ͡Δ
  5. vimeo/php-mysql-engine • σʔλϕʔε(MySQL)Λ༻͍ͨςετͷ೰Έͷ͓ॿ͚πʔϧ • VimeoࣾͷOSS • ੩తղੳπʔϧͷPsalm΍ ʮIt’s not legacy

    code — it’s PHPʯͷهࣄͰ͓ೃછΈͰ͢Ͷ • “Ninety-nine percent of our tests use it in place of an actual database”ͱͷ͜ͱ 参考: It’s not legacy code — it’s PHP. Vimeo has been using PHP in production | by Matt Brown | Vimeo Engineering Blog | Medium https://medium.com/vimeo-engineering-blog/its-not-legacy-code-it-s-php-1f0ee0462580
  6. ࣮ࡍʹଌͬͯΈΔ: ࣮ߦ಺༰ • Tests: 309, Assertions: 1026, Warnings: 1, Skipped:

    15 • 9,632 queries (DML+DDL+DCL) • τϥϯβΫγϣϯ؅ཧ(BEGINͱ͔COMMITͱ͔)ؚΉ • ࣮ߦ؀ڥ: php:8.0-fpm + Xdebug + CakePHP 4.2.4
  7. Appendix • ϐΫγϒඦՊࣄయͷςετʹphp-mysql-engineΛಋೖ͠·ͨ͠ - pixiv inside https://inside.pixiv.blog/2021/02/18/123000 • vimeo/php-mysql-engine: A

    MySQL engine written in pure PHP https://github.com/vimeo/php-mysql-engine • The great pretender: faster application tests with MySQL simulation | by Matt Brown | Vimeo Engineering Blog | Feb, 2021 | Medium https://medium.com/vimeo-engineering-blog/the-great-pretender-faster- application-tests-with-mysql-simulation-26250f13d251