{"id":47734,"date":"2024-12-02T16:24:23","date_gmt":"2024-12-02T08:24:23","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47734\/"},"modified":"2024-12-02T16:24:23","modified_gmt":"2024-12-02T08:24:23","slug":"phpstorm-%e4%b8%ad%e7%9a%84-php-%e5%87%bd%e6%95%b0%e4%bb%a3%e7%a0%81%e8%a6%86%e7%9b%96%e7%8e%87","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47734\/","title":{"rendered":"PHPStorm \u4e2d\u7684 PHP \u51fd\u6570\u4ee3\u7801\u8986\u76d6\u7387"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHPStorm \u4e2d\u7684 PHP \u51fd\u6570\u4ee3\u7801\u8986\u76d6\u7387<\/h1>\n<p>\u4f60\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u7684\u77e5\u8bc6\u5417\uff1f\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPHPStorm \u4e2d\u7684 PHP \u51fd\u6570\u4ee3\u7801\u8986\u76d6\u7387\u300b<\/span>\uff0c\u4e3b\u8981\u4ecb\u7ecd\u7684\u5185\u5bb9\u5c31\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u5982\u679c\u4f60\u60f3\u63d0\u5347\u81ea\u5df1\u7684\u5f00\u53d1\u80fd\u529b\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0\uff0c\u5927\u5bb6\u8981\u77e5\u9053\u7f16\u7a0b\u7406\u8bba\u57fa\u7840\u548c\u5b9e\u6218\u64cd\u4f5c\u90fd\u662f\u4e0d\u53ef\u6216\u7f3a\u7684\u54e6\uff01<\/p>\n<p>\u5728 PHPStorm \u4e2d\uff0c\u4f7f\u7528 Xdebug \u8ba1\u7b97\u51fd\u6570\u4ee3\u7801\u8986\u76d6\u7387\uff1a1. \u5b89\u88c5\u548c\u914d\u7f6e Xdebug \u6269\u5c55\uff1b2. \u8fd0\u884c\u6d4b\u8bd5\uff1b3. \u67e5\u770b\u8986\u76d6\u7387\u62a5\u544a\uff0c\u663e\u793a\u6bcf\u4e2a\u51fd\u6570\u7684\u8986\u76d6\u7387\u3001\u672a\u8986\u76d6\u4ee3\u7801\u884c\u548c\u8fd0\u884c\u65f6\u5f02\u5e38\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729932989671caebdd1748.jpg\" class=\"aligncenter\" title=\"PHPStorm \u4e2d\u7684 PHP \u51fd\u6570\u4ee3\u7801\u8986\u76d6\u7387\u63d2\u56fe\" alt=\"PHPStorm \u4e2d\u7684 PHP \u51fd\u6570\u4ee3\u7801\u8986\u76d6\u7387\u63d2\u56fe\" \/><\/p>\n<p><strong>PHPStorm \u4e2d\u7684 PHP \u51fd\u6570\u4ee3\u7801\u8986\u76d6\u7387<\/strong><\/p>\n<p><strong>\u7b80\u4ecb<\/strong><\/p>\n<p>\u4ee3\u7801\u8986\u76d6\u7387\u662f\u6d4b\u91cf\u5728\u6d4b\u8bd5\u6267\u884c\u671f\u95f4\u8fd0\u884c\u4e86\u591a\u5c11\u4ee3\u7801\u7684\u6307\u6807\u3002\u5728 PHPStorm \u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 Xdebug \u5206\u6790\u5668\u8ba1\u7b97\u51fd\u6570\u7684\u4ee3\u7801\u8986\u76d6\u7387\u3002<\/p>\n<p><strong>\u5b89\u88c5\u548c\u914d\u7f6e<\/strong><\/p>\n<ol>\n<li>\u5b89\u88c5 Xdebug \u6269\u5c55\u3002\u6709\u5173\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605 Xdebug \u6587\u6863\u3002<\/li>\n<li>\u5728 PHPStorm \u4e2d\uff0c\u5728 &#8220;PHP&#8221; \u4e0b\u7684 &#8220;Settings&#8221; \u4e2d\u542f\u7528 &#8220;Xdebug&#8221;\u3002<\/li>\n<li>\u6253\u5f00 &#8220;Coverage&#8221; \u9009\u9879\u5361\u5e76\u914d\u7f6e\u4ee5\u4e0b\u8bbe\u7f6e\uff1a<\/li>\n<\/ol>\n<pre>Coverage server: localhost\nCoverage port: 9000<\/pre>\n<p><strong>\u8fd0\u884c\u6d4b\u8bd5<\/strong><\/p>\n<p>\u4f7f\u7528\u60a8\u559c\u6b22\u7684\u6d4b\u8bd5\u6846\u67b6\uff08\u5982 PHPUnit\uff09\u8fd0\u884c\u6d4b\u8bd5\u3002\u786e\u4fdd Xdebug \u6269\u5c55\u5df2\u542f\u7528\u5e76\u4e14 PHPUnit \u4e0e Xdebug \u517c\u5bb9\u3002<\/p>\n<p><strong>\u67e5\u770b\u8986\u76d6\u7387\u62a5\u544a<\/strong><\/p>\n<p>\u6d4b\u8bd5\u8fd0\u884c\u5b8c\u6210\u540e\uff0c\u5728 PHPStorm \u4e2d\u6253\u5f00 &#8220;Coverage&#8221; \u5de5\u5177\u7a97\u53e3\u3002\u60a8\u53ef\u4ee5\u67e5\u770b\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<ul>\n<li>\u6309\u51fd\u6570\u5206\u5217\u7684\u8986\u76d6\u7387\u62a5\u544a<\/li>\n<li>\u7a81\u51fa\u663e\u793a\u672a\u8986\u76d6\u4ee3\u7801\u7684\u884c<\/li>\n<li>\u8fd0\u884c\u65f6\u5f02\u5e38\u548c\u65e5\u5fd7\u8bb0\u5f55<\/li>\n<\/ul>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u8003\u8651\u4ee5\u4e0b PHP \u51fd\u6570\uff1a<\/p>\n<pre>function addNumbers(int $a, int $b)\n{\n    return $a + $b;\n}<\/pre>\n<p>\u8981\u6d4b\u8bd5\u8986\u76d6\u7387\uff0c\u8bf7\u4f7f\u7528 PHPUnit \u521b\u5efa\u6d4b\u8bd5\u7528\u4f8b\uff1a<\/p>\n<pre>namespace Tests;\n\nuse PHPUnit\\Framework\\TestCase;\n\nclass AddNumbersTest extends TestCase\n{\n    public function testAddNumbers()\n    {\n        $result = addNumbers(2, 3);\n        $this-&gt;assertEquals(5, $result);\n    }\n}<\/pre>\n<p>\u8fd0\u884c\u6d4b\u8bd5\u540e\uff0c\u60a8\u53ef\u4ee5\u5728 PHPStorm \u4e2d\u67e5\u770b\u8986\u76d6\u7387\u62a5\u544a\u3002\u5b83\u5c06\u663e\u793a <code>addNumbers<\/code> \u51fd\u6570\u88ab\u5b8c\u5168\u8986\u76d6\uff0c\u56e0\u4e3a PHPUnit \u6d4b\u8bd5\u7528\u4f8b\u8c03\u7528\u4e86\u6240\u6709\u4ee3\u7801\u8def\u5f84\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\u7c73\u4e91\uff01\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHPStorm \u4e2d\u7684 PHP \u51fd\u6570\u4ee3\u7801\u8986\u76d6\u7387 \u4f60\u5728\u5b66\u4e60\u6587\u7ae0\u76f8\u5173\u7684\u77e5\u8bc6\u5417\uff1f\u672c\u6587\u300aPHPStorm \u4e2d\u7684 PHP \u51fd\u6570\u4ee3\u7801\u8986\u76d6\u7387\u300b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u7684\u5185\u5bb9\u5c31\u6d89\u53ca\u5230\uff0c\u5982\u679c\u4f60\u60f3\u63d0\u5347\u81ea\u5df1\u7684\u5f00\u53d1\u80fd\u529b\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0\uff0c\u5927\u5bb6\u8981\u77e5\u9053\u7f16\u7a0b\u7406\u8bba\u57fa\u7840\u548c\u5b9e\u6218\u64cd\u4f5c\u90fd\u662f\u4e0d\u53ef\u6216\u7f3a\u7684\u54e6\uff01 \u5728 PHPStorm \u4e2d\uff0c\u4f7f\u7528 Xdebug \u8ba1\u7b97\u51fd\u6570\u4ee3\u7801\u8986\u76d6\u7387\uff1a1. \u5b89\u88c5\u548c\u914d\u7f6e Xdebug \u6269\u5c55\uff1b2. \u8fd0\u884c\u6d4b\u8bd5\uff1b3. \u67e5\u770b\u8986\u76d6\u7387\u62a5\u544a\uff0c\u663e\u793a\u6bcf\u4e2a\u51fd\u6570\u7684\u8986\u76d6\u7387\u3001\u672a\u8986\u76d6\u4ee3\u7801\u884c\u548c\u8fd0\u884c\u65f6\u5f02\u5e38\u3002 PHPStorm \u4e2d\u7684 PHP \u51fd\u6570\u4ee3\u7801\u8986\u76d6\u7387 \u7b80\u4ecb \u4ee3\u7801\u8986\u76d6\u7387\u662f\u6d4b\u91cf\u5728\u6d4b\u8bd5\u6267\u884c\u671f\u95f4\u8fd0\u884c\u4e86\u591a\u5c11\u4ee3\u7801\u7684\u6307\u6807\u3002\u5728 PHPStorm \u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 Xdebug \u5206\u6790\u5668\u8ba1\u7b97\u51fd\u6570\u7684\u4ee3\u7801\u8986\u76d6\u7387\u3002 \u5b89\u88c5\u548c\u914d\u7f6e \u5b89\u88c5 Xdebug \u6269\u5c55\u3002\u6709\u5173\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605 Xdebug \u6587\u6863\u3002 \u5728 PHPStorm \u4e2d\uff0c\u5728 &#8220;PHP&#8221; \u4e0b\u7684 &#8220;Settings&#8221; \u4e2d\u542f\u7528 &#8220;Xdebug&#8221;\u3002 \u6253\u5f00 &#8220;Coverage&#8221; \u9009\u9879\u5361\u5e76\u914d\u7f6e\u4ee5\u4e0b\u8bbe\u7f6e\uff1a Coverage server: localhost Coverage port: 9000 \u8fd0\u884c\u6d4b\u8bd5 \u4f7f\u7528\u60a8\u559c\u6b22\u7684\u6d4b\u8bd5\u6846\u67b6\uff08\u5982 PHPUnit\uff09\u8fd0\u884c\u6d4b\u8bd5\u3002\u786e\u4fdd Xdebug [&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-47734","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47734","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=47734"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47734\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47734"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47734"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47734"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}