unit tests with vagrant

20
Unit tests with Vagrant USING VARYING VAGRANT VAGRANTS (VVV)

Upload: paul-bearne

Post on 14-Jul-2015

178 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Unit tests with vagrant

Unit tests with VagrantUSING VARYING VAGRANT VAGRANTS

(VVV)

Page 2: Unit tests with vagrant

@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

Page 3: Unit tests with vagrant

VagrantWhat is it?

HostComputerVirtualbox

Shared Folder/usr/html/site C:/user/document/code

Telnet client / vagrant ssh

Page 4: Unit tests with vagrant
Page 5: Unit tests with vagrant
Page 6: Unit tests with vagrant

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

Page 7: Unit tests with vagrant

Vagrant Demo

Page 8: Unit tests with vagrant

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

Page 9: Unit tests with vagrant

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

Page 10: Unit tests with vagrant

PHPUnit

Page 11: Unit tests with vagrant

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 );

}}

Page 12: Unit tests with vagrant

PHPUnit Commands phpunit --list-groups

phpunit –groups ******

phpunit –verbose

phpunit –filter text

Page 13: Unit tests with vagrant

Vagrant sshcd /srv/www/wordpress-devolop/phpunit --group functions.phpphpunit --group 28666

Run WordPress core unit tests

Page 14: Unit tests with vagrant

Core Test demo

Page 15: Unit tests with vagrant

Vagrant sshcd /srv/www/wordpress-trunk/wp scaffold plugin-tests hellocd wp-content/plugins/hello/phpunit

Add Unit tests to a plugin

Page 16: Unit tests with vagrant

PHPUnit plugin demo

Page 17: Unit tests with vagrant

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

Page 18: Unit tests with vagrant

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

Page 19: Unit tests with vagrant

wp_mock demo

Page 20: Unit tests with vagrant

Questions?

http://www.slideshare.net/pbearne