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
(48 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Moodle 2.3}}
{{Moodle 2.3}}


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


==Before you start==
==Before you start==


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:
If you see '''launch as administrator''' below 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.
* 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.
* 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".
* Open file Explorer and type "C:\windows\system32", then find cmd.exe and right click and select "Run as administrator".
* Start the Command Prompt as Administrator by clicking Start, All programs and Accessories, then right-click on Command Prompt link and selecting "Run as Administrator" from the context menu.
* Temporarily turn off UAC.
* 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". Use "C:\Program Files (x86)" instead of "C:\Program Files" in 64bit Windows.
It is possible to paste text into command line (cmd.exe) by right-clicking inside the terminal window selecting "Paste".


==Install Apache 2.2==
==Install PHP 5.4==


* download Apache server installer from http://httpd.apache.org/download.cgi, for example httpd-2.2.22-win32-x86-openssl-0.9.8t.msi
* Create a "C:\server\" directory.
* install to default location "C:\Program Files\Apache Software Foundation\Apache2.2\"
* Download the latest '''thread safe''' PHP 5.4.x installer from http://windows.php.net/download/ (for example php-5.4.26-Win32-VC9-x86.zip)
* create "C:\server\workspace" directory
* Extract the file into "C:\server\PHP\"
* edit "C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf"


  DocumentRoot "C:/server/workspace"
==Install Apache 2.4==
  <Directory "C:/server/workspace">
 
* Download VC10 SP1 vcredist_x86.exe from http://www.microsoft.com/en-us/download/details.aspx?id=8328 and install it
* Download the Apache server from http://www.apachelounge.com/download/ (for example httpd-2.4.9-win32-VC11.zip)
* Unzip the archive to "C:\server\", this should create "C:\server\Apache2\" directory
 
==Configure Apache and PHP==
 
* Set up PATH ENVIRONMENT (System Properties | Advanced | Environment Variables | System variables | Path):
 
;c:\server\PHP;c:\server\Apache24;C:\server\Apache24\bin;
 
* Create a "C:\server\workspace" directory and make it read/write for everybody.
* Edit the "C:\server\Apache24\conf\httpd.conf" file so that it includes the following.
 
ServerRoot "c:/server/Apache24"
 
LoadModule php5_module "c:/server/PHP/php5apache2_4.dll"
AddHandler application/x-httpd-php .php
 
# configure the path to php.ini
PHPIniDir "C:/server/PHP"
 
  DocumentRoot "c:/server/workspace"
  <Directory "c:/server/workspace">
     Options FollowSymLinks
     Options FollowSymLinks
     AllowOverride All
     AllowOverride All
Line 29: Line 52:
  </Directory>
  </Directory>


==Install PHP==
DirectoryIndex index.php index.html
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.
 
* Copy "C:\server\PHP\php.ini-developer" to "C:\server\PHP\php.ini" and add
 
extension_dir = "C:\server\PHP\ext"
 
extension=php_curl.dll
extension=php_gd2.dll
extension=php_intl.dll
extension=php_mbstring.dll
extension=php_mysqli.dll
extension=php_openssl.dll
extension=php_soap.dll
extension=php_pgsql.dll
extension=php_xmlrpc.dll


* download '''thread safe''' PHP 5.3.x installer from http://windows.php.net/download/, for example php-5.3.10-Win32-VC9-x86.msi
date.timezone = "Europe/Prague"
* launch PHP installer
** install to 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>
* Register apache service
    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
c:\server\Apache24\bin\httpd -k install
* 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


==Verify Apache and PHP configuration==
==Verify Apache and PHP configuration==


* restart windows
* Restart windows.
* launch cmd.exe as normal user
* Launch cmd.exe as a normal user.
* verify <code>php.exe --version</code> prints version information, if not fix system PATH setting to include "C:\Program Files\PHP"
* Verify <code>php.exe --version</code> prints version information, if not fix system PATH setting to include "C:\server\PHP".
* create "C:\server\workspace\index.php" file:
** Right-click on My Computer
** Select Properties
** If you are using Windows Vista or beyond, click "Advanced system settings". Windows XP users can skip this step.
** On the Advanced tab, click "Environment Variables".
** Find the Path variable under "System variables" and edit it.
** Add your PHP directory path to this variable.
** Close all System property windows for this to take effect.
** Restart any cmd.exe terminals to start using the new Path value.
* Create "C:\server\workspace\index.php" file with the following content.


<code php>
<code php>
Line 62: Line 94:
</code>
</code>


* open http://127.0.0.1/ in browser and verify all necessary extensions including intl are present
* Open http://127.0.0.1/ in you browser and verify all necessary extensions, including intl, are present in the list shown.
* delete "C:\server\workspace\index.php"
* Delete "C:\server\workspace\index.php".


==Install PEAR==
==Install PostgreSQL==
launch cmd.exe '''as administrator'''
* Download PostgreSQL from http://www.enterprisedb.com/products-services-training/pgdownload#windows (for example postgresql-9.3.4-1-windows.exe).
 
* Install PostgreSQL with some default locale using UTF-8 (skip the StackBuilder).
cd "C:\Program Files\PHP"
* Launch PgAdmin III - double click on "PostgreSQL 9.3 (localhost:5432)", right-click on "Databases (1)" and create new database called "moodle".
go-pear.bat
 
* confirm "system"
* type 12 and select "C:\Program Files\PHP" directory
* hit Enter a few times


start PEAR_ENV.reg
==Install MariaDB==
 
* Download MariaDB from https://downloads.mariadb.org (for example mariadb-5.5.36-win32.msi).
* optionally set proxy server
* Install MariaDB, use UTF-8 as default server's character set.
 
* Create ''moodle'' database.
pear config-set http_proxy my.proxy.is:80
 
* upgrade all PEAR packages
 
pear upgrade-all
 
==Install PHPUnit==
launch cmd.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==
* 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==
==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
* Download git from http://www.git-scm.com/downloads (for example Git-1.9.0-preview20140217.exe).
* install git
* Install git, use '''Checkout as-is, commit Unix-style line endings'''
* start "Git bash" (icon on desktop)
* Start "Git bash" (icon on desktop) and clone Moodle using the following commands.


  cd /C/server/workspace
  cd /C/server/workspace
  git clone git://github.com/moodle/moodle.git
  git clone git://github.com/moodle/moodle.git


* close the bash window
* Close the bash window.


==Install Moodle==
==Install Moodle==
* create directory "C:\server\moodledata"
* Create a directory called "C:\server\moodledata", make it read/write for everybody.
* create directory "C:\server\phpu_moodledata"
* Create a directory called "C:\server\phpu_moodledata", make it read/write for everybody.
* create file "C:\server\workspace\moodle\config.php":
* Create a file "C:\server\workspace\moodle\config.php" with the following content:


<code php>
<code php>
Line 123: Line 132:
$CFG->dbname    = 'moodle';
$CFG->dbname    = 'moodle';
$CFG->dbuser    = 'postgres';
$CFG->dbuser    = 'postgres';
$CFG->dbpass    = 'YOUR PASSWORD HERE';
$CFG->dbpass    = 'PUT POSTGRESQL PASSWORD HERE';
$CFG->prefix    = 'mdl_';
$CFG->prefix    = 'mdl_';
$CFG->dboptions = array (
$CFG->dboptions = array (
Line 129: Line 138:
   'dbsocket' => '',
   'dbsocket' => '',
);
);
/*
// Uncomment to test MySQL compatibility.
$CFG->dbtype    = 'mysqli';
$CFG->dblibrary = 'native';
$CFG->dbhost    = 'localhost';
$CFG->dbname    = 'moodle';
$CFG->dbuser    = 'root';
$CFG->dbpass    = 'PUT MARIADB PASSWORD HERE';
$CFG->prefix    = 'mdl_';
$CFG->dboptions = array (
  'dbpersist' => 0,
  'dbsocket' => '',
);
*/
$CFG->wwwroot  = 'http://127.0.0.1/moodle';
$CFG->wwwroot  = 'http://127.0.0.1/moodle';
$CFG->dataroot  = 'C:\\server\\moodledata';
$CFG->dataroot  = 'C:\\server\\moodledata';
Line 141: Line 166:
</code>
</code>
* optionally go to http://127.0.0.1/moodle and finish standard installation
* Open browser and go to http://127.0.0.1/moodle and finish standard installation.
 
==Install Composer dependency manager==
 
* Download '''Composer-Setup.exe''' from http://getcomposer.org/download/ and install it
 
==Install PHPUnit==
 
* Launch cmd.exe as normal user and run the following command:
 
cd C:\server\workspace\moodle
composer install --dev


==Initialise test environment==
==Initialise test environment==
launch cmd.exe as normal user
Launch cmd.exe as normal user and run the following command:
 
  cd C:\server\workspace\moodle
  cd C:\server\workspace\moodle
  php admin\tool\phpunit\cli\init.php
  php admin\tool\phpunit\cli\init.php


==Execute all tests==
==Execute all tests==
launch cmd.exe as normal user
Launch cmd.exe as normal user and run the following command:
 
  cd C:\server\workspace\moodle
  cd C:\server\workspace\moodle
  phpunit
  vendor\bin\phpunit


==Useful tools==


* PHPStorm IDE - http://www.jetbrains.com/phpstorm/download/
* SourceTree Git UI - http://www.sourcetreeapp.com


[[Category:PHPUnit]]
[[Category:Unit testing]]

Revision as of 02:04, 28 March 2014

Moodle 2.3


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

Before you start

If you see launch as administrator below 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".
  • Start the Command Prompt as Administrator by clicking Start, All programs and Accessories, then right-click on Command Prompt link and selecting "Run as Administrator" from the context menu.
  • Temporarily turn off UAC.

It is possible to paste text into command line (cmd.exe) by right-clicking inside the terminal window selecting "Paste".

Install PHP 5.4

  • Create a "C:\server\" directory.
  • Download the latest thread safe PHP 5.4.x installer from http://windows.php.net/download/ (for example php-5.4.26-Win32-VC9-x86.zip)
  • Extract the file into "C:\server\PHP\"

Install Apache 2.4

Configure Apache and PHP

  • Set up PATH ENVIRONMENT (System Properties | Advanced | Environment Variables | System variables | Path):
;c:\server\PHP;c:\server\Apache24;C:\server\Apache24\bin;
  • Create a "C:\server\workspace" directory and make it read/write for everybody.
  • Edit the "C:\server\Apache24\conf\httpd.conf" file so that it includes the following.
ServerRoot "c:/server/Apache24"
LoadModule php5_module "c:/server/PHP/php5apache2_4.dll"
AddHandler application/x-httpd-php .php
# configure the path to php.ini
PHPIniDir "C:/server/PHP"
DocumentRoot "c:/server/workspace"
<Directory "c:/server/workspace">
    Options FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>
DirectoryIndex index.php index.html
  • Copy "C:\server\PHP\php.ini-developer" to "C:\server\PHP\php.ini" and add
extension_dir = "C:\server\PHP\ext"
extension=php_curl.dll
extension=php_gd2.dll
extension=php_intl.dll
extension=php_mbstring.dll
extension=php_mysqli.dll
extension=php_openssl.dll
extension=php_soap.dll
extension=php_pgsql.dll
extension=php_xmlrpc.dll
date.timezone = "Europe/Prague"
  • Register apache service
c:\server\Apache24\bin\httpd -k install

Verify Apache and PHP configuration

  • Restart windows.
  • Launch cmd.exe as a normal user.
  • Verify php.exe --version prints version information, if not fix system PATH setting to include "C:\server\PHP".
    • Right-click on My Computer
    • Select Properties
    • If you are using Windows Vista or beyond, click "Advanced system settings". Windows XP users can skip this step.
    • On the Advanced tab, click "Environment Variables".
    • Find the Path variable under "System variables" and edit it.
    • Add your PHP directory path to this variable.
    • Close all System property windows for this to take effect.
    • Restart any cmd.exe terminals to start using the new Path value.
  • Create "C:\server\workspace\index.php" file with the following content.

<?php
echo phpinfo();

  • Open http://127.0.0.1/ in you browser and verify all necessary extensions, including intl, are present in the list shown.
  • Delete "C:\server\workspace\index.php".

Install PostgreSQL

  • Download PostgreSQL from http://www.enterprisedb.com/products-services-training/pgdownload#windows (for example postgresql-9.3.4-1-windows.exe).
  • Install PostgreSQL with some default locale using UTF-8 (skip the StackBuilder).
  • Launch PgAdmin III - double click on "PostgreSQL 9.3 (localhost:5432)", right-click on "Databases (1)" and create new database called "moodle".

Install MariaDB

  • Download MariaDB from https://downloads.mariadb.org (for example mariadb-5.5.36-win32.msi).
  • Install MariaDB, use UTF-8 as default server's character set.
  • Create moodle database.

Install Git and clone Moodle repository

  • Download git from http://www.git-scm.com/downloads (for example Git-1.9.0-preview20140217.exe).
  • Install git, use Checkout as-is, commit Unix-style line endings
  • Start "Git bash" (icon on desktop) and clone Moodle using the following commands.
cd /C/server/workspace
git clone git://github.com/moodle/moodle.git
  • Close the bash window.

Install Moodle

  • Create a directory called "C:\server\moodledata", make it read/write for everybody.
  • Create a directory called "C:\server\phpu_moodledata", make it read/write for everybody.
  • Create a file "C:\server\workspace\moodle\config.php" with the following content:

<?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 = 'PUT POSTGRESQL PASSWORD HERE'; $CFG->prefix = 'mdl_'; $CFG->dboptions = array (

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

);

/* // Uncomment to test MySQL compatibility. $CFG->dbtype = 'mysqli'; $CFG->dblibrary = 'native'; $CFG->dbhost = 'localhost'; $CFG->dbname = 'moodle'; $CFG->dbuser = 'root'; $CFG->dbpass = 'PUT MARIADB 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');

Install Composer dependency manager

Install PHPUnit

  • Launch cmd.exe as normal user and run the following command:
cd C:\server\workspace\moodle
composer install --dev

Initialise test environment

Launch cmd.exe as normal user and run the following command:

cd C:\server\workspace\moodle
php admin\tool\phpunit\cli\init.php

Execute all tests

Launch cmd.exe as normal user and run the following command:

cd C:\server\workspace\moodle
vendor\bin\phpunit

Useful tools