catalyst / moodle-auth_outage

Planned, graduated user and admin friendly moodle outages
https://moodle.org/plugins/auth_outage
17 stars 33 forks source link

Fix PHP unit test error #221

Closed yao9394 closed 3 years ago

yao9394 commented 3 years ago

Declaration must be compatible with PHPUnit\Framework\TestCase methods

yao9394 commented 3 years ago

This PR is an updated version of https://github.com/catalyst/moodle-auth_outage/pull/218 And for [Totara 13] we also need https://github.com/catalyst/moodle-auth_outage/pull/219 Thanks

danmarsden commented 3 years ago

looks like we need to change the expectexception stuff to stuff like this too:

$this->expectException(\moodle_exception::class);

not sure if it's backwards compatible though.

yao9394 commented 3 years ago

HI @danmarsden Thanks for your feedback. are you referring to the warning like this? The @expectedException, @expectedExceptionCode, @expectedExceptionMessage, and @expectedExceptionMessageRegExp annotations are deprecated. They will be removed in PHPUnit 9. Refactor your test to use expectException(), expectExceptionCode(), expectExceptionMessage(), or expectExceptionMessageMatches() instead. I am not seeing anything related to expectException(), I might have missed something, please let me know.

Cheers, John Y

danmarsden commented 3 years ago

yeah that's it - I had to add this (and remove the phdoc comments)


diff --git a/server/auth/saml2/tests/phpunit/metadata_parser_test.php b/server/auth/saml2/tests/phpunit/metadata_parser_test.php
index e17807931ee..4c8bbbcfba0 100644
--- a/server/auth/saml2/tests/phpunit/metadata_parser_test.php
+++ b/server/auth/saml2/tests/phpunit/metadata_parser_test.php
@@ -48,6 +48,7 @@ class auth_saml2_metadata_parser_testcase extends basic_testcase {
     /**
      */
     public function test_parse_metadata_fail() {
+        $this->expectException(\moodle_exception::class);
         $malformedxml = <<<XML
 <EntitiesDescriptor Name="https://your-federation.org/metadata/federation-name.xml"
                     xmlns="urn:oasis:names:tc:SAML:2.0:metadata"
diff --git a/server/auth/saml2/tests/phpunit/metadata_writer_test.php b/server/auth/saml2/tests/phpunit/metadata_writer_test.php
index 3393d5e02c6..9a7fcd18035 100644
--- a/server/auth/saml2/tests/phpunit/metadata_writer_test.php
+++ b/server/auth/saml2/tests/phpunit/metadata_writer_test.php
@@ -50,6 +50,7 @@ class auth_saml2_metadata_writer_testcase extends basic_testcase {
     /**
      */
     public function test_write_empty_filename() {
+        $this->expectException(\coding_exception::class);
         $filename = '';
         $content = 'Test data';
danmarsden commented 3 years ago

haha - too many windows/patches... it's saml2 :-)

ScottVerbeek commented 3 years ago

Opened a new branch and created a new pull request combining this and https://github.com/catalyst/moodle-auth_outage/pull/219