tools and tips for moodle developers - #mootus16

32
Tools and Tips for Moodle Developers Dan Poltawski Integrator Moodle HQ @dan_p the world’s open source learning platform #mootus16

Upload: dan-poltawski

Post on 14-Jan-2017

938 views

Category:

Technology


4 download

TRANSCRIPT

Page 1: Tools and Tips for Moodle Developers - #mootus16

Tools and Tips for Moodle Developers

Dan PoltawskiIntegrator

Moodle HQ

@dan_p

the world’s open source learning platform

#mootus16

Page 2: Tools and Tips for Moodle Developers - #mootus16

$CFG->debug = (E_ALL | E_STRICT); // DEBUG_DEVELOPER.

$CFG->debugdisplay = 1; // (unless you tail logs)

$CFG->cachejs = false; // But beware of browser cache!

$CFG->debugstringids = true; // With strings=1 url param.

$CFG->debugusers = ‘2,3,10’; // List of users ids

Debugging: config.php settings

the world’s open source learning platform

Page 3: Tools and Tips for Moodle Developers - #mootus16

// Beginner. echo "Course ID: $course->id”;

// Intermediate. print_object($SESSION);

// Advanced. debugging('a stack trace too!', DEBUG_DEVELOPER); if ($CFG->debugdeveloper) { echo '[..] some diagnostic code.'; }

// Wizard. // (Uses xdebug and variable introspection)

Stages of Moodle printf() debugging (PHP)

the world’s open source learning platform

Page 4: Tools and Tips for Moodle Developers - #mootus16

Stages of Moodle printf() debugging (JS)// Beginner: alert('courseid is: ' + course.id);

// Intermediate: console.dir(course);

// Advanced: Y.log('Info example in YUI module', 'info');

define(['core/log'], function(log) { log.info('Info example from AMD Module.'); });

// Wizard: // (uses web inspector, variable introspection)

the world’s open source learning platform

Page 5: Tools and Tips for Moodle Developers - #mootus16

Performance debugging

the world’s open source learning platform

$CFG->perfdebug = 15; // First step.

Page 6: Tools and Tips for Moodle Developers - #mootus16

xhprof

the world’s open source learning platform

Page 7: Tools and Tips for Moodle Developers - #mootus16

xhprof

the world’s open source learning platform

Page 8: Tools and Tips for Moodle Developers - #mootus16

the world’s open source learning platform

PHPUnitUseful CLI Options

Filtering

vendor/bin/phpunit --filter block_online_users

vendor/bin/phpunit --testsuite block_online_users_testsuite

vendor/bin/phpunit blocks/online_users/tests/online_users_test.php

Coverage

vendor/bin/phpunit --coverage-html=coverage --filter block_online_users

Page 9: Tools and Tips for Moodle Developers - #mootus16

PHPUnit

Test authoring tips:

• Use most specific assertion possible

• Make use of @dataProvider to

reduce duplication and get better

errors

• Remember we have data generators

to simplify setup code

/** * Data provider for test_get_real_size(). * * @return array An array of arrays contain test data */ public function data_for_test_get_real_size() { return array( array('8KB', 8192), array('8G', 8589934592), ); } /** * @dataProvider data_for_test_get_real_size */ public function test_get_real_size($input, $expectedbytes) { $this->assertEquals($expectedbytes,get_real_size($input)); }

There was 1 failure:

1) core_setuplib_testcase::test_get_real_size with data set #0 ('8KB', 8193) Failed asserting that 8192 matches expected 8193.

the world’s open source learning platform

Page 10: Tools and Tips for Moodle Developers - #mootus16

Behat

Useful CLI Options:

Filtering

—tags @block_online_users

—name “Add the online users on course

page and see other logged in users”

Rerun

—rerun

Profiles

—profile chrome

$CFG->behat_profiles = array(

'phantomjs' => array( 'browser' => ‘chrome’,

'wd_host' => ‘http://10.0.0.3:4444/wd/hub', ));

the world’s open source learning platform

Page 11: Tools and Tips for Moodle Developers - #mootus16

BehatTips:

• Solutions for headless running:

• All platforms: Phantom JS

• Linux: Xvfb - X virtual framebuffer

• Mac: Fast user switching - with background user

• $x() in web developer console extremely useful for constructing

XPath queries

the world’s open source learning platform

Page 12: Tools and Tips for Moodle Developers - #mootus16

Grunt• grunt

• grunt watch

• grunt css

• grunt js

• grunt amd

• grunt yui

the world’s open source learning platform

Page 13: Tools and Tips for Moodle Developers - #mootus16

• Analysing code for potential errors

• Good feedback loop

• Ensure consistency

• Integrate with your development workflow FTW!

Code Linting

the world’s open source learning platform

Page 14: Tools and Tips for Moodle Developers - #mootus16

• Code-checker (local_codechecker)

• Available from Plugins Directory

• Uses PHP Code-sniffer underneath

• Integrations configured with path to local_codechecker/moodle/

location

Moodle Code Linters: PHP

the world’s open source learning platform

Page 15: Tools and Tips for Moodle Developers - #mootus16

• ESLint

• New in Moodle 3.2 (MDL-52127), replaced jshint

• grunt js: checks for errors on AMD modules and YUI modules

• Integrations usually work without configuration ( eslintrc bundled)

Moodle Code Linters: Javascript

the world’s open source learning platform

Page 16: Tools and Tips for Moodle Developers - #mootus16

• Packages: linter

• linter-phpcs

• linter-eslint

• Config:

"linter-phpcs":

codeStandardOrConfigFile: “/path/to/moodle-

Lint in your editor: Atom

the world’s open source learning platform

Page 17: Tools and Tips for Moodle Developers - #mootus16

• Package: syntastic

• vimrc:let g:syntastic_javascript_checkers = ['eslint']

let g:syntastic_php_checkers = ['php', 'phpcs']

let g:syntastic_php_phpcs_args='--standard="/

path/to/moodle-local_codechecker/moodle/"'

Lint in your editor: vim

the world’s open source learning platform

Page 18: Tools and Tips for Moodle Developers - #mootus16

Lint in your editor: PHPStorm

Configured in Editor > Inspections:

• PHP > PHP Code Sniffer Validation

• Select ‘Custom’ coding standard and

choose path to local_codechecker/

moodle/

• Javascript > Code Quality Tools >

ESLint

the world’s open source learning platform

Page 19: Tools and Tips for Moodle Developers - #mootus16

• SublimeLinter

• SublimeLinter-phpcs

• SublimeLinter-contrib-eslint

Sublime

"linters": {

"eslint": {

"@disable": false,

"args": [],

"excludes": []

},

"phpcs": {

"@disable": false,

"args": [],

"excludes": [],

"standard": “/path/to/moodle-local_codechecker/moodle/"

}}the world’s open source learning platform

Page 20: Tools and Tips for Moodle Developers - #mootus16

Lint in your editor….I’m sure their is an emacs integration too 🙄😘

the world’s open source learning platform

Page 21: Tools and Tips for Moodle Developers - #mootus16

the world’s open source learning platform

“The goal of this project is to facilitate the running of

tests and code analysis tools against a Moodle plugin in

Travis CI.”

• https://github.com/moodlerooms/moodle-plugin-ci

• Created by Mark Nielsen (Moodlerooms)

• Extremely simple and comprehensive way to add CI to

your plugin

moodle-plugin-ci

Page 22: Tools and Tips for Moodle Developers - #mootus16

the world’s open source learning platform

moodle-plugin-ci

Page 23: Tools and Tips for Moodle Developers - #mootus16

the world’s open source learning platform

“A collection of tools meant to make developers' lives easier.”

• https://github.com/FMCorz/mdk

• Created by Frédéric Massart (Moodle HQ)

• Python tools - works with Linux and Mac

• (Windows patches welcomed!)

• Developed for core development tasks, but useful for non-core

work too

Moodle Development Kit (mdk)

Page 24: Tools and Tips for Moodle Developers - #mootus16

• mdk create

• mdk upgrade

• mdk install

• mdk run

• mdk remove

MDK: Instance management

the world’s open source learning platform

Page 25: Tools and Tips for Moodle Developers - #mootus16

• mdk phpunit

• init

• mdk behat

• init

• fail dumps

• seleneium server start

MDK: Testing

the world’s open source learning platform

Page 26: Tools and Tips for Moodle Developers - #mootus16

• mdk fix

• mdk pull

• mdk push

MDK: Fixing issues

the world’s open source learning platform

Page 27: Tools and Tips for Moodle Developers - #mootus16

• mdk fix

• mdk pull

• mdk push

MDK: Fixing continued

the world’s open source learning platform

Page 28: Tools and Tips for Moodle Developers - #mootus16

the world’s open source learning platform

Email testing: config options

// Disable all Email. $CFG->noemailever = true;

// Divert all outgoing emails to this address to test and debug emailing features $CFG->divertallemailsto = '[email protected]';

// Except for certain email addresses you want to let through for testing. Accepts // a comma separated list of regexes. $CFG->divertallemailsexcept = '[email protected], fred(\+.*)[email protected]';

Page 29: Tools and Tips for Moodle Developers - #mootus16

Email testing: mailcatcher

$CFG->smtphosts = 'localhost:1025';

$ gem install mailcatcher $ mailcatcher Starting MailCatcher ==> smtp://127.0.0.1:1025 ==> http://127.0.0.1:1080 *** MailCatcher runs as a daemon by default. Go to the web interface to quit.

the world’s open source learning platform

Page 30: Tools and Tips for Moodle Developers - #mootus16

the world’s open source learning platform

Accessibility testing• ChromeVox

• Chrome Extension - Quick and straight forward to get started

• Not JAWS but better than nothing

• Accessibility Developer Tools - Accessibility audit useful

Page 31: Tools and Tips for Moodle Developers - #mootus16

git• git log

• git blame

• git bisect

• https://github.com/dmonllao/who-broke-it

• git log --author=Damyon --grep="services"

the world’s open source learning platform

Page 32: Tools and Tips for Moodle Developers - #mootus16

Questions?

@dan_p

the world’s open source learning platform