{"id":2083,"date":"2013-11-24T00:57:30","date_gmt":"2013-11-23T15:57:30","guid":{"rendered":"http:\/\/codaholic.org\/?p=2083"},"modified":"2020-08-23T01:32:43","modified_gmt":"2020-08-22T16:32:43","slug":"phpunit-%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%80%81%e7%89%b9%e5%ae%9a%e3%81%ae%e3%83%a1%e3%82%bd%e3%83%83%e3%83%89%e3%81%8c%e5%91%bc%e3%81%b3%e5%87%ba%e3%81%95%e3%82%8c%e3%81%9f%e3%81%93%e3%81%a8","status":"publish","type":"post","link":"https:\/\/codaholic.org\/?p=2083","title":{"rendered":"PHPUnit \u3092\u4f7f\u3063\u3066\u3001\u7279\u5b9a\u306e\u30e1\u30bd\u30c3\u30c9\u304c\u547c\u3073\u51fa\u3055\u308c\u305f\u3053\u3068\u3092\u78ba\u304b\u3081\u308b"},"content":{"rendered":"<p>PHPUnit \u306e\u30e2\u30c3\u30af\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f7f\u3063\u3066\u3001\u60f3\u5b9a\u3055\u308c\u305f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30e1\u30bd\u30c3\u30c9\u304c\u60f3\u5b9a\u3055\u308c\u305f\u5f15\u6570\u3092\u6e21\u3055\u308c\u3066\u547c\u3070\u308c\u3066\u3044\u308b\u3053\u3068\u3092\u30c6\u30b9\u30c8\u3057\u307e\u3059\u3002\u30e2\u30c3\u30af\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u5177\u4f53\u7684\u306b\u4f55\u306e\u5f79\u306b\u7acb\u3064\u306e\u304b\u30e2\u30e4\u30e2\u30e4\u3057\u3066\u305f\u306e\u3067\u3059\u304c\u3001\u52d5\u304b\u3057\u3066\u307f\u3066\u3084\u3063\u3068\u30e1\u30ea\u30c3\u30c8\u304c\u7406\u89e3\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<p><!--more--><br \/>\n\u307e\u305a\u3001\u4e0b\u8a18\u306f\u30c6\u30b9\u30c8\u5bfe\u8c61\u3068\u306a\u308b\u30af\u30e9\u30b9\u3067\u3059\u3002greet \u30e1\u30bd\u30c3\u30c9\u306f\u5f15\u6570\u306b $name \u3092\u53d6\u308a\u3001Hello \u3068\u3044\u3046\u6587\u5b57\u5217\u3068\u3064\u306a\u3052\u3066\u8fd4\u5374\u3057\u307e\u3059\u3002<\/p>\n<p>Hoge.php<\/p>\n<pre><code class=\"language-php\">&lt;?php\n\nclass Hoge{\n  function greet($name){\n    return 'Hello, ' . $name;\n  }\n}\n<\/code><\/pre>\n<p>\u6b21\u306b\u30c6\u30b9\u30c8\u7528\u306e\u30b3\u30fc\u30c9\u3067\u3059\u3002\u3053\u306e\u30b3\u30fc\u30c9\u3067 Hoge \u30af\u30e9\u30b9\u306e\u30e2\u30c3\u30af\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>TestHoge.php<\/p>\n<pre><code class=\"language-php\">&lt;?php\n\nclass TestHoge extends PHPUnit_Framework_TestCase{\n  function testGreet(){\n    $hoge = $this-&gt;getMock('Hoge', array('greet'));\n    $hoge-&gt;expects($this-&gt;once())\n      -&gt;method('greet')\n      -&gt;with('Saitama');\n  }\n}\n<\/code><\/pre>\n<p>5\u884c\u76ee<br \/>\ngetMock \u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3063\u3066\u30e2\u30c3\u30af\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002Hoge \u3068\u3044\u3046\u30af\u30e9\u30b9\u306e greet \u30e1\u30bd\u30c3\u30c9\u306e\u30e2\u30c3\u30af\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>6\u884c\u76ee<br \/>\n\u3053\u306e\u30e2\u30c3\u30af\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c1\u56de\u547c\u3073\u51fa\u3055\u308c\u308b\u3053\u3068\u3092\u30c6\u30b9\u30c8\u3057\u307e\u3059\u3002<\/p>\n<p>7\u884c\u76ee<br \/>\n\u547c\u3073\u51fa\u3055\u308c\u308b\u306e\u306f greet \u30e1\u30bd\u30c3\u30c9\u3067\u3042\u308b\u3053\u3068\u3092\u30c6\u30b9\u30c8\u3057\u307e\u3059\u3002<\/p>\n<p>8\u884c\u76ee<br \/>\n\u5f15\u6570\u3068\u3057\u3066 Saimata \u3068\u3044\u3046\u6587\u5b57\u5217\u304c\u6e21\u3055\u308c\u308b\u3053\u3068\u3092\u30c6\u30b9\u30c8\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u3053\u307e\u3067\u3067\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3057\u3066\u307f\u308b\u3068\u3001\u4e0b\u8a18\u306e\u5b9f\u884c\u7d50\u679c\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre><code>PHPUnit 3.6.10 by Sebastian Bergmann.\n\nF\n\nTime: 0 seconds, Memory: 1.75Mb\n\nThere was 1 failure:\n\n1) TestHoge::testGreet\nExpectation failed for method name is equal to &lt;string:greet&gt; when invoked 1 time(s).\nMethod was expected to be called 1 times, actually called 0 times.\n\n\nFAILURES!\nTests: 1, Assertions: 1, Failures: 1.\n<\/code><\/pre>\n<p>\u30c6\u30b9\u30c8\u306f\u5931\u6557\u3057\u307e\u3059\u3002\u3053\u308c\u306f\u30e2\u30c3\u30af\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e greet \u30e1\u30bd\u30c3\u30c9\u304c 1 \u56de\u547c\u3073\u51fa\u3055\u308c\u308b\u3053\u3068\u3092\u671f\u5f85\u3057\u3066\u3044\u305f\u306e\u306b\u3001\u5b9f\u969b\u306f 1 \u5ea6\u3082\u547c\u3073\u51fa\u3055\u308c\u3066\u3044\u306a\u3044\u304b\u3089\u3067\u3059\u3002\u306a\u306e\u3067\u3001\u3053\u306e\u30c6\u30b9\u30c8\u3092\u6210\u529f\u3055\u305b\u308b\u305f\u3081\u306b\u3001\u30e2\u30c3\u30af\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e greet \u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3059\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>TestHoge.php<\/p>\n<pre><code>&lt;?php\n\nclass TestHoge extends PHPUnit_Framework_TestCase{\n  function testGreet(){\n    $hoge = $this-&gt;getMock('Hoge', array('greet'));\n    $hoge-&gt;expects($this-&gt;once())\n      -&gt;method('greet')\n      -&gt;with('Saitama');\n    $hoge-&gt;greet('Saitama');\n  }\n}\n<\/code><\/pre>\n<p>9 \u884c\u76ee\u306b greet \u30e1\u30bd\u30c3\u30c9\u306b Saimata \u3068\u3044\u3046\u5f15\u6570\u3092\u6e21\u3057\u3066\u5b9f\u884c\u3059\u308b\u30b3\u30fc\u30c9\u3092\u8ffd\u8a18\u3057\u3066\u3044\u307e\u3059\u3002\u3053\u306e\u30c6\u30b9\u30c8\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001\u30c6\u30b9\u30c8\u306f\u6210\u529f\u3057\u307e\u3059\u3002\u3064\u307e\u308a\u30016 \u884c\u76ee\u304b\u3089 8 \u884c\u76ee\u3067\u8a18\u8ff0\u3057\u305f\u52d5\u4f5c\u304c\u3055\u308c\u3066\u3044\u306a\u3044\u3068\u3001PHPUnit \u304c\u6559\u3048\u3066\u304f\u308c\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<\/p>\n<p>\u305f\u3060\u3001\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u5185\u306b\u76f4\u63a5 greet \u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3059\u3088\u3046\u81ea\u5206\u3067\u66f8\u3044\u305f\u306e\u3067\u3059\u304b\u3089\u6210\u529f\u3059\u308b\u306e\u306f\u5f53\u305f\u308a\u524d\u3067\u3059\u306d\u3002\u3053\u306e\u307e\u307e\u3067\u306f\u610f\u5473\u304c\u3042\u308a\u307e\u305b\u3093\u3002\u5f15\u6570\u306b Hoge \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u53d6\u308a\u3001greet \u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3063\u3066\u3044\u308b\u51e6\u7406\u304c\u3042\u308b\u30af\u30e9\u30b9\u3092\u30c6\u30b9\u30c8\u3059\u308b\u5834\u5408\u306b\u3001Hoge \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u4ee3\u308f\u308a\u306b\u30e2\u30c3\u30af\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u6e21\u3057\u3066\u3057\u307e\u3048\u3070\u3001\u3061\u3083\u3093\u3068\u547c\u3073\u51fa\u3057\u3066\u304f\u308c\u3066\u3044\u308b\u306e\u304b\u30c6\u30b9\u30c8\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u3053\u306e\u5834\u5408\u306f\u30e2\u30c3\u30af\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f7f\u3063\u3066\u30c6\u30b9\u30c8\u3092\u3059\u308b\u610f\u5473\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u30e2\u30c3\u30af\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f7f\u3046\u3068\u3001\u76ee\u7684\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u76ee\u7684\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u5fd8\u308c\u3066\u3044\u305f\u308a\u3001\u76ee\u7684\u306e\u30e1\u30bd\u30c3\u30c9\u306b\u8aa4\u3063\u305f\u5f15\u6570\u3092\u6e21\u3057\u3066\u3057\u307e\u3063\u3066\u3044\u305f\u308a\u3059\u308b\u3053\u3068\u3092\u691c\u51fa\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHPUnit \u306e\u30e2\u30c3\u30af\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f7f\u3063\u3066\u3001\u60f3\u5b9a\u3055\u308c\u305f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30e1\u30bd\u30c3\u30c9\u304c\u60f3\u5b9a\u3055\u308c\u305f\u5f15\u6570\u3092\u6e21\u3055\u308c\u3066\u547c\u3070\u308c\u3066\u3044\u308b\u3053\u3068\u3092\u30c6\u30b9\u30c8\u3057\u307e\u3059\u3002\u30e2\u30c3\u30af\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u5177\u4f53\u7684\u306b\u4f55\u306e\u5f79\u306b\u7acb\u3064\u306e\u304b\u30e2\u30e4\u30e2\u30e4\u3057\u3066\u305f\u306e\u3067\u3059\u304c\u3001\u52d5\u304b\u3057\u3066\u307f\u3066\u3084\u3063 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[4,228],"tags":[244,287],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8gd1W-xB","_links":{"self":[{"href":"https:\/\/codaholic.org\/index.php?rest_route=\/wp\/v2\/posts\/2083"}],"collection":[{"href":"https:\/\/codaholic.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codaholic.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codaholic.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codaholic.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2083"}],"version-history":[{"count":22,"href":"https:\/\/codaholic.org\/index.php?rest_route=\/wp\/v2\/posts\/2083\/revisions"}],"predecessor-version":[{"id":2385,"href":"https:\/\/codaholic.org\/index.php?rest_route=\/wp\/v2\/posts\/2083\/revisions\/2385"}],"wp:attachment":[{"href":"https:\/\/codaholic.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2083"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codaholic.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2083"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codaholic.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2083"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}