catalyst / moodle-auth_saml2

SAML done 100% in Moodle, fast, simple, secure
https://moodle.org/plugins/auth_saml2
70 stars 132 forks source link

Deprecated twig class reference causes unit test failure #711

Closed matthewhilton closed 1 year ago

matthewhilton commented 1 year ago

This error occurs when another plugin loads in the twig class before auth_saml2 (simplesaml) for e.g. qtype_coderunner https://moodle.org/plugins/qtype_coderunner

Then run the unit tests for both plugins

vendor/bin/phpunit --testsuite qtype_coderunner_testsuite,auth_saml2_testsuite

You will get a failure:

There was 1 failure:

1) auth_saml2_autoloader_test::test_it_loads_classes
Class not found: Twig_Loader_Filesystem
Failed asserting that false is true.

/var/www/macquarie/auth/saml2/tests/autoloader_test.php:45
/var/www/macquarie/lib/phpunit/classes/advanced_testcase.php:80
phpvfscomposer:///var/www/macquarie/vendor/phpunit/phpunit/phpunit:60

To re-run:
 vendor/bin/phpunit "auth_saml2_autoloader_test" auth/saml2/tests/autoloader_test.php

This appears to be caused by this line https://github.com/catalyst/moodle-auth_saml2/blob/714163d4e0f61eba856d6a700c679827b0331e44/tests/autoloader_test.php#L41 Which is referencing a deprecated class for Twig, it should be Twig\Loader\FilesystemLoader::class as noted here https://github.com/catalyst/moodle-auth_saml2/blob/714163d4e0f61eba856d6a700c679827b0331e44/.extlib/simplesamlphp/vendor/twig/twig/lib/Twig/Loader/Filesystem.php#L7

Changing this, the tests now pass. I will be making a PR for this soon :tm: