Configuration5:17 with Alena Holligan
PHPUnit uses XML file for configuration. This configuration file can be added to your version control system so all developers get the same output. These settings will help you make sure your tests work the way you want.
Let's go to documentation and 0:00 then down to appendix in the XML configuration file. 0:03 This configuration file can be added to your version control system, so 0:08 all developers get the same output. 0:12 If you wanna a direct link, check the notes associated with this video. 0:14 These settings will help you make sure that your test work the way that you want. 0:18 This first section shows you all the settings that PHP unit uses by default, 0:23 backups, caching, converting errors to exceptions, 0:28 when to stop running, and when to time out. 0:32 We're only going to use a couple of these just to see how it changes our output. 0:35 Let's go back to Visual Studio. 0:40 We'll create a new file named phpunit.xml. 0:42 Phpunit, And then close phpunit. 0:49 And for our settings, we're going to set our bootstrap file. 0:56 Vendor autoload.php. 1:01 This will allow us to be certain that everyone is using the composer 1:06 autoload file. 1:11 Then we're going to set colors equal to true. 1:12 Let's run our test now and see how this changes things. 1:16 If we scroll up, we see that our check marks are in green and 1:22 our Xs and failed messages are highlighted in red. 1:27 We get a lot of extra details because we still have our testdox flag set. 1:31 Let's run this again without testdox. 1:36 We see our failure F highlighted in red and we also see our failure. 1:42 As we add more and more tests, we probably don't wanna show all the details of 1:47 the successful tests here in the terminal. 1:51 We're probably just interested in if there's something that we need to fix. 1:54 We may want to generate a report of all the success and 1:58 failures, and we can do that in our configuration file using logging. 2:02 Back in the documentation, we'll scroll down to logging. 2:06 We're just going to use the testdox logs for now. 2:12 We can copy these three lines. 2:17 Go back into Visual Studios, 2:20 And add logging and 2:27 then there we go. 2:32 Formatted it a little bit nicer. 2:37 Let's change the target to our test folder. 2:38 Tests/log, and the same thing here, tests/log. 2:45 Now we'll run our test again. 2:51 The output in our terminal hasn't changed. 2:53 But we now have a logs folder within our test folder. 2:58 In this folder, we have a testdox.html and a testdox.txt. 3:02 If we open the txt, we see a list of each of our tests, 3:08 and an X for the ones that passed. 3:13 If you want something a little prettier, 3:16 you can open the testdox.html file in a browser. 3:19 This gives us checks for each test that passes and a red X for the ones that fail. 3:22 The last thing I want to show you is changing the printer itself. 3:29 This can change the whole layout of the displayed results. 3:33 Let's do a search for PHP unit, printer. 3:37 The first one we see is by codedungeon. 3:41 This is the most popular. 3:45 Although, there are others such as the Nyan Cat printer. 3:47 To use this printer, the first thing we need to do is install it with Composer. 3:51 Once again, this is for development, so we're going to use the dev flag. 4:04 Once the package is installed, we need to add this to our config. 4:13 The code dungeon printer includes an initialization script which will add 4:17 the code to our config and also add its own config file for customization. 4:21 We don't need to run the initialization. 4:26 We can just add the printer class to our config. 4:29 Now let's run the test again. 4:43 This is still compact, but it gives us a litter nicer of a view. 4:48 We can see in our EmailTest that all three tests pass. 4:52 We can also see in FirstTest that our first assertion does not pass, 4:57 but our second does. 5:03 It also gives our failure notice. 5:05 Feel free to play with these configurations all you want. 5:08 Next, we'll move on to some test-driven development. 5:12
You need to sign up for Treehouse in order to download course files.Sign up