- Overview
- Transcript
3.3 Easier Testing With Snippets
In this lesson, we'll install a helpful bundle of snippets for writing PHPUnit tests. I'll show you how to use it in this lesson.
1.Introduction1 lesson, 02:05
1.1Welcome02:05
2.Getting Started9 lessons, 35:20
2.1Installation and Base Settings04:54
2.2Services and Opening Sublime From the Terminal02:20
2.3Multiple Cursors and Incremental Search06:54
2.4The Command Palette04:13
2.5Instant File Changing03:19
2.6Symbols04:17
2.7Key Bindings02:33
2.8Installing Plugins Without Package Control02:54
2.9Package Control03:56
3.Snippets3 lessons, 14:40
3.1Your First Snippet09:04
3.2Adding Snippets Through Package Control02:32
3.3Easier Testing With Snippets03:04
4.Essential Plugins12 lessons, 46:58
4.1Zen Coding07:09
4.2Emmet06:52
4.3Cross-Browser CSS With Prefixr02:17
4.4Fetch Files With Ease 04:22
4.5Lightning Fast Folder and File Creation 02:12
4.6Sidebar Enhancements03:09
4.7Sublime Linter02:01
4.8Sexy Code Snippet Management With Gists07:50
4.9DocBlockr03:49
4.10Pretty Task Management02:42
4.11HTTP Requests Within Sublime02:29
4.12LiveReload02:06
5.Tips, Techniques and Modifications8 lessons, 49:09
5.1Regular Expressions in Sublime05:49
5.2Vintage Mode10:46
5.3Quicker Stylesheet References02:30
5.4Joining Lines04:40
5.5Sublime and Markdown with Marked03:10
5.6All About Projects 05:54
5.7Configuring and Mastering Split Windows07:19
5.8Custom Builds09:01
6.Closing1 lesson, 00:49
6.1Conclusion00:49
3.3 Easier Testing With Snippets
One thing that would be nice is if Sublime Text could give me a easy way to prepare my tests. So in this case I'm using php, so I'm using php unit. And I frequently have to do things like this assert equals. But then from time to time you forget, is this supposed to be what's expected, is this what we're matching against? As you may know these things can slightly be different from method to method. So if we tried to install a solution. We'll look for phpunit. All we have right here is a plugin, but that doesn't really have the snippets that I'm interested in. But don't always depend on Package Control. Sometimes you'll find resources that simply haven't been added to Package Control. So in these cases, GitHub can be an excellent resource. So I've done a search for phpunit snippets, and I came up with this repo. And take a look. There's probably around 50 different snippets. So let's go ahead and bring this into our project. I'm going to copy the URL here, and then, within the terminal, I'm going to CD into my library, on the MAC into Application Support, Sublime Text 2, and into the Packages directory. Within here, we need to switch into the User directory. So CD into the User directory. Now assuming that you have git installed, I can run git clone I paste in the url and we're gonna call it PHPUnit. And that's it. We now have that PHPUnit directory. If I list files, there is all of our snippets. So now I have free reign over all of the snippets. If I run ass. Now you'll start to see all of the snippets that are available to us. So in addition to providing a shorthand, it's also a great reference when I'm not exactly sure which method I need? Well I can quickly search through this list here. Maybe I need assertContains and then that will expand. Here is the needle, my string. We're going to look into haystack of my string. Hit Tab again. If I want a message, I can add it. Otherwise I can hit Backspace, and now I'm done. So maybe I need to assert by regular expression. I could do ass for assert, r and there we go, assertRegExp. The only other thing that I see myself needing is the ability to quickly write these test functions. So why don't we create a snippet ourselves? A new snippet, and right here, I will do public function test${}(), and then I will set the caret right after that. And then, we'll set the next stop point right there. All right? I'm gonna set the scope to source.php, and the tabTrigger is going to be test. I'm going to save this into my PHPUnit directory, and we'll call it test.sublime-snippet. Again, remember, it has to have that extension in order to work. So once that has been saved, let's try it again. We'll delete everything entirely. And now we're going to write a test, test Tab. The name will be CanCreateUser, something like that. And now we'll assert equals, and everything is working as expected. So I love this, because it turns the process of writing your test into only a few keystrokes.