{"id":4061,"date":"2022-01-09T09:19:17","date_gmt":"2022-01-09T00:19:17","guid":{"rendered":"https:\/\/www.wetch.co.jp\/?p=4061"},"modified":"2022-02-24T14:48:27","modified_gmt":"2022-02-24T05:48:27","slug":"laravel%ef%bc%9amock%e3%81%ab%e3%81%8a%e3%81%91%e3%82%8b%e5%bc%95%e6%95%b0%e3%81%a8%e6%88%bb%e3%82%8a%e5%80%a4%e3%81%ae%e9%96%a2%e4%bf%82","status":"publish","type":"post","link":"https:\/\/www.wetch.co.jp\/note\/laravel%ef%bc%9amock%e3%81%ab%e3%81%8a%e3%81%91%e3%82%8b%e5%bc%95%e6%95%b0%e3%81%a8%e6%88%bb%e3%82%8a%e5%80%a4%e3%81%ae%e9%96%a2%e4%bf%82\/","title":{"rendered":"Laravel\uff1amock\u306b\u304a\u3051\u308b\u5f15\u6570\u3068\u623b\u308a\u5024\u306e\u95a2\u4fc2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u9045\u307e\u304d\u306a\u304c\u3089\u65b0\u5e74\u660e\u3051\u307e\u3057\u3066\u304a\u3081\u3067\u3068\u3046\u3054\u3056\u3044\u307e\u3059\u3002<br>\u6628\u5e74\u306b\u5f15\u304d\u7d9a\u304d\u3001\u4eca\u5e74\u3082\u6bce\u9031\u65e5\u66dc\u306e\u6295\u7a3f\u3092\u5fc3\u304c\u3051\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\uff08\u3068\u8a00\u3044\u3064\u30641\u67082\u65e5\u306f\u3044\u304d\u306a\u308a\u30b5\u30dc\u308a\u307e\u3057\u305f\u304c\uff09\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6628\u5e74\u306e\u6700\u521d\u306e\u6295\u7a3f\u3082\u30c6\u30b9\u30c8\u95a2\u9023\u3067\u3057\u305f\u304c\u3001\u4eca\u5e74\u3082\u300c\u30c6\u30b9\u30c8\u30d5\u30a1\u30fc\u30b9\u30c8\u300d\u3068\u8a00\u3046\u3053\u3068\u3067\u30c6\u30b9\u30c8\u306e\u8a71\u984c\u304b\u3089\u3002<br>Laravel\u306emock\u6a5f\u80fd\u306b\u95a2\u3057\u3066\u3067\u3059\u304c\u3001\u4fbf\u5229\u306a\u6a5f\u80fd\u3067\u306f\u3042\u308b\u306e\u3067\u3059\u304c\u610f\u5916\u306b\u307e\u3068\u307e\u3063\u305f\u89e3\u8aac\u304c\u5c11\u306a\u304f\u3001\u5c11\u3057\u60a9\u3093\u3060\u30cd\u30bf\u306a\u306e\u3067\u8a18\u4e8b\u306b\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u307e\u305a\u306f\u57fa\u672c\u5f62<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u51e6\u7406\u3092\u691c\u8a3c\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\nnamespace App\\Services\\Sample;\n\nclass Test1Service\n{\n    public function __invoke(array $serviceInput)\n    {\n        $Test1Repository = app()-&gt;make(\\App\\Repositories\\Test1Repository::class);\n\n        $resultObj = new \\stdClass;\n        $resultObj-&gt;result1 = $Test1Repository(1);\n        return $resultObj;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u8a18\u3067\u623b\u3057\u305f\u300cstdClass\u300d\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306e\u5185\u5bb9\u306b\u5f93\u3063\u3066API\u306e\u623b\u308a\u30c7\u30fc\u30bf\uff08JSON\uff09\u3092\u6574\u5f62\u3057\u307e\u3059\u304c\u3001\u305d\u306e\u8fba\u306f\u91cd\u8981\u3067\u306f\u306a\u3044\u306e\u3067\u5272\u611b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u8a18\u306b\u5bfe\u3057\u3066\u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    \/**\n     * @test\n     *\/\n    public function Sample_Test1Controller_\u57fa\u672c() : void\n    {\n        $this-&gt;mock(\\App\\Repositories\\Test1Repository::class, function($mock) {\n            $mock-&gt;shouldReceive('__invoke')-&gt;with(1)-&gt;andReturn(10);\n        });        \n\n        \/\/ \u5b9f\u884c\n        $response = $this-&gt;get(route('sample.test1'));\n\n        \/\/ \u78ba\u8a8d\n        $response-&gt;assertStatus(200);\n        $expected = &#91;\n            'data' =&gt; &#91;\n                'result1' =&gt; 10,\n            ],\n        ];\n        $response-&gt;assertExactJson($expected);\n    }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u30af\u30e9\u30b9\u300c<meta charset=\"utf-8\">\\App\\Repositories\\Test1Repository\u300d\u306e\u6319\u52d5\u3092mock\u3067\u4ee3\u66ff\u3057\u3088\u3046\u3068\u3057\u3066\u3044\u308b\u8a33\u3067\u3059\u3002<br>\u540c\u30af\u30e9\u30b9\u306f1\u3092\u5165\u529b\u3059\u308b\u306810\u3092\u8fd4\u3059\u6a5f\u80fd\u3092\u6709\u3057\u3066\u3044\u308b\u3053\u3068\u304c\u671f\u5f85\u3055\u308c\u3066\u304a\u308a\u3001\u305d\u308c\u3092\u30c6\u30b9\u30c8\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u30dd\u30a4\u30f3\u30c8\u306f\u30e1\u30bd\u30c3\u30c9\u300cwith\u300d\u3067\u3059\u3002<br>mock\u306e\u4f8b\u3068\u3057\u3066\u306f\u7f6e\u63db\u5bfe\u8c61\u30e1\u30bd\u30c3\u30c9\u3092\u6307\u5b9a\u3059\u308b\u300c<meta charset=\"utf-8\">shouldReceive\u300d\u3084\u623b\u308a\u5024\u3092\u6307\u5b9a\u3059\u308b\u300c<meta charset=\"utf-8\">andReturn\u300d\u306b\u95a2\u3057\u3066\u66f8\u304b\u308c\u305f\u3082\u306e\u306f\u3088\u304f\u898b\u304b\u3051\u308b\u306e\u3067\u3059\u304c\uff08\u305d\u3082\u305d\u3082\u3053\u306e2\u3064\u304c\u7279\u5b9a\u3067\u304d\u306a\u3044\u3068\u30c6\u30b9\u30c8\u81ea\u4f53\u304c\u3067\u304d\u306a\u3044\u306e\u3067\u3059\u304c\uff09\u3001\u5f15\u6570\u306e\u78ba\u8a8d\u306b\u95a2\u3057\u3066\u8a00\u53ca\u3057\u3066\u3044\u308b\u8a18\u4e8b\u306f\u5272\u3068\u5c11\u306a\u3044\u5370\u8c61\u3067\u3059\u3002<br>\u3068\u8a00\u3046\u3053\u3068\u3067\u3001\u300cwith\u300d\u3067\u306f\u5f15\u6570\u3068\u3057\u3066\u5165\u529b\u3055\u308c\u308b\u3053\u3068\u304c\u60f3\u5b9a\u3055\u308c\u308b\u5024\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u3053\u306e\u3088\u3046\u306b\u6307\u5b9a\u3057\u3066\u304a\u304f\u3068\u5f15\u6570\u304c\u4e0d\u4e00\u81f4\u306e\u5834\u5408\u306f\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f62\u7684\u306b\u3082\u3001\u3069\u306e\u30e1\u30bd\u30c3\u30c9\u306b\u5bfe\u3057\u3066\u3001\u4f55\u3092\u5165\u529b\u3057\u3001\u4f55\u304c\u51fa\u529b\u3055\u308c\u308b\u304b\u3001\u3068\u8a00\u3046\u3053\u3068\u304c\u63c3\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u30d0\u30e9\u30f3\u30b9\u304c\u826f\u3044\u5370\u8c61\u3067\u3059\u3002<br>\u7a4d\u6975\u7684\u306b\u300cwith\u300d\u306f\u6307\u5b9a\u3057\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u540c\u3058\u30af\u30e9\u30b9\u30fb\u30e1\u30bd\u30c3\u30c9\u306e\u8907\u6570\u547c\u3073\u51fa\u3057<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u8a18\u300c<meta charset=\"utf-8\">Test1Service\u300d\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><meta charset=\"utf-8\">&lt;?php\n\nnamespace App\\Services\\Sample;\n\nclass Test1Service\n{\n    public function __invoke(array $serviceInput)\n    {\n        $Test1Repository = app()-&gt;make(\\App\\Repositories\\Test1Repository::class);\n\n        $resultObj = new \\stdClass;\n        $resultObj-&gt;result1 = $Test1Repository(1);\n<meta charset=\"utf-8\">        $resultObj-&gt;result2 = $Test1Repository(1);\n        return $resultObj;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u8a18\u306b\u5bfe\u3057\u3066\u4ee5\u4e0b\u306e\u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\u306f\u6210\u7acb\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><meta charset=\"utf-8\">    \/**\n     * @test\n     *\/\n    public function Sample_Test1Controller_\u57fa\u672c() : void\n    {\n        $this-&gt;mock(\\App\\Repositories\\Test1Repository::class, function($mock) {\n            $mock-&gt;shouldReceive('__invoke')-&gt;with(1)-&gt;andReturn(10);\n        });        \n\n        \/\/ \u5b9f\u884c\n        $response = $this-&gt;get(route('sample.test1'));\n\n        \/\/ \u78ba\u8a8d\n        $response-&gt;assertStatus(200);\n        $expected = &#91;\n            'data' =&gt; &#91;\n                'result1' =&gt; 10,\n<meta charset=\"utf-8\">                'result2' =&gt; 10,\n            ],\n        ];\n        $response-&gt;assertExactJson($expected);\n    }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u306f\u3001mock\u306e\u8a2d\u5b9a\u306b\u304a\u3044\u3066\u7279\u5b9a\u306e\u30e1\u30bd\u30c3\u30c9\u306b\u5bfe\u3057\u3066\u7279\u5b9a\u306e\u5f15\u6570\u304c\u4e0e\u3048\u3089\u308c\u305f\u5834\u5408\u306b\u7279\u5b9a\u306e\u5024\u3092\u8fd4\u3059\u3068\u8a00\u3046\u4ed5\u7d44\u307f\u306f\u3001\u57fa\u672c\u7684\u306b\u306f\u56de\u6570\u6307\u5b9a\u306a\u3057\u3067\u6a5f\u80fd\u3059\u308b\u3068\u8a00\u3046\u3053\u3068\u3067\u3059\u3002<br>\u9006\u306b\u3001\u4e00\u5ea6\u3057\u304b\u5b9f\u884c\u3055\u308c\u306a\u3044\u3053\u3068\u304c\u60f3\u5b9a\u3055\u308c\u308b\u5834\u5408\u306f\u300conce\u300d\u30e1\u30bd\u30c3\u30c9\u306e\u547c\u3073\u51fa\u3057\u3092\u4ed8\u52a0\u3059\u308b\u3053\u3068\u3067\u3001\u8907\u6570\u56de\u547c\u3073\u51fa\u3055\u308c\u305f\u5834\u5408\u306f\u30a8\u30e9\u30fc\u306b\u306a\u308b\u3088\u3046\u306b\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><meta charset=\"utf-8\">$mock-&gt;shouldReceive('__invoke')-&gt;with(1)-&gt;andReturn(10)-&gt;once();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u3067\u306f\u3001\u540c\u3058\u30e1\u30bd\u30c3\u30c9\u306b\u5bfe\u3057\u3066\u5f15\u6570\u3092\u5909\u3048\u306a\u304c\u3089\u8907\u6570\u56de\u547c\u3073\u51fa\u3057\u3092\u884c\u3046\u5834\u5408\u306f\u3069\u3046\u3059\u308c\u3070\u826f\u3044\u3067\u3057\u3087\u3046\uff1f<br>\u5b9f\u306f\u7c21\u5358\u3067\u3001\u540c\u3058\u30e1\u30bd\u30c3\u30c9\u3092\u6307\u5b9a\u3057\u3064\u3064\u3001\u7570\u306a\u308b\u5f15\u6570\u3068\u623b\u308a\u5024\u306e\u7d44\u307f\u5408\u308f\u305b\u3092\u7f85\u5217\u3059\u308c\u3070\u826f\u3044\u3060\u3051\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><meta charset=\"utf-8\">\u300c<meta charset=\"utf-8\">Test1Service\u300d\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><meta charset=\"utf-8\">&lt;?php\n\nnamespace App\\Services\\Sample;\n\nclass Test1Service\n{\n    public function __invoke(array $serviceInput)\n    {\n        $Test1Repository = app()-&gt;make(\\App\\Repositories\\Test1Repository::class);\n\n        $resultObj = new \\stdClass;\n        $resultObj-&gt;result1 = $Test1Repository(1);\n<meta charset=\"utf-8\">        $resultObj-&gt;result2 = $Test1Repository(2);\n        return $resultObj;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u3053\u308c\u306b\u5bfe\u3057\u3066\u3001\u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><meta charset=\"utf-8\">    \/**\n     * @test\n     *\/\n    public function Sample_Test1Controller_\u57fa\u672c() : void\n    {\n        $this-&gt;mock(\\App\\Repositories\\Test1Repository::class, function($mock) {\n            $mock-&gt;shouldReceive('__invoke')-&gt;with(1)-&gt;andReturn(10);\n<meta charset=\"utf-8\">            $mock-&gt;shouldReceive('__invoke')-&gt;with(2)-&gt;andReturn(200);\n        });        \n\n        \/\/ \u5b9f\u884c\n        $response = $this-&gt;get(route('sample.test1'));\n\n        \/\/ \u78ba\u8a8d\n        $response-&gt;assertStatus(200);\n        $expected = &#91;\n            'data' =&gt; &#91;\n                'result1' =&gt; 10,\n<meta charset=\"utf-8\">                'result2' =&gt; 200,\n            ],\n        ];\n        $response-&gt;assertExactJson($expected);\n    }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f15\u6570\u304c1\u306e\u5834\u5408\u306f10\u3092\u8fd4\u3057\u30012\u306e\u5834\u5408\u306f200\u3092\u8fd4\u3059\u51e6\u7406\u3092\u60f3\u5b9a\u3057\u305f\u30c6\u30b9\u30c8\u304c\u5b9f\u65bd\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u306a\u304a\u3001\u5f15\u6570\u3068\u623b\u308a\u5024\u306e\u7d44\u307f\u5408\u308f\u305b\u306e\u6307\u5b9a\u306e\u9806\u5e8f\u306f\u5b9f\u969b\u306e\u51e6\u7406\u306b\u304a\u3051\u308b\u547c\u3073\u51fa\u3057\u9806\u5e8f\u3068\u306f\u7121\u95a2\u4fc2\u3067\u3059\u3002<br>\u4e0a\u8a18\u4f8b\u3067\u8a00\u3048\u3070\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u6307\u5b9a\u306e\u9806\u5e8f\u3092\u9006\u8ee2\u3055\u305b\u3066\u3082\u554f\u984c\u306a\u304f\u52d5\u4f5c\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$mock-&gt;shouldReceive('__invoke')-&gt;with(2)-&gt;andReturn(200);\n$mock-&gt;shouldReceive('__invoke')-&gt;with(1)-&gt;andReturn(10);<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u540c\u3058\u5f15\u6570\u3067\u306e\u8907\u6570\u547c\u3073\u51fa\u3057\u306b\u5bfe\u3057\u3066\u623b\u308a\u5024\u3092\u5909\u3048\u305f\u3044\u5834\u5408<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u305d\u306e\u3088\u3046\u306a\u30b1\u30fc\u30b9\u304c\u5b58\u5728\u3059\u308b\u304b\u3069\u3046\u304b\u5206\u304b\u308a\u307e\u305b\u3093\u304c\u3001\u540c\u4e00\u30af\u30e9\u30b9\u30fb\u30e1\u30bd\u30c3\u30c9\u306b\u5bfe\u3057\u3066\u540c\u3058\u5f15\u6570\u3067\u8907\u6570\u56de\u547c\u3073\u51fa\u3057\u3064\u3064\u3001\u305d\u306e\u90fd\u5ea6\u623b\u308a\u5024\u3092\u5909\u3048\u305f\u3044\u30b1\u30fc\u30b9\u3082\u8a66\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><meta charset=\"utf-8\">\u300c<meta charset=\"utf-8\">Test1Service\u300d\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><meta charset=\"utf-8\">&lt;?php\n\nnamespace App\\Services\\Sample;\n\nclass Test1Service\n{\n    public function __invoke(array $serviceInput)\n    {\n        $Test1Repository = app()-&gt;make(\\App\\Repositories\\Test1Repository::class);\n\n        $resultObj = new \\stdClass;\n        $resultObj-&gt;result1 = $Test1Repository(1);\n<meta charset=\"utf-8\">        $resultObj-&gt;result2 = $Test1Repository(1);\n        return $resultObj;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2\u56de\u3068\u3082\u5f15\u6570\u306f1\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3053\u308c\u306b\u5bfe\u3057\u3066\u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><meta charset=\"utf-8\">    \/**\n     * @test\n     *\/\n    public function Sample_Test1Controller_\u57fa\u672c() : void\n    {\n        $this-&gt;mock(\\App\\Repositories\\Test1Repository::class, function($mock) {\n            $mock-&gt;shouldReceive('__invoke')-&gt;with(1)-&gt;andReturn(10)-&gt;once();\n<meta charset=\"utf-8\">            $mock-&gt;shouldReceive('__invoke')-&gt;with(1)-&gt;andReturn(200)-&gt;once();\n        });        \n\n        \/\/ \u5b9f\u884c\n        $response = $this-&gt;get(route('sample.test1'));\n\n        \/\/ \u78ba\u8a8d\n        $response-&gt;assertStatus(200);\n        $expected = &#91;\n            'data' =&gt; &#91;\n                'result1' =&gt; 10,\n<meta charset=\"utf-8\">                'result2' =&gt; 200,\n            ],\n        ];\n        $response-&gt;assertExactJson($expected);\n    }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u30dd\u30a4\u30f3\u30c8\u306f\u300conce\u300d\u30e1\u30bd\u30c3\u30c9\u3092\u5229\u7528\u3059\u308b\u70b9\u3067\u3059\u3002\u3053\u308c\u3092\u884c\u308f\u306a\u3044\u3068\u3001\u8907\u6570\u56de\u547c\u3073\u51fa\u3057\u306b\u5bfe\u3057\u3066\u5e38\u306b\u6700\u521d\u306e\u8a2d\u5b9a\u304c\u6709\u52b9\u306b\u306a\u3063\u3066\u3057\u307e\u3046\u305f\u3081\u3001200\u3092\u623b\u3059\u51e6\u7406\u306f\u5b9f\u884c\u3055\u308c\u307e\u305b\u3093\u3002\u8a00\u3044\u63db\u3048\u308c\u3070\u3001\u4e0a\u8a18\u306e\u3088\u3046\u306b\u300conce\u300d\u30e1\u30bd\u30c3\u30c9\u3067\u5b9f\u884c\u56de\u6570\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u30672\u56de\u76ee\u306e\u547c\u3073\u51fa\u3057\u306b\u95a2\u3057\u3066\u306f200\u3092\u623b\u3059\u65b9\u306e\u51e6\u7406\u304c\u6709\u52b9\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53\u7136\u306a\u304c\u3089\u3001\u3053\u306e\u30b1\u30fc\u30b9\u3067\u306f\u5f15\u6570\u3068\u623b\u308a\u5024\u306e\u7d44\u307f\u5408\u308f\u305b\u9806\u5e8f\u304c\u91cd\u8981\u306b\u306a\u308a\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u9806\u5e8f\u3092\u9006\u8ee2\u3055\u305b\u3066\u3057\u307e\u3046\u3068\u671f\u5f85\u3057\u305f\u7d50\u679c\u304c\u5f97\u3089\u308c\u307e\u305b\u3093\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$mock-&gt;shouldReceive('__invoke')-&gt;with(1)-&gt;andReturn(200)-&gt;once();\n$mock-&gt;shouldReceive('__invoke')-&gt;with(1)-&gt;andReturn(10)-&gt;once();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u3055\u3089\u306b\u306f\u300conce\u300d\u30e1\u30bd\u30c3\u30c9\u6307\u5b9a\u306e\u7279\u6027\u306b\u3088\u308a\u3001\u540c\u3058\u5f15\u6570\u30fb\u623b\u308a\u5024\u306e\u7d44\u307f\u5408\u308f\u305b\u3092\u8907\u6570\u4f7f\u7528\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><meta charset=\"utf-8\">\u300c<meta charset=\"utf-8\">Test1Service\u300d\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><meta charset=\"utf-8\">&lt;?php\n\nnamespace App\\Services\\Sample;\n\nclass Test1Service\n{\n    public function __invoke(array $serviceInput)\n    {\n        $Test1Repository = app()-&gt;make(\\App\\Repositories\\Test1Repository::class);\n\n        $resultObj = new \\stdClass;\n        $resultObj-&gt;result1 = $Test1Repository(1);\n<meta charset=\"utf-8\">        $resultObj-&gt;result2 = $Test1Repository(1);\n<meta charset=\"utf-8\">        $resultObj-&gt;result3 = $Test1Repository(1);\n        return $resultObj;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u300c<meta charset=\"utf-8\">Test1Repository\u300d\u306e\u547c\u3073\u51fa\u3057\u30921\u3064\u5897\u3084\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><meta charset=\"utf-8\">    \/**\n     * @test\n     *\/\n    public function Sample_Test1Controller_\u57fa\u672c() : void\n    {\n        $this-&gt;mock(\\App\\Repositories\\Test1Repository::class, function($mock) {\n            $mock-&gt;shouldReceive('__invoke')-&gt;with(1)-&gt;andReturn(10)-&gt;once();\n<meta charset=\"utf-8\">            $mock-&gt;shouldReceive('__invoke')-&gt;with(1)-&gt;andReturn(200)-&gt;once();\n<meta charset=\"utf-8\">            $mock-&gt;shouldReceive('__invoke')-&gt;with(1)-&gt;andReturn(10)-&gt;once();\n        });        \n\n        \/\/ \u5b9f\u884c\n        $response = $this-&gt;get(route('sample.test1'));\n\n        \/\/ \u78ba\u8a8d\n        $response-&gt;assertStatus(200);\n        $expected = &#91;\n            'data' =&gt; &#91;\n                'result1' =&gt; 10,\n<meta charset=\"utf-8\">                'result2' =&gt; 200,\n<meta charset=\"utf-8\">                'result3' =&gt; 10,\n            ],\n        ];\n        $response-&gt;assertExactJson($expected);\n    }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f15\u65701\u3092\u6e21\u3057\u3066\u623b\u308a\u502410\u3092\u5f97\u308b\u51e6\u7406\u304c\u3001\u5f15\u65701\u3092\u6e21\u3057\u3066\u623b\u308a\u5024200\u3092\u5f97\u308b\u51e6\u7406\u3092\u631f\u3093\u30672\u56de\u5b9f\u884c\u3055\u308c\u308b\u3053\u3068\u3092\u60f3\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<br>\u3053\u306e\u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\u306f\u6b63\u5e38\u306b\u52d5\u4f5c\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3064\u307e\u308a\u306f\u300conce\u300d\u6307\u5b9a\u3057\u305f\u30e1\u30bd\u30c3\u30c9\u306f\u305d\u306e\u5f15\u6570\u3068\u623b\u308a\u5024\u306e\u7d44\u307f\u5408\u308f\u305b\u304c\u8a2d\u5b9a\u9806\u306b\u8a18\u9332\u3055\u308c\u3001\u5b9f\u884c\u6642\u306b\u306f\u305d\u306e\u9806\u5e8f\u3067\u7167\u5408\u3055\u308c\u308b\u3068\u8a00\u3046\u3053\u3068\u306e\u3088\u3046\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3053\u306e\u65b9\u5f0f\u304c\u63a1\u7528\u3067\u304d\u308b\u306e\u3067\u3042\u308c\u3070\u3001\u30c6\u30b9\u30c8\u306e\u67d4\u8edf\u6027\u304c\u304b\u306a\u308a\u5411\u4e0a\u3057\u307e\u3059\u306d\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u7dcf\u62ec<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u7d50\u679c\u3060\u3051\u898b\u308b\u3068\u5225\u6bb5\u7279\u6b8a\u6027\u306f\u306a\u3044\u3088\u3046\u306b\u601d\u3044\u307e\u3059\u304c\u3001\u540c\u3058\u30af\u30e9\u30b9\u30fb\u30e1\u30bd\u30c3\u30c9\u306b\u5bfe\u3057\u3066\u5f15\u6570\u3068\u623b\u308a\u5024\u306e\u7d44\u307f\u5408\u308f\u305b\u3092\u8907\u6570\u6307\u5b9a\u3067\u304d\u308b\u3068\u8a00\u3046\u767a\u60f3\u306b\u81f3\u308b\u307e\u3067\u306b\u5c11\u3005\u624b\u9593\u53d6\u308a\u307e\u3057\u305f\u306e\u3067\u3001\u5099\u5fd8\u9332\u7684\u306b\u60c5\u5831\u3092\u6b8b\u3057\u3066\u304a\u304f\u610f\u5473\u3082\u542b\u3081\u3066\u7d39\u4ecb\u3055\u305b\u3066\u3044\u305f\u3060\u304d\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7279\u306b\u540c\u3058\u5f15\u6570\u30fb\u623b\u308a\u5024\u306e\u7d44\u307f\u5408\u308f\u305b\u3092\u8907\u6570\u56de\u6307\u5b9a\u3067\u304d\u308b\u306e\u306f\u500b\u4eba\u7684\u306b\u306f\u304b\u306a\u308a\u610f\u5916\u3067\u3001\u6539\u3081\u3066Laravel\u3063\u3066\u8272\u3005\u3068\u3067\u304d\u308b\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3060\u3068\u5b9f\u611f\u3057\u307e\u3057\u305f\uff08\u3053\u306e\u5834\u5408\u306fMockery\u304c\u512a\u79c0\u3068\u8a00\u3046\u3053\u3068\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\uff09\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">mock\u6a5f\u80fd\u3092\u4f7f\u3044\u3053\u306a\u305b\u308b\u3053\u3068\u3068\u30c6\u30b9\u30c8\u306e\u52b9\u7387\u306f\u975e\u5e38\u306b\u95a2\u4fc2\u304c\u6df1\u3044\uff08\u3068\u601d\u3063\u3066\u3044\u308b\uff09\u306e\u3067\u3001\u4eca\u5f8c\u3082\u7cbe\u9032\u3057\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9045\u307e\u304d\u306a\u304c\u3089\u65b0\u5e74\u660e\u3051\u307e\u3057\u3066\u304a\u3081\u3067\u3068\u3046\u3054\u3056\u3044\u307e\u3059\u3002\u6628\u5e74\u306b\u5f15\u304d\u7d9a\u304d\u3001\u4eca\u5e74\u3082\u6bce\u9031\u65e5\u66dc\u306e\u6295\u7a3f\u3092\u5fc3\u304c\u3051\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\uff08\u3068\u8a00\u3044\u3064\u30641\u67082\u65e5\u306f\u3044\u304d\u306a\u308a\u30b5\u30dc\u308a\u307e\u3057\u305f\u304c\uff09\u3002 \u6628\u5e74\u306e\u6700\u521d\u306e\u6295\u7a3f\u3082\u30c6\u30b9\u30c8\u95a2\u9023\u3067\u3057\u305f\u304c\u3001\u4eca\u5e74\u3082\u300c\u30c6\u30b9\u30c8\u30d5\u30a1\u30fc [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":4443,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_wp_rev_ctl_limit":""},"categories":[210],"tags":[],"class_list":["post-4061","post","type-post","status-publish","format-standard","has-post-thumbnail","category-210"],"_links":{"self":[{"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/posts\/4061","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/comments?post=4061"}],"version-history":[{"count":0,"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/posts\/4061\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/media\/4443"}],"wp:attachment":[{"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/media?parent=4061"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/categories?post=4061"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wetch.co.jp\/note\/wp-json\/wp\/v2\/tags?post=4061"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}