Categorieën
PHP WordPress

PHPUnit en WordPress plugins

In het bericht “Unit tests voor WordPress plugins” uit juni 2013 schreef ik al eerder over unit testing voor WordPress plugins. In dit bericht een korte update over hoe je PHPUnit in 2014 voor WordPress plugins kunt inrichten.

In het WordPress.org core handboek staat in het artikel “Automated Testing” meer informatie over unit testing en WordPress. In dit artikel staat onder andere beschreven hoe je WordPress test suite kunt uitvoeren.

cd ~/Projects
svn co https://develop.svn.wordpress.org/trunk/ wordpress-develop

Zodra je het ‘wordpress-develop’ project op je lokale computer hebt staan dien je nog een database aan te maken en het ‘wp-tests-config.php’ te voorzien van de juiste gegevens.

Vervolgens kun je .bash_profile bestand bewerken met behulp van het volgende commando:

nano ~/.bash_profile

En het volgende toevoegen:

# WordPress tests
export WP_TESTS_DIR=~/Projects/wordpress-develop/tests/phpunit

Op deze manier weet Bash ook waar je WordPress tests map staat. Vervolgens kun je in je WordPress plugin een PHPUnit XML-bestand aanmaken.

<?xml version="1.0" encoding="UTF-8"?>

<phpunit
 bootstrap="tests/bootstrap.php"
 colors="true"
>
 <testsuites>
 <testsuite name="WordPress Plugins Test Suite">
 <directory>./tests/</directory>
 </testsuite>
 </testsuites>

 <filter>
 <whitelist>
 <directory>./src</directory>
 </whitelist>
 </filter>

 <logging>
 <log type="coverage-clover" target="build/logs/clover.xml"/>
 </logging>
</phpunit>

In de ’tests’ map binnen je WordPress plugin kan vervolgens een ‘bootstrap.php’ bestand neergezet worden met de volgende inhoud:

<?php

$_tests_dir = getenv( 'WP_TESTS_DIR' );
if ( ! $_tests_dir ) {
 $_tests_dir = '/tmp/wordpress-tests-lib';
}

require_once $_tests_dir . '/includes/functions.php';

require_once __DIR__ . '/../vendor/autoload.php';

require $_tests_dir . '/includes/bootstrap.php';

Een voorbeeld van deze test setup is terug te vinden in een aantal van de WordPress Pay gateways bibliotheken.

https://github.com/wp-pay-gateways

Categorieën
Geen categorie

WordPress ontwikkelomgeving op Mac met Brew, Nginx, PHP 5.6, PHP-FPM, MariaDB, phpMyAdmin en meer

 In dit bericht beschrijf ik in een aantal stappen hoe je een WordPress ontwikkelomgeving omgeving kunt opzetten op een Mac.

Brew

Homebrew is een pakket manager voor je Mac en erg handig voor het installeren van allerlei handig tools.

http://brew.sh/

Met het volgende commando kun je Homebrew installeren, maar ik adviseer je om de instructies op de Homebrew website te volgen:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Mocht je Brew al geïnstalleerd hebben dan kun je met het volgende commando Brew bijwerken.

brew update
brew upgrade

PHP

PHP kan eenvoudig via Homebrew geïnstalleerd worden, maar hiervoor moet je wel even de PHP repository intappen.

https://github.com/Homebrew/homebrew-php

Met de volgende commando’s kun je de PHP repository voor Homebrew tappen:

brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php

Vervolgens kun je met het volgende commando bekijken wel opties er beschikbaar zijn voor het installeren van PHP 5.6:

brew options php56

Als het goed is geeft dit commando het volgende resultaat:

--disable-opcache
	Build without Opcache extension
--disable-zend-multibyte
	Disable auto-detection of Unicode encoded scripts (PHP 5.2 and 5.3 only)
--homebrew-apxs
	Build against apxs in Homebrew prefix
--with-apache
	Enable building of shared Apache 2.0 Handler module, overriding any options which disable apache
--with-cgi
	Enable building of the CGI executable (implies --without-apache)
--with-debug
	Compile with debugging symbols
--with-fpm
	Enable building of the fpm SAPI executable (implies --without-apache)
--with-gmp
	Build with gmp support
--with-homebrew-curl
	Include Curl support via Homebrew
--with-homebrew-libxslt
	Include LibXSLT support via Homebrew
--with-homebrew-openssl
	Include OpenSSL support via Homebrew
--with-imap
	Include IMAP extension
--with-libmysql
	Include (old-style) libmysql support instead of mysqlnd
--with-mssql
	Include MSSQL-DB support
--with-pdo-oci
	Include Oracle databases (requries ORACLE_HOME be set)
--with-pgsql
	Include PostgreSQL support
--with-phpdbg
	Enable building of the phpdbg SAPI executable (PHP 5.4 and above)
--with-thread-safety
	Build with thread safety
--with-tidy
	Include Tidy support
--without-bz2
	Build without bz2 support
--without-mysql
	Remove MySQL/MariaDB support
--without-pcntl
	Build without Process Control support
--without-pear
	Build without PEAR
--without-snmp
	Build without SNMP support
--HEAD
	install HEAD version

Ik heb vervolgens PHP 5.6 geïnstalleerd met de volgende opties:

brew install php56 --with-debug --with-fpm --with-homebrew-curl --with-homebrew-libxslt --with-homebrew-openssl

Zodra de installatie is voltooid kun je via het volgende commando controleren of de juiste PHP versie is geïnstalleerd;

php -v

Vervolgens kun je met het volgende commando controleren welke modules er actief zijn:

php -m

PHP-extensies

Er zijn binnen Brew flink wat PHP-extensies beschikbaar, deze kun je met het volgende commando weergeven:

brew search php56-

Hieronder vind je een aantal handige PHP-extensies ik geïnstalleerd heb.

Xdebug

Xdebug is een PHP-extensie die debugging functionaliteiten toevoegt, om dit te installeren kan het volgende commando uitgevoerd worden:

brew install php56-xdebug

Tidy

brew install php56-tidy

PHP-FPM

Om PHP-FPM op te starten dienen de volgende commando’s uitgevoerd te worden:

ln -sfv /usr/local/opt/php56/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php56.plist

Met behulp van het volgende commando kan vervolgens bekeken worden of PHP-FPM luistert naar poort 9000.

lsof -Pni4 | grep LISTEN | grep php

MariaDB

Ook MariaDB kan via Homebrew geïnstalleerd worden met behulp van het volgende commando:

brew install mariadb

Als het goed is gaat Homebrew vervolgens MariaDB installeren en vermeld het de volgende kanttekeningen:

To have launchd start mariadb at login:
    ln -sfv /usr/local/opt/mariadb/*.plist ~/Library/LaunchAgents
Then to load mariadb now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
Or, if you don't want/need launchctl, you can just run:
    mysql.server start

Aangezien MariaDB van mij opgestart mag worden bij het inloggen heb ik vervolgens het volgende commando uitgevoerd:

ln -sfv /usr/local/opt/mariadb/*.plist ~/Library/LaunchAgents

Om MariaDB na installatie op te starten heb ik het volgende commando uitgevoerd:

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist

Om de MySQL installatie te beveiligen kan het volgende commando uitgevoerd worden:

mysql_secure_installation

Mocht je je root wachtwoord vergeten zijn dan kun je de volgende pagina van MariaDB volgen: https://mariadb.com/blog/how-reset-root-password-mariadb-linux.

Mocht je eerder al MySQL geïnstalleerd hebben dan kun je via de volgende stappen MySQL verwijderen: http://stackoverflow.com/questions/1436425/how-do-you-uninstall-mysql-from-mac-os-x.

phpMyAdmin

Voor het installeren van phpMyAdmin kan het volgende commando uitgevoerd worden:

brew install phpmyadmin

Na de installatie zal Homebrew de volgende kanttekeningen melden:

Note that this formula will NOT install mysql. It is not
required since you might want to get connected to a remote
database server.

Webserver configuration example (add this at the end of
your /etc/apache2/httpd.conf for instance) :
  Alias /phpmyadmin /usr/local/share/phpmyadmin
  
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
  
Then, open http://localhost/phpmyadmin

More documentation : file:///usr/local/Cellar/phpmyadmin/4.2.8/share/phpmyadmin/doc/

Configuration has been copied to /usr/local/etc/phpmyadmin.config.inc.php
Don't forget to:
  - change your secret blowfish
  - uncomment the configuration lines (pma, pmapass ...)

Apache uitschakelen

Binnen een Mac wordt Apache vaak standaard opgestart, met het volgende commando kan Apache uitgeschakeld worden:

sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist

Bron: http://stackoverflow.com/a/20439859

Nginx

Nginx kan geïnstalleerd worden met het volgende commando:

brew install nginx

Na de installatie zal Homebrew de volgende kanttekeningen melden:

Docroot is: /usr/local/var/www

The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.

To have launchd start nginx at login:
    ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents
Then to load nginx now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
Or, if you don't want/need launchctl, you can just run:
    nginx

Na installatie zal er een standaard Nginx configuratie bestand ingesteld zijn. Aangezien in dit bestand veel commentaar staat is het niet heel overzichtelijk. Daarom verwijderen we dit bestand volledig en voegen we een eigen configuratie bestand toe.

rm /usr/local/etc/nginx/nginx.conf
nano /usr/local/etc/nginx/nginx.conf

In het nieuwe configuratie bestand plaatsen we het volgende:

worker_processes  1;
 
error_log  /usr/local/etc/nginx/logs/error.log debug;
 
events {
    worker_connections  256;
}
 
http {
    include             mime.types;
    default_type        application/octet-stream;
 
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
 
    access_log  /usr/local/etc/nginx/logs/access.log  main;
 
    sendfile            on;
 
    keepalive_timeout   65;
 
    index index.html index.php;
 
    include /usr/local/etc/nginx/sites-enabled/*; 
}

Op de Nginx documentatie websites staat meer informatie over de verschillende directives:

Voor de logs en configuratie bestanden maken we een aantal maken aan:

mkdir -p /usr/local/etc/nginx/logs
mkdir -p /usr/local/etc/nginx/sites-available
mkdir -p /usr/local/etc/nginx/sites-enabled
mkdir -p /usr/local/etc/nginx/conf.d

Composer

brew install composer

WP-CLI

brew install wp-cli

 

Dnsmasq

Met behulp van Dnsmasq kunnen we er voor zorgen dat elk request naar bijvoorbeeld .dev domeinnamen doorverwezen worden naar je lokale IP-adres 127.0.0.1. Hiermee hoef je dus niet voor elke ontwikkelomgeving een extra regel toe te voegen aan je host bestand (/etc/hosts).

brew install dnsmasq

Na het installeren van Dnsmasq geeft Brew de volgende kanttekeningen:

To configure dnsmasq, copy the example configuration to /usr/local/etc/dnsmasq.conf
and edit to taste.

  cp /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf

To have launchd start dnsmasq at startup:
    sudo cp -fv /usr/local/opt/dnsmasq/*.plist /Library/LaunchDaemons
Then to load dnsmasq now:
    sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist

t

Bronnen

Categorieën
Mac

Mijn MacBook Pro installatie

In dit bericht zal ik kort samenvatten hoe mijn MacBook Pro installatie er uit ziet qua programma’s, tools, addons, etc..

Webbrowsers

  • Google Chrome [standaard]
    • LastPass
    • AdBlock Plus
  • Firefox
    • LastPass
    • AdBlock Plus
    • Firebug
  • Opera
    • LastPass
  • Safari
    • LastPass

Productiviteit

  • Evernote
  • Dropbox
  • Alfred 2

Entertainment

  • Spotify
  • VLC

Ontwikkeling

  • iTerm2
  • Sublime Text 3
  • Java SE Development Kit
  • Eclipse
    • PHP Development Tools (PDT)
    • Preferences
      • PHP » Editor » Save Actions » ✓ Remove trailing whitespace » All lines
  •  SourceTree
    • Project folder: /Users/remco/Projects
    • Terminal App: iTerm2
    • Taal: English
  • FileZilla
    • Thema: Classic
  • Poedit
  • Homebrew
  • Node.js
    • brew install node
  • Git
    • brew install git
  • PHP
    • brew tap homebrew/dupes
    • brew tap homebrew/versions
    • brew tap homebrew/homebrew-php
    • brew install php56
  • PHP CodeSniffer
    • brew install php-code-sniffer
  • WordPress Coding Standards
    • https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards
  •  Grunt
    • npm install -g grunt-cli
    • npm install -g npm-check-updates
  • Xcode
  • VirtualBox
    • https://github.com/xdissent/ievms

Communicatie

  • Adium
  • Skype
  • Twitter

Overige

  • ScanSnap
    • ABBYY FineReader for ScanSnap
  • uTorrent
  • The Unarchiver
  • QFinder
  • Kitabu
  • Aegisub

Bronnen