cake php + php unitによる実践的ユニットテスト

48
CakePHP + PHPUnitによる 実践的ユニットテスト 2013/07/06 ゆるかわPHP#2 松 慶信(@yshnb) 2013/07/06 ゆるかわPHP #2

Upload: yoshinobu-wakamatsu

Post on 30-Jun-2015

8.119 views

Category:

Technology


3 download

TRANSCRIPT

  • 1. CakePHP + PHPUnit 2013/07/06 PHP#2 @yshnb

2. 1987/8/1 Web 3. CakPHP 4. CakePHP ActiveRecord Web 5. Google Web 2012/07 ~ 2013/06 CakePHP > 6. Google Web 2012/07 ~ 2013/06 7. CakePHP CakePHP1.x SimpleTest CakePHP2 PHPUnit 8. PHPUnit xUnit PHPUnit3.8 JenkinsCI 9. 10. 11. 100% 12. 100% 13. 14. 15. 16. $actual = $this->Sample->getSomething(); $this->assertInternalType("array", $something); $this->assertEquals($expected, $something); 17. Q. 18. CakePHP 19. CakePHP MVCModel2 Model + Controller + Model 20. public function url2link($url = null) { return empty($url) ? $url : "{$url}"; } public function createHoge($data) { $this->create(); return $this->save($data); } 21. 22. 23. 24. Model (Component) Controller (Behavior, Shell) Model 25. 26. Model Fixture 27. Model // $this->Hoge->save($this->sampleData); // $data = $this->Hoge->getTableData(); // $this->assertIntenralType(array, $data); $this->assertDataFormat($data); 28. Controller Model, Component 29. Controller Controller ControlllerTestCase::generate set 30. Controller // $this->Hoges = $this->generates(Hoges); // $this->testAction(/test/); // $this->assertArrayHasKey(hoge, $this->vars); 31. Tips dataProvider 32. dataProvider 33. dataProvider public function dp_sample() { $cases[] = array(1); // Case1 $cases[] = array(-1); // Case2 return $cases; } /** * @test * @dataProvider dp_sample */ public function dp_sample($arg) { // } 34. 35. // $__privateMethod = new ReflectionMethod(Subject, __privateMethod); $__privateMethod->setAccessible(true); // public // $__privateMethod->invoke($this->Subject, null); // // ReflectionMethod 36. Closure::bind(function() { // $Subject = ClassRegistry::init(Subject); // $Subject->doSomething(); // }, $this, Subject)->__invoke(); Closure::bind() 37. public function register() { App::uses("File", "Utility"); $file = new File("/path/to/file"); if ($file->open()) { // } } Filew 38. public function startup() { App::uses("File", "Utility"); $this->File = new File("/path/to/file"); } public function register() { if ($this->File->open()) { $filetext = $this->File->read(); } } 39. 40. Jenkins 41. Jenkins 42. Jenkins Mess Detector Code Sniffer Copy Paste Detecor 43. Phing 44. PHP Ant 45.