{"id":46939,"date":"2024-12-02T14:21:33","date_gmt":"2024-12-02T06:21:33","guid":{"rendered":"https:\/\/fwq.ai\/blog\/46939\/"},"modified":"2024-12-02T14:21:33","modified_gmt":"2024-12-02T06:21:33","slug":"php-%e5%87%bd%e6%95%b0%e5%8d%95%e5%85%83%e6%b5%8b%e8%af%95%e4%b8%ad%e7%9a%84%e5%8d%95%e5%85%83%e5%92%8c%e9%9b%86%e6%88%90%e6%b5%8b%e8%af%95%e4%b9%8b%e9%97%b4%e7%9a%84%e5%8c%ba%e5%88%ab","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/46939\/","title":{"rendered":"PHP \u51fd\u6570\u5355\u5143\u6d4b\u8bd5\u4e2d\u7684\u5355\u5143\u548c\u96c6\u6210\u6d4b\u8bd5\u4e4b\u95f4\u7684\u533a\u522b"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u51fd\u6570\u5355\u5143\u6d4b\u8bd5\u4e2d\u7684\u5355\u5143\u548c\u96c6\u6210\u6d4b\u8bd5\u4e4b\u95f4\u7684\u533a\u522b<\/h1>\n<p>\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u52aa\u529b\u5b66\u4e60\u5427\uff01\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPHP \u51fd\u6570\u5355\u5143\u6d4b\u8bd5\u4e2d\u7684\u5355\u5143\u548c\u96c6\u6210\u6d4b\u8bd5\u4e4b\u95f4\u7684\u533a\u522b\u300b<\/span>\u4e3b\u8981\u8bb2\u89e3\u4e86<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6211\u4f1a\u5728\u7c73\u4e91\u4e2d\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u7684\u7cfb\u5217\u6587\u7ae0\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u5e76\u79ef\u6781\u7559\u8a00\u5efa\u8bae\u3002\u4e0b\u9762\u5c31\u5148\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u672c\u7bc7\u6b63\u6587\u5185\u5bb9\u5427\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01<\/p>\n<p>PHP \u5355\u5143\u6d4b\u8bd5\u4e2d\uff0c\u5355\u5143\u6d4b\u8bd5\u548c\u96c6\u6210\u6d4b\u8bd5\u6709\u672c\u8d28\u533a\u522b\uff1a\u5355\u5143\u6d4b\u8bd5\u4ec5\u9488\u5bf9\u5355\u4e2a\u51fd\u6570\uff0c\u4e0e\u5176\u4ed6\u4ee3\u7801\u9694\u79bb\uff0c\u907f\u514d\u4f9d\u8d56\u9879\uff1b\u800c\u96c6\u6210\u6d4b\u8bd5\u5219\u68c0\u67e5\u591a\u4e2a\u7ec4\u4ef6\u7684\u96c6\u6210\uff0c\u6d89\u53ca\u771f\u5b9e\u6216\u6a21\u62df\u7684\u4f9d\u8d56\u9879\uff0c\u7528\u4e8e\u9a8c\u8bc1\u7ec4\u4ef6\u95f4\u4ea4\u4e92\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241025\/1729855601671b8071c42ed.jpg\" class=\"aligncenter\" title=\"PHP \u51fd\u6570\u5355\u5143\u6d4b\u8bd5\u4e2d\u7684\u5355\u5143\u548c\u96c6\u6210\u6d4b\u8bd5\u4e4b\u95f4\u7684\u533a\u522b\u63d2\u56fe\" alt=\"PHP \u51fd\u6570\u5355\u5143\u6d4b\u8bd5\u4e2d\u7684\u5355\u5143\u548c\u96c6\u6210\u6d4b\u8bd5\u4e4b\u95f4\u7684\u533a\u522b\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u5355\u5143\u6d4b\u8bd5\u4e2d\u7684\u5355\u5143\u548c\u96c6\u6210\u6d4b\u8bd5<\/strong><\/p>\n<p>\u5728 PHP \u51fd\u6570\u5355\u5143\u6d4b\u8bd5\u4e2d\uff0c\u5355\u5143\u6d4b\u8bd5\u548c\u96c6\u6210\u6d4b\u8bd5\u4e4b\u95f4\u5b58\u5728\u7740\u6e05\u6670\u7684\u533a\u522b\u3002\u8ba9\u6211\u4eec\u6df1\u5165\u63a2\u8ba8\u4e00\u4e0b\u8fd9\u4e24\u79cd\u7c7b\u578b\u6d4b\u8bd5\u4e4b\u95f4\u7684\u5dee\u5f02\uff1a<\/p>\n<p><strong>\u5355\u5143\u6d4b\u8bd5<\/strong><\/p>\n<ul>\n<li><strong>\u76ee\u7684\uff1a<\/strong>\u68c0\u67e5\u5355\u4e2a\u51fd\u6570\u6216\u5c0f\u90e8\u5206\u4ee3\u7801\u7684\u6b63\u786e\u6027\u3002<\/li>\n<li><strong>\u9694\u79bb\uff1a<\/strong>\u6d4b\u8bd5\u5728\u4e0e\u5176\u4ed6\u4ee3\u7801\u7ec4\u4ef6\u9694\u79bb\u7684\u73af\u5883\u4e2d\u8fdb\u884c\u3002<\/li>\n<li><strong>\u4f5c\u7528\u57df\uff1a<\/strong>\u4ec5\u9488\u5bf9\u88ab\u6d4b\u51fd\u6570\u3002<\/li>\n<li><strong>\u4f9d\u8d56\uff1a<\/strong>\u907f\u514d\u6216\u6a21\u62df\u51fd\u6570\u5916\u90e8\u7684\u4f9d\u8d56\u9879\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>use PHPUnit\\Framework\\TestCase;\n\nclass MathTest extends TestCase\n{\n    public function testAdd()\n    {\n        $this-&gt;assertEquals(5, add(2, 3));\n    }\n}<\/pre>\n<p><strong>\u96c6\u6210\u6d4b\u8bd5<\/strong><\/p>\n<ul>\n<li><strong>\u76ee\u7684\uff1a<\/strong>\u68c0\u67e5\u591a\u4e2a\u51fd\u6570\u6216\u4ee3\u7801\u7ec4\u4ef6\u4e4b\u95f4\u7684\u96c6\u6210\u3002<\/li>\n<li><strong>\u96c6\u6210\uff1a<\/strong>\u6d4b\u8bd5\u5728\u771f\u5b9e\u7684\u6216\u6a21\u62df\u7684\u73af\u5883\u4e2d\u4e0e\u5176\u4ed6\u4ee3\u7801\u7ec4\u4ef6\u96c6\u6210\u3002<\/li>\n<li><strong>\u4f5c\u7528\u57df\uff1a<\/strong>\u68c0\u67e5\u7ec4\u4ef6\u95f4\u4ea4\u4e92\u548c\u4f9d\u8d56\u5173\u7cfb\u3002<\/li>\n<li><strong>\u4f9d\u8d56\uff1a<\/strong>\u771f\u5b9e\u6216\u6a21\u62df\u5916\u90e8\u4f9d\u8d56\u9879\uff08\u5982\u6570\u636e\u5e93\u6216\u6587\u4ef6\u7cfb\u7edf\uff09\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>use PHPUnit\\Framework\\TestCase;\n\nclass OrderServiceTest extends TestCase\n{\n    public function testCreateOrder()\n    {\n        $productRepository = $this-&gt;createMock(ProductRepository::class);\n        $orderService = new OrderService($productRepository);\n\n        $order = $orderService-&gt;createOrder('product-1', 1);\n\n        $this-&gt;assertInstanceOf(Order::class, $order);\n    }\n}<\/pre>\n<p><strong>\u5173\u952e\u533a\u522b<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>\u7279\u5f81<\/th>\n<th>\u5355\u5143\u6d4b\u8bd5<\/th>\n<th>\u96c6\u6210\u6d4b\u8bd5<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u4f5c\u7528\u57df<\/td>\n<td>\u5355\u4e2a\u51fd\u6570<\/td>\n<td>\u591a\u4e2a\u7ec4\u4ef6<\/td>\n<\/tr>\n<tr>\n<td>\u9694\u79bb<\/td>\n<td>\u662f<\/td>\n<td>\u5426<\/td>\n<\/tr>\n<tr>\n<td>\u4f9d\u8d56\u5173\u7cfb<\/td>\n<td>\u6a21\u62df<\/td>\n<td>\u771f\u5b9e\/\u6a21\u62df<\/td>\n<\/tr>\n<tr>\n<td>\u76ee\u7684<\/td>\n<td>\u9a8c\u8bc1\u5355\u4e2a\u51fd\u6570\u7684\u5de5\u4f5c\u65b9\u5f0f<\/td>\n<td>\u9a8c\u8bc1\u7ec4\u4ef6\u95f4\u4ea4\u4e92<\/td>\n<\/tr>\n<tr>\n<td>\u901f\u5ea6<\/td>\n<td>\u66f4\u5feb<\/td>\n<td>\u66f4\u6162<\/td>\n<\/tr>\n<tr>\n<td>\u7ef4\u62a4<\/td>\n<td>\u66f4\u5bb9\u6613<\/td>\n<td>\u66f4\u56f0\u96be<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8e\u6587\u7ae0\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u51fd\u6570\u5355\u5143\u6d4b\u8bd5\u4e2d\u7684\u5355\u5143\u548c\u96c6\u6210\u6d4b\u8bd5\u4e4b\u95f4\u7684\u533a\u522b \u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u52aa\u529b\u5b66\u4e60\u5427\uff01\u672c\u6587\u300aPHP \u51fd\u6570\u5355\u5143\u6d4b\u8bd5\u4e2d\u7684\u5355\u5143\u548c\u96c6\u6210\u6d4b\u8bd5\u4e4b\u95f4\u7684\u533a\u522b\u300b\u4e3b\u8981\u8bb2\u89e3\u4e86\u7b49\u7b49\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6211\u4f1a\u5728\u7c73\u4e91\u4e2d\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u7684\u7cfb\u5217\u6587\u7ae0\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u5e76\u79ef\u6781\u7559\u8a00\u5efa\u8bae\u3002\u4e0b\u9762\u5c31\u5148\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u672c\u7bc7\u6b63\u6587\u5185\u5bb9\u5427\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01 PHP \u5355\u5143\u6d4b\u8bd5\u4e2d\uff0c\u5355\u5143\u6d4b\u8bd5\u548c\u96c6\u6210\u6d4b\u8bd5\u6709\u672c\u8d28\u533a\u522b\uff1a\u5355\u5143\u6d4b\u8bd5\u4ec5\u9488\u5bf9\u5355\u4e2a\u51fd\u6570\uff0c\u4e0e\u5176\u4ed6\u4ee3\u7801\u9694\u79bb\uff0c\u907f\u514d\u4f9d\u8d56\u9879\uff1b\u800c\u96c6\u6210\u6d4b\u8bd5\u5219\u68c0\u67e5\u591a\u4e2a\u7ec4\u4ef6\u7684\u96c6\u6210\uff0c\u6d89\u53ca\u771f\u5b9e\u6216\u6a21\u62df\u7684\u4f9d\u8d56\u9879\uff0c\u7528\u4e8e\u9a8c\u8bc1\u7ec4\u4ef6\u95f4\u4ea4\u4e92\u3002 PHP \u51fd\u6570\u5355\u5143\u6d4b\u8bd5\u4e2d\u7684\u5355\u5143\u548c\u96c6\u6210\u6d4b\u8bd5 \u5728 PHP \u51fd\u6570\u5355\u5143\u6d4b\u8bd5\u4e2d\uff0c\u5355\u5143\u6d4b\u8bd5\u548c\u96c6\u6210\u6d4b\u8bd5\u4e4b\u95f4\u5b58\u5728\u7740\u6e05\u6670\u7684\u533a\u522b\u3002\u8ba9\u6211\u4eec\u6df1\u5165\u63a2\u8ba8\u4e00\u4e0b\u8fd9\u4e24\u79cd\u7c7b\u578b\u6d4b\u8bd5\u4e4b\u95f4\u7684\u5dee\u5f02\uff1a \u5355\u5143\u6d4b\u8bd5 \u76ee\u7684\uff1a\u68c0\u67e5\u5355\u4e2a\u51fd\u6570\u6216\u5c0f\u90e8\u5206\u4ee3\u7801\u7684\u6b63\u786e\u6027\u3002 \u9694\u79bb\uff1a\u6d4b\u8bd5\u5728\u4e0e\u5176\u4ed6\u4ee3\u7801\u7ec4\u4ef6\u9694\u79bb\u7684\u73af\u5883\u4e2d\u8fdb\u884c\u3002 \u4f5c\u7528\u57df\uff1a\u4ec5\u9488\u5bf9\u88ab\u6d4b\u51fd\u6570\u3002 \u4f9d\u8d56\uff1a\u907f\u514d\u6216\u6a21\u62df\u51fd\u6570\u5916\u90e8\u7684\u4f9d\u8d56\u9879\u3002 \u793a\u4f8b\u4ee3\u7801\uff1a use PHPUnit\\Framework\\TestCase; class MathTest extends TestCase { public function testAdd() { $this-&gt;assertEquals(5, add(2, 3)); } } \u96c6\u6210\u6d4b\u8bd5 \u76ee\u7684\uff1a\u68c0\u67e5\u591a\u4e2a\u51fd\u6570\u6216\u4ee3\u7801\u7ec4\u4ef6\u4e4b\u95f4\u7684\u96c6\u6210\u3002 \u96c6\u6210\uff1a\u6d4b\u8bd5\u5728\u771f\u5b9e\u7684\u6216\u6a21\u62df\u7684\u73af\u5883\u4e2d\u4e0e\u5176\u4ed6\u4ee3\u7801\u7ec4\u4ef6\u96c6\u6210\u3002 \u4f5c\u7528\u57df\uff1a\u68c0\u67e5\u7ec4\u4ef6\u95f4\u4ea4\u4e92\u548c\u4f9d\u8d56\u5173\u7cfb\u3002 \u4f9d\u8d56\uff1a\u771f\u5b9e\u6216\u6a21\u62df\u5916\u90e8\u4f9d\u8d56\u9879\uff08\u5982\u6570\u636e\u5e93\u6216\u6587\u4ef6\u7cfb\u7edf\uff09\u3002 \u793a\u4f8b\u4ee3\u7801\uff1a use PHPUnit\\Framework\\TestCase; class OrderServiceTest extends TestCase { public function testCreateOrder() { $productRepository = $this-&gt;createMock(ProductRepository::class); $orderService = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-46939","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/46939","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=46939"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/46939\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=46939"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=46939"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=46939"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}