در حال بارگذاری ...

Configuring PHPUnit in PhpStorm0:00

One of the most useful and compelling features of phpstorm is the ability to easily trigger your phpunit suite. So take a look, I have a fresh project here for Laravel, and we'll go to the exampleTest, and anywhere within the method, I'm just going to right-click, and you'll see run exampleTest. So we'll run that, but then this pops up and it gets confusing, and a lot of people just think, nah, I'm going to do it from the command line instead. Okay, let's just go through it. You can see I have an error here, interpreter is not specified. So I'm going to be using PHP 7.1 here, and my interpreter is PHP 7.1. It's really easy at this point. But next we have another error, custom loader is not specified. Okay, well, it's a Composer project, so I will simply point it to my autoload.php file, and if you did it right, you should see your version. Apply. Okay, we're all set to go.

Running Method vs Class Tests0:40

Okay, well, it's a Composer project, so I will simply point it to my autoload.php file, and if you did it right, you should see your version. Apply. Okay, we're all set to go. So we will run it. It should pop up with the results of your test, and we can now close it in the top right corner. Let's now bring the cursor to the class level, and once again, I will run it, but this time it's going to trigger the entire class, every test method within that class, rather than a single one. Now, this is useful, but let me show you a few key maps I apply. I have command T that will run context configuration. So that's what I hit on any method to run my test, and it pops up. Okay, next I have command shift T, and that's going to run my test again, and specifically, it's going to run the last test I triggered. So for example, let me show you one here. ExampleTest where we get the home page and assert a good status code.

Keymaps for Fast Reruns1:23

my test again, and specifically, it's going to run the last test I triggered. So for example, let me show you one here. Example test where we get the home page and assert a good status code. All right, command T, it runs it, but now let's go to my routes/web.php file and comment this out, and if I want to run that specific test again, I hit shift command T, and now it fails. Great, so now we have a nice feedback loop where I don't always have to switch to the terminal, or always switch back to the test class. I can be working on it, and when I want to try again, shift command T, and it runs it. Finally, I hate having to click that, so one final key map I have is shift command W, and that will close the active tab. So my general workflow will be write a test, hit command T, it runs it, shift command W to close it, and then anywhere else that I'm working in my project, if I want to run that single test again, shift command T, and that's good.

Setting Up Full Suite Run2:10

hit command T, it runs it, shift command W to close it, and then anywhere else that I'm working in my project, if I want to run that single test again, shift command T, and that's good. Now finally, to trigger the full suite, let's go to Run, Edit Configurations, set up a new one, we'll call it full suite, and we will use the test scope defined in our phpunit.xml file. Now if it doesn't find the default, you can of course give it a direct link to your phpunit file. Otherwise, it may find it automatically. And that's it. So now we can run the full suite with ctrl-r in this case, and now you can see it's triggering the full suite rather than a single file. So now, yeah, anywhere in my project, ctrl-r will trigger my full suite. That's all there is to it.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟