1"use strict";(globalThis.webpackChunkscaffold=globalThis.webpackChunkscaffold||[]).push([[2460],{8453(e,n,t){t.d(n,{R:()=>o,x:()=>a});var s=t(6540);const i={},r=s.createContext(i);function o(e){const n=s.useContext(r);return s.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),s.createElement(r.Provider,{value:n},e.children)}},9790(e,n,t){t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>a,default:()=>h,frontMatter:()=>o,metadata:()=>s,toc:()=>l});const s=JSON.parse('{"id":"php/testing","title":"Testing","description":"This template provides PHPUnit 10 configuration and example tests for your","source":"@site/content/php/testing.mdx","sourceDirName":"php","slug":"/php/testing","permalink":"/php/testing","draft":false,"unlisted":false,"editUrl":"https://github.com/AlexSkrypnyk/scaffold/tree/main/docs/content/php/testing.mdx","tags":[],"version":"current","sidebarPosition":6,"frontMatter":{"title":"Testing","sidebar_position":6},"sidebar":"tutorialSidebar","previous":{"title":"Linting","permalink":"/php/linting"},"next":{"title":"NodeJS","permalink":"/nodejs/"}}');var i=t(4848),r=t(8453);const o={title:"Testing",sidebar_position:6},a="Testing",c={},l=[{value:"PHPUnit",id:"phpunit",level:2},{value:"Namespaces",id:"namespaces",level:2},{value:"Coverage",id:"coverage",level:2}];function d(e){const n={a:"a",code:"code",h1:"h1",h2:"h2",header:"header",li:"li",p:"p",pre:"pre",ul:"ul",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.header,{children:(0,i.jsx)(n.h1,{id:"testing",children:"Testing"})}),"\n",(0,i.jsx)(n.p,{children:"This template provides PHPUnit 10 configuration and example tests for your\nproject."}),"\n",(0,i.jsx)(n.h2,{id:"phpunit",children:"PHPUnit"}),"\n",(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.a,{href:"https://phpunit.de/",children:"PHPUnit"})," is a widely used testing framework for PHP\napplications. It provides an extensive set of tools to create unit tests,\nperform assertions, and generate test reports. By integrating PHPUnit into your\ndevelopment workflow, you can ensure that your code remains robust and\nerror-free as it evolves. It is an essential tool for anyone aiming to maintain\nhigh code quality and adhere to best practices in PHP development."]}),"\n",(0,i.jsxs)(n.p,{children:["This template includes a ",(0,i.jsx)(n.a,{href:"https://github.com/AlexSkrypnyk/scaffold/blob/main/phpunit.xml",children:"phpunit.xml"}),"\nfile with some sensible defaults to get you started."]}),"\n",(0,i.jsx)(n.p,{children:"Some of the features include:"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:"Orders test execution based on dependencies and defects."}),"\n",(0,i.jsx)(n.li,{children:"Strict about output during tests."}),"\n",(0,i.jsx)(n.li,{children:"Fails on risky tests and warnings."}),"\n",(0,i.jsx)(n.li,{children:"Displays detailed information on tests that trigger warnings, errors, and notices."}),"\n",(0,i.jsx)(n.li,{children:"Restricts deprecations, notices, and warnings from the code."}),"\n",(0,i.jsx)(n.li,{children:"Provides coverage generation configuration."}),"\n"]}),"\n",(0,i.jsx)(n.p,{children:"Running the following command will execute all the tests:"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"composer test\n"})}),"\n",(0,i.jsxs)(n.p,{children:["To execute a specific test tagged with a ",(0,i.jsx)(n.code,{children:"@group wip"}),", use the following command:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"composer test -- --group=wip\n"})}),"\n",(0,i.jsx)(n.h2,{id:"namespaces",children:"Namespaces"}),"\n",(0,i.jsxs)(n.p,{children:["The tests are automatically loaded using Composer's autoloader by specifying\nthe ",(0,i.jsx)(n.code,{children:"YourNamespace\\App\\Tests\\"})," namespace in the ",(0,i.jsx)(n.code,{children:"autoload-dev"})," section of the\n",(0,i.jsx)(n.code,{children:"composer.json"})," file."]}),"\n",(0,i.jsxs)(n.p,{children:["You would need to update the namespace in tests and ",(0,i.jsx)(n.code,{children:"composer.json"})," to match\nyour project's namespace."]}),"\n",(0,i.jsx)(n.h2,{id:"coverage",children:"Coverage"}),"\n",(0,i.jsxs)(n.p,{children:["The template is configured to generate code coverage reports in HTML and\nCobertura formats (",(0,i.jsx)(n.code,{children:"cobertura.xml"}),")."]}),"\n",(0,i.jsxs)(n.p,{children:["Here are some of the coverage settings specified in the ",(0,i.jsx)(n.a,{href:"https://github.com/AlexSkrypnyk/scaffold/blob/main/phpunit.xml",children:"phpunit.xml"})," file:"]}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:"Requires coverage metadata but is not strict about it."}),"\n",(0,i.jsx)(n.li,{children:"Includes uncovered files in the code coverage report."}),"\n",(0,i.jsx)(n.li,{children:"Does not use path-based code coverage."}),"\n",(0,i.jsx)(n.li,{children:"Ignores deprecated code units in the code coverage."}),"\n",(0,i.jsx)(n.li,{children:"Generates HTML coverage reports, which are useful for visualizing code\ncoverage in a browser."}),"\n",(0,i.jsxs)(n.li,{children:["Generates Cobertura coverage reports, which are machine-readable reports\nuseful for integrating with other tools. This template ",(0,i.jsx)(n.a,{href:"../ci/test#code-coverage",children:"provides a GitHub\nAction"})," that uses this report to publish code\ncoverage to the related pull request as a sticky comment."]}),"\n"]}),"\n",(0,i.jsx)(n.p,{children:"To generate the coverage reports, run the following command:"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"XDEBUG_MODE=coverage composer test-coverage\n"})}),"\n",(0,i.jsxs)(n.p,{children:["To execute a specific test tagged with a ",(0,i.jsx)(n.code,{children:"@group wip"})," and get the coverage\nreport, use the following command:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-bash",children:"XDEBUG_MODE=coverage composer test -- --group=wip\n"})})]})}function h(e={}){const{wrapper:n}={...(0,r.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.