Running Basic PHPUnit Test 0:00Here, you can see the basic example test class that is included with every install of Laravel. Also, I've pulled in phpunit, so if we check out my required dev block, there it is. So that means, assuming that we have a homepage route, I should be able to run phpunit and see the output. Perfect. Now, though, if you don't like to use iTerm or the terminal, you can do this directly within your IDE. If I scroll up, down to Tools, all the way to Open Terminal, you can do the same thing right here. So, mostly, that just sort of comes down to preference.right here. So, mostly, that just sort of comes down to preference. For me, I really like using iTerm and having it full screen like this. But if you want to do this, that's perfectly cool. Now, if I close this out, in this particular example, we could also rewrite this. I could call and make a GET request to the homepage, and then if I want to assert that the response is essentially 200, then this would be all the code that I need. So once again, if I run it again, we still get green. But now, it might be nice if I could run the test directly within the IDE without opening up some kind of terminal, and also have the flexibility to, when I need to, run only single Running Tests in PhpStorm 1:01But now, it might be nice if I could run the test directly within the IDE without opening up some kind of terminal, and also have the flexibility to, when I need to, run only single tests. So imagine if this class had 10 different tests. If I just wanted to test this single one, well, phpStorm allows us to do that. Let's see how we might go about it. If I scroll up to Run, let's try this out. Now, in our case, we want to test ExampleTest. Now, this is something that you might come across, and this had me stumped in the earlier days. Fixing PHPUnit Autoloader 1:30Now, this is something that you might come across, and this had me stumped in the earlier days. If you do get Test Framework Quit unexpectedly, that means it can't find some of the classes it needs. And you can see that right here. Cannot find phpUnit in the include path. And that's because we need to tell it about our autoloader. So if I hit Command Comma, we can come to php all the way down to phpUnit, and I will specify a custom autoloader. Now notice that I'm having that point to my project's vendor slash autoload file.specify a custom autoloader. Now notice that I'm having that point to my project's vendor slash autoload file. So if we apply that, now if we try it again, it should work. And there we go. So notice that we have a total of one test, and we did get green. Perfect. Just to make sure it works, though, let's try a page that I don't have a route set up. We rerun the tests, and of course that failed. So let's bring this back and say test home. Maybe you have some kind of simple functional test, simply to make sure that all of your Adding Routes to Pass Tests 2:22So let's bring this back and say test home. Maybe you have some kind of simple functional test, simply to make sure that all of your various routes do work. So test about. Now if we run it, we have two different tests, two of two, but one of them did fail. And notice we can drill down to figure out exactly what did fail. So in this case, the problem was a not found exception, and that's because, of course, we don't have a route set up for that. So we could do that right now in the routes.php, and let's just very quickly create that route. And if I run it again, it works. Rerunning a Single Test 2:47So we could do that right now in the routes.php, and let's just very quickly create that route. And if I run it again, it works. But now notice that when I hit play, it reran all tests. And that's fine, but you may get to a point where you have potentially thousands of tests. So if you ever just want to rerun a single test, let me show you how to do that. Let's comment that for now, rerun it to get back where we were before. And now once again, we set our fix, and if I now right click right here, I can run just that single test. Or I can press on the Mac Ctrl Shift R. So let's try it. Ctrl Shift R. And now, rather than testing the whole class, we only did this single method. Previewing Code Coverage 3:21Or I can press on the Mac Ctrl Shift R. So let's try it. Ctrl Shift R. And now, rather than testing the whole class, we only did this single method. So the important thing to remember is that you can always go up to run, you can use the keyboard shortcuts, or of course you can right click. So if I want to rerun this, I can hit run example test in that specific method to get that same output. However, what about when you're interested in code coverage? Can phpStorm help us with that? And of course the answer is yes. So we will take a look at that in the next lesson.And of course the answer is yes. So we will take a look at that in the next lesson.