Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

PHPUnit installation in Windows: Difference between revisions

From MoodleDocs
No edit summary
Line 1: Line 1:
= Windows 7 =
This step-by-step guide is intended for developers only, it can not be used on production servers!
 
If you see '''launch as administrator''' bellow it means that you need to work around User Account Controls restrictions. There are several ways to do that:
 
* Click Start button. Type 'cmd' and, instead of pressing Return, press Ctrl + Shift + Return. This should give you a popup prompt to confirm permissions, then run the command prompt as administrator.
* Install some file manager such as TotalCommander and launch it using right click + "Run as administrator". Then all programs started from the file manager have full administrative access.
* Open file Explorer and type "C:\windows\system32", then find cmd.exe and right click and select "Run as administrator".
* Temporarily turn off UAC.
 
It is possible to paste text into command line (cmd.exe) by clicking on the icon in the top-left corner and selecting "Edit / Paste".
 
Do not use PHP 5.4.x because it does not have windows installer yet and some extensions are not compatible. Moodle 2.3 is going to be the first version fully compatible with PHP 5.4.
 
64bit Windows are using "C:\Program Files (x86)" instead of "C:\Program Files".
 
 
==Install Apache 2.2==
 
* download Apache server installer from http://httpd.apache.org/download.cgi, for example httpd-2.2.22-win32-x86-openssl-0.9.8t.msi
* install to default location "C:\Program Files\Apache Software Foundation\Apache2.2\"
* create "C:\server\workspace" directory
* edit "C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf"
 
DocumentRoot "C:/server/workspace"
<Directory "C:/server/workspace">
    Options FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>
 


==Install PHP==
==Install PHP==


* download '''thread safe''' PHP 5.3.x installer from http://windows.php.net/download/, for example php-5.3.10-Win32-VC9-x86.msi
* launch PHP installer
* default location "C:\Program Files\PHP\"
* select "Apache 2.2.x Module"
* Apache configuration is in "C:\Program Files\Apache Software Foundation\Apache2.2\conf\"
* select "PHP / Script Executable" to be installed
* select "PHP / Extensions / Multi-Byte" to be installed
* select "PHP / Extras / PEAR Install" to be installed
* add index.php to C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf


Do not try to install PHP 5.4 as there is no installer and it doesn't include the PEAR installation batch file. Instead, you have to use PHP 5.3.
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>


* http://windows.php.net/download/#php-5.3
* download thread safe PHP 5.3.x zip package from http://windows.php.net/download/, for example php-5.3.10-Win32-VC9-x86.zip
* extract the zip file over contents of "C:\Progam Files\PHP\" to get missing libs and extensions
* edit "C:\Program Files\PHP\php.ini", add <code>extension=php_intl.dll</code> line at the end


You probably want the thread-safe version.


While going through the installation, you probably should use all default options, except:
==Verify Apache and PHP configuration==


# There is a question about which web server to use. Since you do not have PHP installed on your system already, you probably don't want to run a web server, so choose 'Do not setup a web server'.
* restart windows
# There is a list of features. Expand 'Extras' and turn on 'PEAR install'.
* launch cmd.exe as normal user
* verify <code>php.exe --version</code> prints version information, if not fix system PATH setting to include "C:\Program Files\PHP"
* create "C:\server\workspace\index.php" file:


After install completes, open a new terminal and run 'php -version' to verify that it is installed.
<code php>
<?php
echo phpinfo();
</code>


* open http://127.0.0.1/ in browser and verify all necessary extensions including intl are present
* delete "C:\server\workspace\index.php"


== Install PEAR ==


* Click Start button. Type 'cmd' and, instead of pressing Return, press Ctrl + Shift + Return. This should give you a popup prompt to confirm permissions, then run the command prompt as administrator.
==Install PEAR==
* launch cdm.exe '''as administrator'''


  cd "\Program Files (x86)"\php
  cd "C:\Program Files\PHP"
  go-pear
  go-pear.bat


* Hit Return repeatedly to accept all defaults.
* confirm "system"
* type 12 and select "C:\Program Files\PHP" directory
* hit Enter a few times


  start PEAR_ENV.reg  
  start PEAR_ENV.reg


* Accept adding junk to your registry.
* optionally set proxy server


* Note that when I tried this, each time you run 'pear' it will come with a messagebox popup error, but this does not seem to stop it working.
pear config-set http_proxy my.proxy.is:80


* If you use an HTTP proxy:
pear upgrade-all


pear config-set http_proxy my.proxy.is:80


==Install PHPUnit==
==Install PHPUnit==
* launch cdm.exe '''as administrator'''


* Install PHPUnit and DbUnit:
cd "C:\Program Files\PHP"
 
  pear config-set auto_discover 1
  pear config-set auto_discover 1
pear upgrade-all
  pear install pear.phpunit.de/PHPUnit
  pear install pear.phpunit.de/PHPUnit
  pear install pear.phpunit.de/DbUnit
  pear install phpunit/DbUnit
 
 
==Install PostgreSQL==
* download PostgreSQL from http://www.enterprisedb.com/products-services-training/pgdownload#windows, for example postgresql-9.1.3-1-windows.exe
* install PostgreSQL with some default locale using UTF-8 (skip the StackBuilder)
* launch PgAdmin III - double click on "PostgreSQL 9.1 (localhost:5432)", right-click on "Databases (1)" and create new database "moodle"
 
 
==Install Git and clone Moodle repository==
* download git from http://code.google.com/p/msysgit/downloads/list?can=3, for example Git-1.7.10-preview20120409.exe
* install git
* start "Git bash" (icon on desktop)
 
cd /C/server/workspace
git clone git://github.com/moodle/moodle.git
 
* close the bash window
 
 
==Install Moodle==
* create directory "C:\server\moodledata"
* create directory "C:\server\phpu_moodledata"
* create file "C:\server\workspace\moodle\config.php":
 
<code php>
<?php  // Moodle configuration file
unset($CFG);
global $CFG;
$CFG = new stdClass();
$CFG->dbtype    = 'pgsql';
$CFG->dblibrary = 'native';
$CFG->dbhost    = 'localhost';
$CFG->dbname    = 'moodle';
$CFG->dbuser    = 'postgres';
$CFG->dbpass    = 'YOUR PASSWORD HERE';
$CFG->prefix    = 'mdl_';
$CFG->dboptions = array (
  'dbpersist' => 0,
  'dbsocket' => '',
);
$CFG->wwwroot  = 'http://127.0.0.1/moodle';
$CFG->dataroot  = 'C:\\server\\moodledata';
$CFG->passwordsaltmain = 'some random rubbish goes here';
$CFG->debug = (E_ALL | E_STRICT);
$CFG->debugdisplay = 1;
$CFG->phpunit_prefix = 'phpu_';
$CFG->phpunit_dataroot = 'C:\\server\\phpu_moodledata';
require_once(dirname(__FILE__) . '/lib/setup.php');
</code>
* optionally go to http://127.0.0.1/moodle and finish standard installation
 
 
==Initialise test environment==
* launch cmd.exe as normal user
cd C:\server\workspace\moodle
php admin\tool\phpunit\cli\init.php
 
 
==Execute all tests==
* launch cmd.exe as normal user
cd C:\server\workspace\moodle
phpunit


* Using a text editor, edit the 'phpunit' shell script in c:\Program Files (x86)\PHP. Change the first line to:


#!php.exe
==Learn more about PHPUnit==
* read http://www.phpunit.de/manual/current/en/index.html
* follow @s_bergmann on Twitter
* try PHPStorm IDE with built-in PHPUnit integration

Revision as of 14:58, 19 April 2012

This step-by-step guide is intended for developers only, it can not be used on production servers!

If you see launch as administrator bellow it means that you need to work around User Account Controls restrictions. There are several ways to do that:

  • Click Start button. Type 'cmd' and, instead of pressing Return, press Ctrl + Shift + Return. This should give you a popup prompt to confirm permissions, then run the command prompt as administrator.
  • Install some file manager such as TotalCommander and launch it using right click + "Run as administrator". Then all programs started from the file manager have full administrative access.
  • Open file Explorer and type "C:\windows\system32", then find cmd.exe and right click and select "Run as administrator".
  • Temporarily turn off UAC.

It is possible to paste text into command line (cmd.exe) by clicking on the icon in the top-left corner and selecting "Edit / Paste".

Do not use PHP 5.4.x because it does not have windows installer yet and some extensions are not compatible. Moodle 2.3 is going to be the first version fully compatible with PHP 5.4.

64bit Windows are using "C:\Program Files (x86)" instead of "C:\Program Files".


Install Apache 2.2

  • download Apache server installer from http://httpd.apache.org/download.cgi, for example httpd-2.2.22-win32-x86-openssl-0.9.8t.msi
  • install to default location "C:\Program Files\Apache Software Foundation\Apache2.2\"
  • create "C:\server\workspace" directory
  • edit "C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf"
DocumentRoot "C:/server/workspace"
<Directory "C:/server/workspace">
    Options FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>


Install PHP

  • download thread safe PHP 5.3.x installer from http://windows.php.net/download/, for example php-5.3.10-Win32-VC9-x86.msi
  • launch PHP installer
  • default location "C:\Program Files\PHP\"
  • select "Apache 2.2.x Module"
  • Apache configuration is in "C:\Program Files\Apache Software Foundation\Apache2.2\conf\"
  • select "PHP / Script Executable" to be installed
  • select "PHP / Extensions / Multi-Byte" to be installed
  • select "PHP / Extras / PEAR Install" to be installed
  • add index.php to C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>
  • download thread safe PHP 5.3.x zip package from http://windows.php.net/download/, for example php-5.3.10-Win32-VC9-x86.zip
  • extract the zip file over contents of "C:\Progam Files\PHP\" to get missing libs and extensions
  • edit "C:\Program Files\PHP\php.ini", add extension=php_intl.dll line at the end


Verify Apache and PHP configuration

  • restart windows
  • launch cmd.exe as normal user
  • verify php.exe --version prints version information, if not fix system PATH setting to include "C:\Program Files\PHP"
  • create "C:\server\workspace\index.php" file:

<?php
echo phpinfo();

  • open http://127.0.0.1/ in browser and verify all necessary extensions including intl are present
  • delete "C:\server\workspace\index.php"


Install PEAR

  • launch cdm.exe as administrator
cd "C:\Program Files\PHP"
go-pear.bat
  • confirm "system"
  • type 12 and select "C:\Program Files\PHP" directory
  • hit Enter a few times
start PEAR_ENV.reg
  • optionally set proxy server
pear config-set http_proxy my.proxy.is:80
pear upgrade-all


Install PHPUnit

  • launch cdm.exe as administrator
cd "C:\Program Files\PHP"
pear config-set auto_discover 1
pear install pear.phpunit.de/PHPUnit
pear install phpunit/DbUnit


Install PostgreSQL


Install Git and clone Moodle repository

cd /C/server/workspace
git clone git://github.com/moodle/moodle.git
  • close the bash window


Install Moodle

  • create directory "C:\server\moodledata"
  • create directory "C:\server\phpu_moodledata"
  • create file "C:\server\workspace\moodle\config.php":

<?php // Moodle configuration file unset($CFG); global $CFG; $CFG = new stdClass(); $CFG->dbtype = 'pgsql'; $CFG->dblibrary = 'native'; $CFG->dbhost = 'localhost'; $CFG->dbname = 'moodle'; $CFG->dbuser = 'postgres'; $CFG->dbpass = 'YOUR PASSWORD HERE'; $CFG->prefix = 'mdl_'; $CFG->dboptions = array (

 'dbpersist' => 0,
 'dbsocket' => ,

); $CFG->wwwroot = 'http://127.0.0.1/moodle'; $CFG->dataroot = 'C:\\server\\moodledata'; $CFG->passwordsaltmain = 'some random rubbish goes here';

$CFG->debug = (E_ALL | E_STRICT); $CFG->debugdisplay = 1; $CFG->phpunit_prefix = 'phpu_'; $CFG->phpunit_dataroot = 'C:\\server\\phpu_moodledata';

require_once(dirname(__FILE__) . '/lib/setup.php');


Initialise test environment

  • launch cmd.exe as normal user
cd C:\server\workspace\moodle
php admin\tool\phpunit\cli\init.php


Execute all tests

  • launch cmd.exe as normal user
cd C:\server\workspace\moodle
phpunit


Learn more about PHPUnit