Takeaways To Advance You Moodle Development Courtesy Of Dan P. And #MootUS16

3185
Takeaways To Advance You Moodle Development Courtesy Of Dan P. And #MootUS16

Moodle HQ’s senior developer and integrator Dan Poltawski gave this talk at MoodleMoot US, just weeks ago. It gives both novice and advanced “moodlevelopers” Tools and Tips to invigorate our daily practice.

WIRIS

Debugging with config.php hidden settings

There are advanced debugging settings in Moodle beyond the administrator settings. Look in the config.php file for section 7, “Settings for development servers“. Focus on debug-related configuration variables, such as $CFG->display$CFG->debugdisplay and $CFG->debugusers.

Another set of variables relate to performance of your Moodle:

define('MDL_PERF', true);
define('MDL_PERFDB', true);
define('MDL_PERFTOLOG', true);
define('MDL_PERFTOFOOT', true);

When you include this variables in config.php, the footer in Moodle pages will include performance info such as the time it took to load the page and the amount of memory used.

Personal takeaway: Freshen up on Moodle debugging. Again.

Profiling with XHProf

To precisely identify performance bottlenecks in your Moodle, Dan seems to recommend XHProf over the other available profiling tools. It is easy to set up and it has little impact on memory, which can make it preferable even if it is not as detailed as XDebug. It also has the ability to track live servers in addition to development environments.

Set up XHProf and get started on Moodle Performance Testing. It is trickier to do in a Windows than a Linux server as it is often the case.

More of XHProf:

Unit Testing with Framework: PHPUnit

For writing unit tests for Moodle, PHPUnit is the way to go. Allowing you to separate production code from testing benchmarks, PHPUnit is crazy easy to set up and start using. You can write your first PHPUnit test in a matter of minutes. It’s all about knowing what you expect your code to do and setting up the assertEquals() function accordingly.

PHPUnit allows for authoring, filtering and coverage analysis. Another interesting feature is @dataProvider to write a large number of data input test, over which PHPUnit will automatically iterate.

Set up PHPUnit once, have modular, authored testing units for a (production) lifetime.

Behavior Driven Development with Behat

Behavior-Driven Development has been for some time, but if it has gained traction lately it only has Behat to thank. The idea is attractive, in particular for those on the business end: using English-like syntax in sentences, a program builds a scenario comprised of assumptions, behaviors and expected outcomes. Behat is a test scripting tool for PHP that allows you to do just that.

Without a graphical interface, some ‘headless’ outcome tools can help the task of comparing expected to realized outcomes. Dan mentions PhantomJS (for all systems), Xvfb (Linux) and Fast User Switching (Mac).

It is not a bad idea to spend a little more on Behat for some direction and perspective, before jumping into coding.

Automate everything with Grunt

Grunt runs repetitive fron-end activities in schedule, most notably SASS to CSS files, image size optimization,  and concatenation, minification and uglification  of CSS and JavaScript files. But did you now you that you don’t have to stop and restart Grunt every time you make any edits? The watch plugin makes Grunt alert for changes to incorporate into the next iteration of tasks, or automatically if you wish so.

Linting with Code-Checker (PHP) and ESHint (JavaScript)

I can’t help it. When I read it, the word ‘lint’ takes me back to a spring cleaning scenario, removing dust and little fibers from wooden furniture.

Code-Checker is available as a Moodle plugin.

ESLint replaces JSHint as default in Moodle 3.2

Be sure to add Lint add-ons to your IDE. Dan shows options for Atom, vim, PHPStorm and Sublime.

More tools, briefly mentioned by Dan:


Course Merchant

This Moodle Practice related post is made possible by: Course Merchant, the Moodle shopping cart for selling courses. Click here to learn more.


Spark the conversation below!