Date post: | 14-Jan-2017 |
Category: |
Technology |
Upload: | dan-poltawski |
View: | 940 times |
Download: | 4 times |
Tools and Tips for Moodle Developers
Dan PoltawskiIntegrator
Moodle HQ
@dan_p
the world’s open source learning platform
#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
// 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
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
Performance debugging
the world’s open source learning platform
$CFG->perfdebug = 15; // First step.
xhprof
the world’s open source learning platform
xhprof
the world’s open source learning platform
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
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
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
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
Grunt• grunt
• grunt watch
• grunt css
• grunt js
• grunt amd
• grunt yui
the world’s open source learning platform
• 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
• 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
• 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
• 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
• 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
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
• 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
Lint in your editor….I’m sure their is an emacs integration too 🙄😘
the world’s open source learning platform
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
the world’s open source learning platform
moodle-plugin-ci
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)
• mdk create
• mdk upgrade
• mdk install
• mdk run
• mdk remove
MDK: Instance management
the world’s open source learning platform
• mdk phpunit
• init
• mdk behat
• init
• fail dumps
• seleneium server start
MDK: Testing
the world’s open source learning platform
• mdk fix
• mdk pull
• mdk push
MDK: Fixing issues
the world’s open source learning platform
• mdk fix
• mdk pull
• mdk push
MDK: Fixing continued
the world’s open source learning platform
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]';
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
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
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
Questions?
@dan_p
the world’s open source learning platform