1 00:00:00,000 --> 00:00:05,137 For code coverage to work, you'll need to have Xdebug installed. 2 00:00:05,137 --> 00:00:10,740 Xdebug is a PHP extension, so you do not install it through Composer. 3 00:00:10,740 --> 00:00:15,481 For details on installation, check the notes associated with this video. 4 00:00:15,481 --> 00:00:23,120 Once Xdebug is installed, we can add code coverage to our phpunit.xml file. 5 00:00:23,120 --> 00:00:27,588 We'll need to add whitelisting to tell PHPUnit which files to check. 6 00:00:31,649 --> 00:00:33,250 Let's copy these lines. 7 00:00:34,560 --> 00:00:39,440 In our phpunit.xml file, we'll add the filter 8 00:00:44,277 --> 00:00:47,144 We're only going to need the directory. 9 00:00:49,376 --> 00:00:53,440 We want to use our class's directory. 10 00:00:53,440 --> 00:00:58,990 And we want to test all files ending in .php. 11 00:00:58,990 --> 00:01:00,824 Next we want to set up logging. 12 00:01:03,423 --> 00:01:05,000 Let's copy these lines. 13 00:01:06,630 --> 00:01:07,962 And after our filter, 14 00:01:12,143 --> 00:01:16,390 We're going to use our coverage-html. 15 00:01:16,390 --> 00:01:23,050 And we're going to use our coverage-text so that we can output to the terminal. 16 00:01:23,050 --> 00:01:28,955 We'll also keep our lines for the testdox-html and testdox-text. 17 00:01:28,955 --> 00:01:30,150 Let's change our path. 18 00:01:32,070 --> 00:01:40,656 We'll set this to tests/logs, As well as here, 19 00:01:40,656 --> 00:01:46,168 test/logs, tests/logs. 20 00:01:49,581 --> 00:01:51,923 Now let's try running our test again. 21 00:01:57,391 --> 00:02:01,710 When we run our test, we see a simple Code Coverage Report. 22 00:02:01,710 --> 00:02:05,830 That combines all the files from our classes directory. 23 00:02:05,830 --> 00:02:10,950 We then see additional details for the classes that actually have some tests. 24 00:02:10,950 --> 00:02:15,050 We also have a new directory named logs within our tests. 25 00:02:15,050 --> 00:02:17,350 We have the testdox that we looked at before. 26 00:02:17,350 --> 00:02:19,240 But now we also have a reports folder. 27 00:02:20,340 --> 00:02:23,810 This folder contains some HTML files that we can view in the browser. 28 00:02:24,860 --> 00:02:27,070 We see this nicely formatted report. 29 00:02:27,070 --> 00:02:29,470 And we can scroll into our tests. 30 00:02:29,470 --> 00:02:34,634 We can see the construct and the getTitle methods are actually tested. 31 00:02:34,634 --> 00:02:39,920 100% code coverage still may not cover all scenarios. 32 00:02:39,920 --> 00:02:43,600 Just because all lines are covered by a test, 33 00:02:43,600 --> 00:02:46,930 does not mean that they're tested against all input. 34 00:02:46,930 --> 00:02:48,840 But the more tests you have, 35 00:02:48,840 --> 00:02:52,010 the more confident you can be that your code is working.