1 00:00:00,470 --> 00:00:03,350 Let's go to documentation and 2 00:00:03,350 --> 00:00:08,342 then down to appendix in the XML configuration file. 3 00:00:08,342 --> 00:00:12,679 This configuration file can be added to your version control system, so 4 00:00:12,679 --> 00:00:14,895 all developers get the same output. 5 00:00:14,895 --> 00:00:18,732 If you wanna a direct link, check the notes associated with this video. 6 00:00:18,732 --> 00:00:23,220 These settings will help you make sure that your test work the way that you want. 7 00:00:23,220 --> 00:00:28,576 This first section shows you all the settings that PHP unit uses by default, 8 00:00:28,576 --> 00:00:32,592 backups, caching, converting errors to exceptions, 9 00:00:32,592 --> 00:00:35,705 when to stop running, and when to time out. 10 00:00:35,705 --> 00:00:40,442 We're only going to use a couple of these just to see how it changes our output. 11 00:00:40,442 --> 00:00:42,258 Let's go back to Visual Studio. 12 00:00:42,258 --> 00:00:49,229 We'll create a new file named phpunit.xml. 13 00:00:49,229 --> 00:00:56,145 Phpunit, And then close phpunit. 14 00:00:56,145 --> 00:01:01,959 And for our settings, we're going to set our bootstrap file. 15 00:01:01,959 --> 00:01:06,792 Vendor autoload.php. 16 00:01:06,792 --> 00:01:11,410 This will allow us to be certain that everyone is using the composer 17 00:01:11,410 --> 00:01:12,568 autoload file. 18 00:01:12,568 --> 00:01:16,011 Then we're going to set colors equal to true. 19 00:01:16,011 --> 00:01:19,656 Let's run our test now and see how this changes things. 20 00:01:22,881 --> 00:01:27,647 If we scroll up, we see that our check marks are in green and 21 00:01:27,647 --> 00:01:31,847 our Xs and failed messages are highlighted in red. 22 00:01:31,847 --> 00:01:36,972 We get a lot of extra details because we still have our testdox flag set. 23 00:01:36,972 --> 00:01:39,994 Let's run this again without testdox. 24 00:01:42,365 --> 00:01:47,293 We see our failure F highlighted in red and we also see our failure. 25 00:01:47,293 --> 00:01:51,859 As we add more and more tests, we probably don't wanna show all the details of 26 00:01:51,859 --> 00:01:54,473 the successful tests here in the terminal. 27 00:01:54,473 --> 00:01:58,775 We're probably just interested in if there's something that we need to fix. 28 00:01:58,775 --> 00:02:02,207 We may want to generate a report of all the success and 29 00:02:02,207 --> 00:02:06,896 failures, and we can do that in our configuration file using logging. 30 00:02:06,896 --> 00:02:12,499 Back in the documentation, we'll scroll down to logging. 31 00:02:12,499 --> 00:02:17,634 We're just going to use the testdox logs for now. 32 00:02:17,634 --> 00:02:20,200 We can copy these three lines. 33 00:02:20,200 --> 00:02:23,694 Go back into Visual Studios, 34 00:02:27,168 --> 00:02:32,402 And add logging and 35 00:02:32,402 --> 00:02:37,314 then there we go. 36 00:02:37,314 --> 00:02:38,756 Formatted it a little bit nicer. 37 00:02:38,756 --> 00:02:41,913 Let's change the target to our test folder. 38 00:02:45,183 --> 00:02:51,598 Tests/log, and the same thing here, tests/log. 39 00:02:51,598 --> 00:02:53,224 Now we'll run our test again. 40 00:02:53,224 --> 00:02:58,255 The output in our terminal hasn't changed. 41 00:02:58,255 --> 00:03:02,647 But we now have a logs folder within our test folder. 42 00:03:02,647 --> 00:03:08,710 In this folder, we have a testdox.html and a testdox.txt. 43 00:03:08,710 --> 00:03:13,427 If we open the txt, we see a list of each of our tests, 44 00:03:13,427 --> 00:03:16,446 and an X for the ones that passed. 45 00:03:16,446 --> 00:03:19,158 If you want something a little prettier, 46 00:03:19,158 --> 00:03:22,420 you can open the testdox.html file in a browser. 47 00:03:22,420 --> 00:03:29,407 This gives us checks for each test that passes and a red X for the ones that fail. 48 00:03:29,407 --> 00:03:33,410 The last thing I want to show you is changing the printer itself. 49 00:03:33,410 --> 00:03:37,078 This can change the whole layout of the displayed results. 50 00:03:37,078 --> 00:03:41,576 Let's do a search for PHP unit, printer. 51 00:03:41,576 --> 00:03:45,368 The first one we see is by codedungeon. 52 00:03:45,368 --> 00:03:47,434 This is the most popular. 53 00:03:47,434 --> 00:03:51,036 Although, there are others such as the Nyan Cat printer. 54 00:03:51,036 --> 00:03:57,319 To use this printer, the first thing we need to do is install it with Composer. 55 00:04:04,069 --> 00:04:09,103 Once again, this is for development, so we're going to use the dev flag. 56 00:04:13,375 --> 00:04:17,246 Once the package is installed, we need to add this to our config. 57 00:04:17,246 --> 00:04:21,960 The code dungeon printer includes an initialization script which will add 58 00:04:21,960 --> 00:04:26,617 the code to our config and also add its own config file for customization. 59 00:04:26,617 --> 00:04:29,484 We don't need to run the initialization. 60 00:04:29,484 --> 00:04:32,299 We can just add the printer class to our config. 61 00:04:43,568 --> 00:04:45,160 Now let's run the test again. 62 00:04:48,580 --> 00:04:52,919 This is still compact, but it gives us a litter nicer of a view. 63 00:04:52,919 --> 00:04:57,621 We can see in our EmailTest that all three tests pass. 64 00:04:57,621 --> 00:05:03,551 We can also see in FirstTest that our first assertion does not pass, 65 00:05:03,551 --> 00:05:05,435 but our second does. 66 00:05:05,435 --> 00:05:08,400 It also gives our failure notice. 67 00:05:08,400 --> 00:05:12,249 Feel free to play with these configurations all you want. 68 00:05:12,249 --> 00:05:16,540 Next, we'll move on to some test-driven development.