-
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
Right now, you can access vanilla Moodle via the default location http://localhost:8888/moodle
, but we want to run our custom code, so we'll add a link to our own code.
- Create a
Sites
folder, clone our Moodle code and set up the data dir in the MAMP directory.
mkdir ~/Sites
cd ~/Sites
git clone git@github.com:ucla/moodle.git ccle
mkdir -m 777 /Applications/MAMP/data/ccle
mkdir -m 777 /Applications/MAMP/data/behat
- Link the newly created Moodle code to MAMP.
ln -s ~/Sites/ccle /Applications/MAMP/ccle
- Setup the configuration file for Moodle.
cd ~/Sites/ccle
ln -s local/ucla/config/shared_dev_moodle-config.php config.php
cp -p config_private-dist.php config_private.php
- Edit
config_private.php
and set/add the following:
$CFG->dbname = 'ccle';
$CFG->wwwroot = 'http://localhost:8888/ccle';
$CFG->dataroot = '/Applications/MAMP/data/ccle';
- Create the
ccle
database.
mysql -u root --password=root --execute="CREATE DATABASE ccle DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;"
mysql -u root --password=root --execute="GRANT ALL PRIVILEGES ON ccle.* TO 'ccle'@'localhost' IDENTIFIED BY 'test'; FLUSH PRIVILEGES;"
- Go to
http://localhost:8888/ccle/install.php
and install Moodle. Once installed, you can start using your new Moodle instance viahttp://localhost:8888/ccle
, while still being able to access vanilla Moodle athttp://localhost:8888/moodle
.
Assuming you have a site that's now working, add the following to your config_private.php
:
$CFG->behat_prefix = 'bht_';
$CFG->behat_dataroot = '/Applications/MAMP/data/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/ccle
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 /Applications/MAMP/data/behat/behat/behat.yml
Moodle has generated the Behat yaml file, and given you the command to execute. You're all set!