I came across an article on continuous testing in PHP using Guard and guard-phpunit. I gave it a go and I absolutely love it!
If you want to try it out, head over to the article above for the setup and how to run it.
You may find following notes (on Debian) helpful:
1) Make sure /var/lib/gems/1.8/bin is in your $PATH (just substitute the right path)
2) You may encounter the following error if you’re using either PHPUnit 3.7.x or older version of guard-phpunit:
Fatal error in PHPUnit
Fatal error: Call to undefined method PHPUnit_Framework_TestResult::allCompletlyImplemented() in /var/lib/gems/1.8/gems/guard-phpunit-0.1.4/lib/guard/phpunit/formatters/PHPUnit-Progress/PHPUnit/Extensions/Progress/ResultPrinter.php on line 250
The error is caused by a misspelled method in PHPUnit. Easiest way to fix this is to modify the offending file directly to correct the spelling:
vim /var/lib/gems/1.8/gems/guard-phpunit-0.1.4/lib/guard/phpunit/formatters/PHPUnit-Progress/PHPUnit/Extensions/Progress/ResultPrinter.php
Locate the misspelled method name ‘allCompletlyImplemented()’ - mine was in two lines: 1) line:250 and 2) line:256 and correct them to ‘allCompletelyImplemented()’ and you should be able to get your phpunit to run successfully.
3) A note on the Guardfile if you are using Symfony 2
:cli’ variable to ‘-c app/’src/’4) Here’s an example Guardfile that works for me (in the root of the Symfony project):
guard 'phpunit', :tests_path => 'src/Company', :cli => '--colors -c app/' do
watch(%r{^.+Test\.php$})
watch(%r{^src/Company/SomeAppBundle/Entity/(.+)\.php$}) { |m| "src/Company/SomeAppBundle/Tests/Entity/#{m[1]}Test.php" }
watch(%r{^src/Company/SomeAppBundle/Helper/(.+)\.php$}) { |m| "src/Company/SomeAppBundle/Tests/Helper/#{m[1]}Test.php" }
watch(%r{^src/Company/SomeAppBundle/Command/(.+)\.php$}) { |m| "src/Company/SomeAppBundle/Tests/Command/#{m[1]}Test.php" }
end
The above will cause all unit test trigger when any *Test.php files changes and any modified *.php files from Entity, Helper and Command folder to trigger its own corresponding test files.
Have fun!
This is a follow up on my earlier post Ad-hoc keymapping in Vim where I map ‘,s’ to first save the file that I am editing and then executes the specified file.
Wouldn’t it be better if it saves and execute any file that is currently in the active window? You can do it with %.
In Vim, the % sign is a variable containing the full path to the file currently active your window.
So intead of:
:map ,s :w\|!php filename.php<cr>
You can do:
:map ,s :w\|!php %<cr>
So, doesn’t matter which file you’re editing at any given time, hitting ‘,s’ will save and then execute it.
If your Linux, for some unknown reason ran out of sync by days, and you need a quick solution, use ntpdate:
First stop ntp:
[me@localhost ~] /etc/init.d/ntp stop
Then update time with a server using ntpdate:
[me@localhost ~] ntpdate ntp.ubuntu.com
18 Mar 17:23:16 ntpdate[20660]: step time server 91.189.94.4 offset
269404.459039 sec
Then start ntp again:
[me@localhost ~] /etc/init.d/ntp start
Done.
Just realised that CentOS 6.x minimal setup is so minimal that you have no networking to boot? The fix is very easy (assuming you’re just wanting to DHCP it).
Step 1
dhclient eth0
Step 2
vi /etc/sysconfig/network-scripts/ifcfg-eth0
Change the line
ONBOOT="no"
to
ONBOOT="yes"
Hang on.. what? Still not getting an address after rebooting? Try editing the same file as above:
vi /etc/sysconfig/network-scripts/ifcfg-eth0
Add the following:
BOOTPROTO="dhcp"
This will make it automatically ping DHCP server for an IP.
For testing purposes, I usually create a series of files to run my bash scripts against and I love using the jot command.
jot 3
Generates:
1
2
3
Awesome! This allows me to:
jot 8 | xargs touch
I also use it to generate random series of numbers:
jot -r 10
What if you want to specify a range of numbers to which the randomisation occur?
jot -r 10 580 900
The above gives you 10 random numbers between 580 to 900. Awesome, right? Then there’s more - you can prepend a word to it!
jot -w file_%d -r 10 580 900
Like I said, I love the jot command. There’s a lot more use of this nifty little command. I only cover those I use often.
For the rest of it, you can go through the tutorial here.
Ever come across a situation where you need to do this (very quickly):
rm -rf *
And you get this (with the -i flag):
rm: remove regular file 'PRON_0001.jpg'?
Sh*t! I have to hit 'y' to every single file? Well, you can use the yes command.
The yes command generates an infinite loop of 'y'. So, your problem solved:
yes | rm -rf *
Of course the above example uses the rm command, which can be solved with the -f flag but you can use it for any other commands that doesn’t offer such an option.
I always love doing things without my fingers leaving the keyboard. So, the more I can do from my terminal, the better. Over the years, I’ve come to like quite a few really handy commands.
Open files
Open most files as if you double clicked on it in Finder:
open usage_report.pdf
Wanna open Finder where you are in terminal?
open .
Emailing
Emailing output to yourself (you need to enable postfix): first
ps aux | mail -s "Subject line" me@example.com
You should be able to check if the email has been placed in queue:
mailq
You should see something like this if you’re quick (before it gets sent):
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
6762CA18F19* 20039 Sat Jun 9 20:12:03 root@macbookpro.local
me@example.com
-- 19 Kbytes in 1 Request.
Oh this works on any Linux with mailx and local mta installed.
Clipboard manipulation
How about copying something in terminal to clipboard?
cat some_text.txt | pbcopy
You can then use Ctrl+V anywhere. And if you want to past from clipboard:
pbpaste > from_clipboard.txt
Other misc tools
Current Mac version:
sw_vers
Profiler information:
systerm_profiler
Use the Spotlight engine:
mdfind textedit
Screencapture (full tutorial here):
screencapture ~/Desktop/mycapture.jpg
That’s it! Now go have fun!
Wanna quickly rename files right there and then? I discovered this awesome tool rename. You have the following:
IMG_001.jpg
IMG_002.jpg
...
IMG_113.jpg
You want to rename the following to paris_2012_XXX.jpg:
rename 's/IMG/paris_2012/g' *.jpg
Boom! Done!
Ever experience merging something in SVN just to realise that merged the wrong branch or things don’t work? In few cases, you may want to revert all the changes.
So let’s start with this:
svn st
You get a list of files. But you only want those that has ‘M’ status. So, let’s to filter that using grep:
svn st | grep '^M'
Good. Now that I have only the ones that are modified, all I need is get the filename.
svn st | grep '^M' | awk '{print $2}'
This will actually list only the filename part. The ‘$2’ means print only column 2.
And finally, we run svn revert on each of the filenames returned:
svn st | grep '^M' | awk '{print $2}' | xargs svn revert
Of course, this means you can now do specific things like removing newly added files, conflicted files, etc.
If you use terminal a lot you should know a few really useful keybindings (generally works with bash and zshell). Here’s what I use often:
Ctrl+L: Clear your terminalCtrl+K: Delete from cursor to endCtrl+K: Delete from start to cursorCtrl+E: Move to the end of lineCtrl+A: Move to the end of lineAlt+F: Move a word forwardAlt+B: Move a word backwardCtrl+R: Reverse history searchCtrl+W: Delete backward a wordThere’s quite a few more. So, you may wanna hunt around for more but these are just a few that I personally remember and use on a daily basis.