Skip to content
Alfonso Roman edited this page Nov 13, 2013 · 21 revisions

Setting up Behat environment for Mac OSX

This guide will require you to download Moodle4Mac which is a copy of Moodle that ships with a copy of MAMP. Alternatively you can download MAMP on its own, but the version that ships with Moodle seems to be configured with the proper PHP modules out of the box. We will set this up to run our Moodle codebase right next to the vanilla Moodle install. Having a vanilla Moodle install also serves as a reference of what a passing test for Behat or PHPUnit should look like.

Setting up MAMP

Download Moodle4Mac and install like any other OSX app.

Adding PHP and MySQL to path

To make it easier to access MAMP's PHP and MySQL binaries via command line, we'll add them to our system path. This is so that you can type php foobar.php instead of /Applications/MAMP/bin/php/php5.4.10/bin/php foobar.php while you're running your Behat scripts. In your ~/.bash_profile add the following:

export PATH=/Applications/MAMP/Library/bin/:/Applications/MAMP/bin/php/php5.4.10/bin/:$PATH  

Depending on your version of MAMP, those paths may differ slightly. You will need to reload your profile, you can run the following command:

source ~/.bash_profile

Check if you can access PHP and MySQL

$ php -v
PHP 5.4.10 (cli) (built: Jan 21 2013 15:12:32) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
$ mysql -u root -p root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.29 Source distribution
...

If you are having issues, here is some reference material: http://www.metaltoad.com/blog/getting-command-line-access-php-and-mysql-running-mamp-osx

Setting up Moodle

You can access vanilla Moodle via the default port localhost:8888, but we want to run our custom code, so we'll tweak MAMP's preferences to change Apache's document root. Open your MAMP preferences and select the Apache tab. Change your document root to something that's more easily accessible, perhaps in your home folder like so /Users/alfonso/Sites. This assumes I have a directory named Sites in my home folder.

Go to your Sites folder and we'll clone our Moodle code and set up the moodledata dir.

cd ~/Sites
git clone git@github.com:ucla/moodle.git
mkdir moodledata
chmod 777 moodledata

You will now have a local Moodle instance that you can access via localhost:8888/moodle. You will need to set up a database and config file. I've found it easier to simply import a pre-loaded database dump than to have Moodle go through the install process. Here is a fine speciment: https://test.ccle.ucla.edu/vagrant/new_moodle_instance.sql

Clone this wiki locally