Introducing Sublime PHPUnit Plugin0:00
Now, when it comes to testing, yes, of course, you can switch to the command line, trigger your suite, or you can filter it down, but it can still be time-consuming. For example, let's just go to some random feature here for favoriting. Okay, so yes, I could run phpunit, filter it down to that class, or even down to an individual method, like so. But it would be nice if Sublime could do that for us automatically. So luckily, we have a useful Sublime phpunit package from Adam Weathen that works great. All right, so let's see how to use it. Now, I don't think this is available on package control, so we just have to cd to our packages directory.
Installing the Plugin0:35
Now, I don't think this is available on package control, so we just have to cd to our packages directory. Whoops, library. All right, let's clone this repo. And we should be all set to go. So let's go back to Sublime, and if we open up Sublime phpunit, yeah, we can see four new methods here for running all the tests, running tests in a directory, a single file, and then a single test method. So let's put our cursor on this method and then say Sublime phpunit, run this test method, and there you go.
Running and Verifying Tests1:06
So let's put our cursor on this method and then say Sublime phpunit, run this test method, and there you go. Now, in this case, though, you can see it's opening up Terminal rather than iTerm. But nonetheless, it is, in fact, working, which is great. So if I want to scroll down here, and let's just change this to make it fail, and then if we run it again, of course, we're going to get red, and we do. Okay, great. So let's figure out how to switch that over to iTerm. So here it looks like we can add this single item to our settings, and that should do the trick.
Switching Output to iTerm1:33
So here it looks like we can add this single item to our settings, and that should do the trick. All right, so let's add it right down here, like so. And I think that should do the trick. So one more time, let's give this another run, and now it switches over to iTerm and does that automatically. Really useful. So that runs a single method, but if we want to run the entire class, run this file. So now you can see it is triggering phpunit specifically on that single file rather than the full suite.
Adding Key Bindings1:56
So now you can see it is triggering phpunit specifically on that single file rather than the full suite. So the only remaining thing is let's set up a key mapping here. I like to use Command-T and Command-Shift-T. That just comes from phpStorm workflow that I also use. So let's set this up. These are the four commands. So let's go back to Sublime, go to our key bindings, and we're going to set up a new one here. So we'll say, when you type in super, which is Command plus T,
and we're going to set up a new one here. So we'll say, when you type in super, which is Command plus T, then I want to trigger the command. And what is it called? And let's do run single phpunit test. All right, so let's give that a shot. I will put the cursor here and run Command-T, and we get green. And I should be able to put the cursor anywhere within the method for it to work. So if we change this to five, Command-T, I'm within the method, so it will figure out what the name is, as you can see here.
Workflow Recap and Shortcuts3:11
And really, those are the only two ones that I really use. If I'm doing the full suite, yeah, that could be useful. Sometimes I'll just do that from the command line, though. Mostly, I'll stick with this. All right, so anywhere I can run shift Command-T, and that'll run all of the tests within the file. Or I can run Command-T on anywhere within a method, and that will filter it down to that single method. Anyways, that should work nicely for you.
