Unit tests with Vagrant USING VARYING VAGRANT VAGRANTS (VVV)
Unit tests with VagrantUSING VARYING VAGRANT VAGRANTS
(VVV)
@meSenior 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
VagrantWhat is it?
HostComputerVirtualbox
Shared Folder/usr/html/site C:/user/document/code
Telnet client / vagrant ssh
Vagrant Commands Vagrant upstart
Vagrant suspend / resumepause/play
Vagrant haltturn off
Vagrant destroywipeout
Vagrant statusis it up
Vagrant intcreate empty config file
Vagrant boxmanage
Vagrant sshssh in to virtual box
Vagrant Demo
VVV bitsxdebug_on / xdebug_off (via ssh shell)
Login/password: admin/password
Db account: wp/wp
Hosts updaterhttps://github.com/cogitatio/vagrant-hostsupdatervagrant plugin install vagrant-hostsupdater
Guest Editionshttps://github.com/dotless-de/vagrant-vbguestvagrant plugin install vagrant-vbguest
Dashboardhttps://github.com/topdown/VVV-Dashboard
VVV Site Wizardhttps://github.com/aliso/vvv-site-wizardvvv -a create -n mysite -d mysite.dev -v 3.9.1 -x
VVV on windows problemsDos line endssudo dos2unix /home/vagrant/bin/*
SVN fetch fails with DB errorssvn 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 sshcd /srv/www/wordpress-devolop/phpunit --group functions.phpphpunit --group 28666
Run WordPress core unit tests
Core Test demo
Vagrant sshcd /srv/www/wordpress-trunk/wp scaffold plugin-tests hellocd 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