Unit tests with Vagrant
USING VARYING VAGRANT VAGRANTS
(VVV)
@me
Senior Full Stack WordPress Developer
Plugin author of Author Avatars List http://wordpress.org/plugins/author-avatars/
and WP Site Verification tool http://wordpress.org/plugins/wp-site-verification-tool/
Slides @ http://www.slideshare.net/pbearne
Vagrant
What is it?
HostComputer
Virtualbox
Shared Folder/usr/html/site C:/user/document/code
Telnet client / vagrant ssh
Vagrant Commands
Vagrant up
start
Vagrant suspend / resume
pause/play
Vagrant halt
turn off
Vagrant destroy
wipeout
Vagrant status
is it up
Vagrant int
create empty config file
Vagrant box
manage
Vagrant ssh
ssh in to virtual box
Vagrant Demo
VVV bits
xdebug_on / xdebug_off (via ssh shell)
Login/password: admin/password
Db account: wp/wp
Hosts updater
https://github.com/cogitatio/vagrant-hostsupdater
vagrant plugin install vagrant-hostsupdater
Guest Editions
https://github.com/dotless-de/vagrant-vbguest
vagrant plugin install vagrant-vbguest
Dashboard
https://github.com/topdown/VVV-Dashboard
VVV Site Wizard
https://github.com/aliso/vvv-site-wizard
vvv -a create -n mysite -d mysite.dev -v 3.9.1 -x
VVV on windows problems
Dos line ends
sudo dos2unix /home/vagrant/bin/*
SVN fetch fails with DB errors
svn cleanup need to be run
Windows 8 – hosts file need to be unprotect in
window defender
SVN version can be different
PHPUnit
https://make.wordpress.org/core/handbook/automated-testing/
<?php
class SampleTest extends WP_UnitTestCase {
function testSample() {
// replace this with some actual testing code
$this->assertTrue( true );
}
}
PHPUnit Commands
phpunit --list-groups
phpunit –groups ******
phpunit –verbose
phpunit –filter text
Vagrant ssh
cd /srv/www/wordpress-devolop/
phpunit --group functions.php
phpunit --group 28666
Run WordPress core unit tests
Core Test demo
Vagrant ssh
cd /srv/www/wordpress-trunk/
wp scaffold plugin-tests hello
cd wp-content/plugins/hello/
phpunit
Add Unit tests to a plugin
PHPUnit plugin demo
class MyTestClass extends PHPUnit_Framework_TestCase {
public function setUp() {
WP_Mock::setUp();
}
public function tearDown() {
WP_Mock::tearDown();
}
}
WP_Mock::onFilter( 'the_content' )->with( 'Windows Rocks!' )->reply( 'Apple Rocks!' );
wp_mock
https://github.com/10up/wp_mock
public function test_content_filter() {
WP_Mock::onFilter( 'the_content' )->with( 'Windows Rocks!' )->reply( 'Apple Rocks!' );
$post = new stdClass;
$post->post_content = 'Windows Rocks!';
setup_postdata( $post );
$content = get_the_content();
$this->assertEquals( 'Apple Rocks!', $content );
}
wp_mock test example
https://github.com/10up/wp_mock
wp_mock demo
Questions?
http://www.slideshare.net/pbearne

Unit tests with vagrant