Installing SimplePHPUnit Fork0:00
Let's focus on php unit workflow. So for example, from iTerm, in this Laravel project, I can trigger a test suite. And in this case, I'm using a different machine, so I haven't styled iTerm like you normally see. But that's okay, we can trigger it, but maybe it would be cool if we could trigger it directly within Sublime. And maybe we could even add shortcuts where if you just want to run a single file, then you can do that. All right, I'll show you how to do that. We can install a package called SimplePHPUnit, like this. However, I happen to know that there's a fork of this package that actually gives us some of the functionality we need. So instead, I'm going to switch over to Chrome. Here's the repo for that package. And if we go into a pull request area, we can see way back in January, a guy submitted a PR to add some additional functionality, like testing the current file. And it looks like it never got merged. So you know
request area, we can see way back in January, a guy submitted a PR to add some additional functionality, like testing the current file. And it looks like it never got merged. So you know what, I'm just going to use this guy's version of the package instead. Let's go here. It looks like he has a branch set up for this. And why don't we just download and install it manually. Download the zip, open that up, pull that in, and let's rename it to SimplePHPUnit. Okay, now, well, I'll show you a quick way to get to your packages. Go to Sublime, Preferences, Browse Packages. And all I'm going to do here is just drag that in. That's the manual way to tackle this. Okay, so now, if I hit Shift-Command-P, you'll see that we have these new PHPUnit commands we can run. Run it. And there we go. We triggered our test suite. But here's an interesting thing, though. If it acts like it can't find PHPUnit, it seems that Sublime has some awkward issues with the
Fixing Sublime PATH Issues1:35
Run it. And there we go. We triggered our test suite. But here's an interesting thing, though. If it acts like it can't find PHPUnit, it seems that Sublime has some awkward issues with the path and how and when that gets set. So I will close Sublime and I will open it manually, like so. Okay, so let's try to run PHPUnit here. Yeah, and notice we get no such file or directory PHPUnit. And that's because our path is not being applied properly. Now, you have a couple options. One, I believe there is a, if we install a package, a tool called FixMacPath that you might research. That might do the trick for you. Another option, though, is if you simply start Sublime from the command line. And that's almost always what I do. So that's why I haven't worried about it too much. Now, let me show you that. So I will close this out. And I have the Sublime Text documentation pulled up. And you'll see that we have this command line tool that will just open up Sublime
Running Single-File Tests2:24
Now, let me show you that. So I will close this out. And I have the Sublime Text documentation pulled up. And you'll see that we have this command line tool that will just open up Sublime with the given files. So let's grab that, switch over to the terminal. I'll paste that in. And we're just adding a symbolic link to, and in my case, I'm going to move this to /usr/local/bin and then sublime. Now, in my case, it says file exists because I've already done this. But if you're working from scratch, you won't. All right, so now you can type subl . within any directory and it will open up Sublime and have the given files. Great. So now let's give it another shot, phpunit, and that works. A little quirky, right? But no big deal. And why don't we just pull this up a little bit. Okay. Now, if I just want to test a single file, well, once again, phpunit tests/current-file.php. That's what the fork gives us. And in this case, we only have one test rather than
Adding PHPUnit Keybindings3:14
up a little bit. Okay. Now, if I just want to test a single file, well, once again, phpunit test current file. That's what the fork gives us. And in this case, we only have one test rather than multiple. Okay, so that helps. A couple more things. One, I would like the background of the console to match my general theme. And two, I want key bindings for this. All right, let's go to preferences, key bindings, and we'll add a couple more for simple phpunit. Now, the key, well, I'm going to hit, let's say, comma and then p, and that should trigger my full test suite. And the command for that will be simple phpunit. All right, let's try that out. So comma p, and there we go. The full test suite of two tests. Okay, let's add one more though. And this time, we'll set some arguments and specifically test current file. We're going to set that to true. And maybe we will bind that to comma f. Or again, any convention you want. Make up your own mind. All right, so let's
Customizing Console Theme4:07
arguments and specifically test current file. We're going to set that to true. And maybe we will bind that to comma f. Or again, any convention you want. Make up your own mind. All right, so let's try it. comma p does my full test suite, comma f does the single file there. Cool. So we have a pretty good workflow now. Let's just make it look a little prettier. If we browse to preferences, browse packages, and a simple phpunit, let's modify this theme file right here. And it looks like this is the background color we need to modify. So let's grab the correct one here. And we can see the hex value is 252b39. So I will select everything, 252b39. All right, so I hope that did the trick. Let's close out Sublime and open it one more time. And let's try it out. comma p, and there we go. It's honoring our settings. Cool. So comma f to test the single file, and comma p to run my entire suite directly from Sublime Text.
there we go. It's honoring our settings. Cool. So ,f to test the single file, and ,p to run my entire suite directly from Sublime Text.
