Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated .travis.yml to support Moodlerooms plugin #119

Merged
merged 3 commits into from
Jul 3, 2017
Merged

Updated .travis.yml to support Moodlerooms plugin #119

merged 3 commits into from
Jul 3, 2017

Conversation

mikemcgowan
Copy link
Contributor

I have now updated the .travis.yml file to support the Moodlerooms Travis plugin.

See #117

This wasn't straightforward because this plugin executes its own PHPUnits outside of the Moodle PHPUnit test environment. (This should probably be changed so that this plugin's PHPUnits are executable within the wider Moodle PHPUnit test environment. Then, the moodle-plugin-ci phpunit item can be commented-in in .travis.yml and the $ORIG hack removed - see below.)

To avoid the Moodlerooms Travis plugin from linting the Composer packages required by this plugin, I had to cache the original working directory of the plugin (as $ORIG). As the very last item in the Travis build, after all the Moodlerooms stuff is finshed, this plugin's Composer packages are installed and then its PHPUnits ran (independently from the Moodle PHPUnit test environment).

The build reaches the end successfully but of course, there are many errors because the code doesn't currently lint to the Moodle coding style.

However, the second two of these three items pass:

    - moodle-plugin-ci codechecker
    - moodle-plugin-ci validate
    - moodle-plugin-ci savepoints

The plugin's own PHPUnits also pass, as previously (of which there are currently 71 tests, 2304 assertions).

@ryasmi
Copy link
Member

ryasmi commented Jun 14, 2017

Nice @mikemcgowan

@mikemcgowan
Copy link
Contributor Author

@ryansmith94 any word on getting this merged?

ryasmi
ryasmi previously requested changes Jun 28, 2017
Copy link
Member

@ryasmi ryasmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy for this to be merged once all of the code checker issues have been resolved and my code comments have been addressed 👍

- moodle-plugin-ci install

script:
# - moodle-plugin-ci phplint
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for commenting out each of these lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which? Specifically moodle-plugin-ci phpcpd and moodle-plugin-ci phpmd? I suppose, in the first instance, I wanted to get a smaller subset of the available Moodlerooms stuff passing - in particular moodle-plugin-ci codechecker so the code lints to Moodle's own standard.

At a later date, once the Travis build is passing against the Moodlerooms plugins that are currently commented-in, some of the additional Moodlerooms plugins could also be commented in, and any issues then fixed. I think the phpcpd (copy/paste detector) and phpmd (mess detector) are probably very useful checks to include, in the long run, but as there's going to be a tonne of codechecker failures to fix first, I suppose it's arguably better to do each plugin at a time?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, this makes a lot of sense. Yeah we'll enable one bit at a time. I agree those bits should be useful.

.travis.yml Outdated
# - moodle-plugin-ci phplint
# - moodle-plugin-ci phpcpd
# - moodle-plugin-ci phpmd
- moodle-plugin-ci codechecker
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to run these things locally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as moodle-plugin-ci codechecker goes, it's possible to run phpcs locally against the Moodle coding style by following these instructions.

It's apparently possible to run a Travis build locally so that's possibly a way in which to run the other moodle-plugin-ci items.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. probably wouldn't want to run Travis builds locally though, seems a bit overkill. As long as we can run the code checker locally I'm happy.

env:
global:
- MOODLE_BRANCH=MOODLE_32_STABLE
matrix:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably not needed. I'm fairly certain this exists so that the tests are ran against those DBs but since we test against memory to improve build times this isn't required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment, the existing tests don't run in the context of Moodle's PHPUnit test framework and PHPUnit test database. I appreciate that the existing PHPUnits have been written in such a way that a test database isn't currently required, however, it's a Moodle plugin and its tests should really be executable as part of the Moodle PHPUnit test framework.

It's certainly possible that, in the future, test coverage of functionality that touches the database may benefit from being written (e.g. test coverage of the functionality that processes the queue of unsent statements in the logstore_xapi_log table). In which case, the test database would end up being necessary anyway.

Finally, my guess (I haven't checked this) is that the Moodlerooms stuff relies on Moodle actually being installed, so my guess is that the above probably does have to be there (I've taken the .travis.yml file from here so it's very close to the Moodlerooms distribution file).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok in that case, let's comment one out for now, otherwise we're running 6 builds when we could be running 3.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. Done.

@mikemcgowan
Copy link
Contributor Author

I've pushed another commit which addresses the Moodle coding style everywhere but the lib/ directory.

I'll do the lib/ directory hopefully within the next couple of days.

@mikemcgowan
Copy link
Contributor Author

By the way, as part of this PR, Code Climate should be turned off, but I don't think I can do that myself?

@mikemcgowan
Copy link
Contributor Author

I've now done lib/emitter, just lib/expander and lib/translator to go.

It's fairly time-consuming, though!

@ryasmi
Copy link
Member

ryasmi commented Jun 29, 2017

@mikemcgowan awesome work!!! I imagine this is really time consuming, really appreciate you taking the time to get this done 👍

I will disable code climate.

…ot tests passing under Moodle's PHPUnit test framework
@mikemcgowan
Copy link
Contributor Author

@ryansmith94 I'm pretty sure I've done everything now:

  • I've squashed the PR down to just two commits. The first is just .travis.yml (as I originally pushed when I first opened the PR), the second is everything else that I've done over the last couple of days.
  • All the plugin's code now lints to Moodle's coding style (except the vendor/ directory, obviously!).
  • All the tests that are currently in master also pass here (71 tests, 2304 assertions).
  • I've got the tests working with the Moodle PHPUnit test framework (they still run quite quickly as they don't touch the database). And I've documented this in docs/developers.md.
  • I've moved all the tests into the tests/ directory, because that's where Moodle expects them.

Hopefully, all's good for getting this merged ...

Copy link
Member

@ryasmi ryasmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow @mikemcgowan, you're a legend, this is just awesome and I'm massively impressed! Just got one comment on the .gitignore, but I'm happy to approve this, just want to know where those ignored files are coming from.

@@ -26,10 +26,23 @@ If you've read the [plugin design](design.md) you should understand what each of
- [Moodle to xAPI Translator](https://github.com/LearningLocker/Moodle-xAPI-Translator/blob/master/docs/readme.md#adding-events)
- [xAPI Recipe Emitter](https://github.com/LearningLocker/xAPI-Recipe-Emitter/blob/master/docs/readme.md#adding-events)

##PHPUnit Test Filter
All PHPUnit tests should pass, but if you'd like to only run the tests for specific events, add the 'filter' option.
## PHPUnit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good thinking 👍

.gitignore Outdated
@@ -5,3 +5,4 @@ vendor
classes/log/error_log.txt
composer.phar
.idea/
lib/*/docs/examples/*_test.json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this ignored now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually what is that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These files get generated by some of the PHPUnits. Now that the .php files with tests have been changed to the Moodle standard test filename (i.e. *_test.php) the generated test files have different filenames.

The generation of these JSON files by the PHPUnits was already happening in master, and those automatically generated files have already been committed, e.g. see 1139e3f

I wasn't brave enough to take the decision to remove the existing ones! I thought it was safer/cleaner to .gitignore the new ones with the *_test.json extension.

+$ git diff master | grep -Pi '\$exampleFile'
-        $exampleFile = __DIR__.'/../docs/examples/'.$eventName.'.json';
-        file_put_contents($exampleFile, json_encode($output, JSON_PRETTY_PRINT));
-        $exampleFile = __DIR__.'/../docs/examples/'.$eventName.'.json';
-        file_put_contents($exampleFile, json_encode($output, JSON_PRETTY_PRINT));
-        $exampleFile = __DIR__.'/../docs/examples/'.$eventName.'.json';
-        file_put_contents($exampleFile, json_encode($output, JSON_PRETTY_PRINT));
+        $examplefile = __DIR__ . '/../../../lib/emitter/docs/examples/' . $eventname . '.json';
+        file_put_contents($examplefile, json_encode($output, JSON_PRETTY_PRINT));
+        $examplefile = __DIR__ . '/../../../lib/expander/docs/examples/' . $eventname . '.json';
+        file_put_contents($examplefile, json_encode($output, JSON_PRETTY_PRINT));
+        $examplefile = __DIR__ . '/../../../lib/translator/docs/examples/' . $eventname . '.json';
+        file_put_contents($examplefile, json_encode($output, JSON_PRETTY_PRINT));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. You've highlighted a small issue, actually, with the generation of those JSON files. They're not actually supposed to have the _test extension:

    protected function create_example_file($output) {
        $classarray = explode('\\', get_class($this));
        $eventname = str_replace('Test', '', array_pop($classarray));
        $examplefile = __DIR__ . '/../../../lib/emitter/docs/examples/' . $eventname . '.json';
        file_put_contents($examplefile, json_encode($output, JSON_PRETTY_PRINT));
    }

I should have changed the str_replace line to take into consideration the change of filename.

I'll sort that out now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed another commit to address this issue.

  • The change to .gitignore is no longer necessary so I've backed it out.
  • The automatic generation of the file name of the example event JSON files by the PHPUnit tests has been corrected (changed from replacing Test to replacing _test).
  • Example event JSON files themselves (in lib/*/docs/examples/) have all been renamed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! This is awesome! Thanks @mikemcgowan 👍

@ryasmi
Copy link
Member

ryasmi commented Jun 30, 2017

Have a quick check of this if you like @davidpesce, I think it's ready to merge.

@ryasmi ryasmi mentioned this pull request Jun 30, 2017
@davidpesce
Copy link
Collaborator

Wow, this looks like quite a bit of work. Thanks, @mikemcgowan !

After a quick look, this looks OK to me. I haven't done a full test, but if you are good with it, merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants