ランダムデータをPHPで作る

 ランダムデータをPHPで作る

PHPカンファレンス2015 LT

C4c161ae9eeeed8f161197410f7a228a?s=128

Kenichiro Kishida

October 03, 2015
Tweet

Transcript

  1. “joind.in” => https://m.joind.in/talk/ dc860

  2. ϥϯμϜσʔλΛ 1)1Ͱ࡞Δ 1)1$POGFSFODFCZ!TJ[VIJLP Photo by Tom_Brown 6117 on GATAG Generate

    Randomize Data By PHP
  3. ,FOJDIJSP,JTIJEB 5PLZP +"1"/ TJ[VIJLP!HNBJMDPN !TJ[VIJLP IUUQTHJUIVCDPNTJ[VIJLP IUUQCMPHPQFOUPLZPKQ +1POMZ

  4. ςετσʔλ Ͳ͏΍ͬͯ ࡞͍ͬͯ·͔͢ʁ How to generate test data ?

  5. None
  6. ͍΍ͩʔ be messed up!

  7. ͍͍ͷ͋ΔΑ look nice

  8. ԿͦΕᚶ͍͠ʂ sparking service

  9. None
  10. w0QFO4PVSDF (1-W https://github.com/benkeen/generatedata wϥϯμϜσʔλΛੜ੒͢Δπʔϧ Tool for generation randomize data w1)1

     .Z42-  Ͱಈ࡞ wίϛϡχςΟʹΑΔ%PDLFS 7BHSBOU؀ڥ͕͋Δ exists runtime environment of Docker or Vagrant
  11. w$47 &YDFM w)5.- UBCMF VM EM TNBSUZ w+40/ w-%*' w1)1

    +BWF4DSJQU 1FSM 3VCZ w42- w9.-
  12. None
  13. <?php $data = array( array("name"=>"Geoffrey","email"=>"Nunc.ut@semper .net","tel"=>"034-991-2370","birthday"=>"2016-02- 22 13:05:25"), array("name"=>"Aphrodite","email"=>"tincidunt.ped e@idrisusquis.com","tel"=>"043-887-2463","birthda

    y"=>"2015-01-08 22:03:43"), array("name"=>"Karina","email"=>"dictum.Proin.ege t@ipsumleoelementum.edu","tel"=>"056-305-6396","b irthday"=>"2015-04-13 03:37:49"), array("name"=>"Gage","email"=>"in@nisl.co.uk","te
  14. w໊લɺి࿩൪߸ɺϝʔϧΞυϨεɺձ ໊ࣾɺޱ࠲൪߸ɺ೔෇ɺΫϨδοτΧ ʔυ൪߸ɺॅॴɺ༣ศ൪߸ w୯ޠ ࢦఆϥϯμϜݸ਺ ɺ਺஋ ࿈൪ ཚ਺ൣғ ɺ௨՟ wπϦʔɺϦετɺεΫϦϓτ

    4NBSUZ
  15. ʹΌΜ΍ͬͯʂʁ

  16. ҎԼͷΑ͏ʹɺ4NBSUZεΫϦϓ τΛॻ͍ͯɺଞͷྻͷ஋ʹରԠͨ͠ ஋ΛηοτͰ͖ͨΓ͢Δɻ {if $ROW1 == 5}N/A{else}{$ROW1}{/if}

  17. wҰ౓ఆٛͨ͠ϧʔϧ͸อଘͯ͠࠶ར༻ Մೳ the difinition can save to database w8FC6*͚ͩ͡Όͳ͘3&45"1*΋͋ Δ

    have REST API not only Web UI w೔ຊޠͷݴޠϑΝΠϧͳ͍ but, not have japanese language file :-(
  18. ͦΕ 'BLFSͰྑ͘Ͷʁ

  19. w0QFO4PVSDF .*5 https://github.com/fzaninotto/Faker wϥϯμϜσʔλΛੜ੒͢ΔϥΠϒϥϦ library for generation randomize data w1)1

     Ͱಈ࡞ wҰ෦03.ʹ΋ରԠ supported any ORM, doctrine, propel
  20. w1)1ϓϩάϥϚ޲͚ for PHP programer w೔ຊޠͷݴޠϑΝΠϧ͕͋Δ it have japanese language file

    wσʔλλΠϓͷ਺͕ HFOFSBUFEBUBDPNΑΓଟ͍ it have many data types more than generatedata.com wओʹ஋Λੜ੒͢ΔͨΊͷϥΠϒϥϦ it focus to generate fake value
  21. ͱʹ͔͘ద౰ͳ஋Λ%#ʹ ஋ΛೖΕ͍͚ͨͩͳΜͩΑ I want to insert fake data into database,

    just like that
  22. w0QFO4PVSDF .*5 https://github.com/sizuhiko/Fabricate wςʔϒϧͷεΩʔϚ৘ใΛݩʹϥϯμ ϜσʔλΛੜ੒͢ΔϥΠϒϥϦ library for generation fake data

    from schema of table on DB w1)1  Ͱಈ࡞ wσʔλϕʔεඞਢ require database
  23. w1)1ϓϩάϥϚ޲͚ for PHP programer w಺෦Τϯδϯ͸'BLFS use Faker for generation randomize

    data wಠࣗʹมߋ͍ͨ͠ΧϥϜ্͚ͩॻ͖Մ ೳ be able to overwrite, you want it wݱ࣌఺͸$BLF1)1$BLF1)1 ͷΈରԠ ORM adaptors, CakePHP2, CakePHP3 currentry
  24. ͓ئ͍ 1MFBTF 'BCSJDBUFͰ͸֤03.༻ͷΞμϓλʔ ࣮૷Λ଴͍ͬͯ·͢ Fabricate wait to contribute any ORM

    adaptor on github
  25. /** Fabricate Xxxxx Adaptor */ class XxxxFabricateAdaptor extends AbstractFabricateAdaptor {

    public function getModel($modelName) { $model = new FabricateModel($modelName); // εΩʔϚ৘ใ͔ΒϞσϧΦϒδΣΫτΛੜ੒͢Δ return $model; } public function create($modelName, $attributes, $recordCount) { // ORM΁σʔλΛอଘ͢ΔॲཧΛॻ͘ return $entities; } public function build($modelName, $data) { // ORMͷΤϯςΟςΟΫϥεΛੜ੒͢Δ return $entity; } }
  26. w&YDFMͷ୅ΘΓͱͯ͠ HFOFSBUFEBUB͕ྑ͍ͱࢥ͏ wϓϩάϥϚ͸'BLFS͕ศར w'BCSJDBUF΋࢖ͬͯΈ͍ͯͩ͘͞ˍ Ξμϓλʔ࣮૷଴͍ͬͯ·͢ ·ͱΊ

  27. WJTJUNZCMPHHJUIVC https://github.com/sizuhiko 5IBOLZPV http://blog.open.tokyo.jp