-
Notifications
You must be signed in to change notification settings - Fork 1
Behat for mac
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.
Go to Moodle4Mac and download the MAMP version of Moodle you are developing for and install like any other OSX app. Then start running the MAMP application. You may get a notice saying that the application is from an unrecognized developer. To get pass this message, right click the application and click "Open", then "Okay" on the message that appears.
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.5.3/bin/php foobar.php
while you're running your Behat scripts. In your ~/.bash_profile
(you may need to create it) add the following:
export PATH=/Applications/MAMP/Library/bin:/Applications/MAMP/bin/php/php5.5.3/bin:$PATH
Depending on your version of MAMP, those paths may differ slightly. You will need to reload your profile by running the following command:
source ~/.bash_profile
Check if you are now accessing the MAMP versions of PHP and MySQL and can start using MySQL:
$ which php
/Applications/MAMP/bin/php/php5.5.3/bin/php
$ which mysql
/Applications/MAMP/Library/bin/mysql
$ mysql -u root --password=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
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.
mkdir ~/Sites
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 specimen: https://test.ccle.ucla.edu/vagrant/new_moodle_instance.sql
That Moodle sql dump requires that your Moodle config_private.php
file contains this salt $CFG->passwordsaltmain = 'a_very_long_salt_string';
. Your config should look something like:
$CFG->wwwroot = 'http://localhost:8888/moodle';
$CFG->dataroot = '/Users/alfonso/Sites/moodledata';
$CFG->admin = 'admin';
$CFG->directorypermissions = 0777;
$CFG->passwordsaltmain = 'a_very_long_salt_string';
The SQL dump is updated for Moodle 2.5.2, so if you're running that codebase you will not have to run any site upgrades.
Assuming you have a site that's now working, add the following to your config_private.php
:
$CFG->behat_prefix = 'bht_';
$CFG->behat_dataroot = '/Users/alfonso/Sites/moodledata/behat';
$CFG->behat_switchcompletely = true;
Those config values set up your Moodle Behat environment. Moodle will generate a new set of tables for the Behat environment with the given prefix. We're also directing Moodle to completely switch off the site to 'acceptance testing' mode. We're also telling Moodle where to put all the Behat generated files in the moodledata dir.
PHP Composer is required to download the Behat dependencies. To install PHP Composer go to your Moodle project folder:
cd ~/Sites/moodle
curl -sS http://getcomposer.org/installer
That's it!
You now need to switch to Behat mode. If it's your first time running this, Composer will download all the required dependencies.
php admin/tool/behat/cli/init.php
...
...
...
Acceptance tests environment enabled, to run the tests use:
vendor/bin/behat --config /Users/alfonso/Sites/moodledata/behat/behat/behat.yml
Moodle has generated the Behat yaml file, and given you the command to execute. You're all set!