The PHP_CodeSniffer @codingStandardsIgnore annotations are deprecated
and, since version 3.x, the new // phpcs:ignore comments should be used
instead.
This commits just reviews all the uses in core, replacing them for
the better new candidate, or removing when no longer needed.
Statically cache list of loaded reports during request lifecycle,
this ensures that computationally heavy initialisation routines
in system reports are only executed once (e.g. the access tab).
* The basic_test::assertTag method will issue a warning as $tag is not
found, failing the PHP Unit test that uses this method.
* Add tests to check that assertTag is working
Following the changes in the schema, from "whitelists" to "includes",
we are deprecating these two properties from phpunit_coverage_info:
- whitelistfolders => includelistfolders
- whitelistfiles => includelistfiles
They will continue working over the deprecation period but the init/util
scripts will throw some warnings about them being deprecated for 3.11 and
the way to replace them.
Standard 2y deprecation applies with final removed to happen @ MDL-71067
This performs all the changes needed in the util generator to
produce XML files compliant with the new schema (see previous
commit for description of changes).
- All the occurrences in code of filter => coverage.
- All the occurrences in code of whitelist => include.
- Apply all the changes to comply with the new schema.
- Remove processUncoveredFilesFromWhitelist attribute, useless (false
is its default value, and now have another name).
- Move from 4-spaces indented XML to 2-spaces indented.
- Small linefeed tweaks to generate better-looking XML.
Custom autoloaders are deprecated with PHPUnit 9 and will be removed
with PHPUnit 10.
Since PHPUnit 8.5 custom autoloaders don't do much because that
version removed the ability to launch unit tests by class name
and that's exactly the reason we had a custom autoloader (to map
class names to files within our tests). See MDL-67673 about
when direct use of classes was deprecated (8.5), now removed (9.5).
So, as far as it's unused, removing it now, test still can be
selectively using any of:
- a relative path to file (although there are some restrictions comming
with PHPUnit 9, see https://github.com/sebastianbergmann/phpunit/issues/4105
- using --filter, to point to any classname[::method]
- using --testsuite to run a complete suite
- using --config to point to custom components.
Also, commented out the lib/ajax/tests directory because it doesn't
exist / is empty and PHPUnit 9 emits error when a configured test
directory does not exist. See
https://github.com/sebastianbergmann/phpunit/issues/4493.
Alternative was to completely remove the configuration line, but
decided to keep it around in case some day we want to add some
test there.
Used by our custom assertTag() and assertNotTag() assertions, that some
day we should deprecate... the loading of XML content for further
processing has been moved to new classes within the PHPUnit utils. We
are just following the move here.
There are some unexpected differences between 310 and master,
better reconcile them now. Note this is not 100% critical but,
as far as nothing exclusively for 4.0 has landed to master yet
only branch/version differences should exist.
That custom printer was using some hacks to be able to intercept
configuration switches, reflection and other tricks to be able to
print the:
To re-run:
vendor/bin/phpunit --verbose "core_setuplib_testcase" lib/tests/setuplib_test.php
line on every failed/exceptional/skipped test. After some internal
discussion it was agreed that the normal phpunit output:
1) core_setuplib_testcase::test_localcachedir
Time is lower that allowed start value
Failed asserting that 1601976686 is equal to 1601976687 or is greater than 1601976687.
/var/www/html/lib/phpunit/classes/advanced_testcase.php:446
/var/www/html/lib/tests/setuplib_test.php:170
/var/www/html/lib/phpunit/classes/advanced_testcase.php:80
has already all the information at hand about how to rerun a test:
- vendor/bin/phpunit lib/tests/setuplib_test.php
- vendor/bin/phpunit --filter core_setuplib_testcase::test_localcachedir
- vendor/bin/phpunit --filter ::test_localcachedir
- vendor/bin/phpunit --testsuite componentname_testsuite
- vendor/bin/phpunit --config <<compoenent directory>>
- use --cache-result to get failed tests rerun with ease.
- ...
So better, let's use standard phpunit output and done. Also, note that,
with the upgrade to phpunit 8.5, the printer was not working correctly
any more, causing some switches, like --verbose ... to be ignored. Sure
it could have been fixed but, as commented above, no real need for all
that "parapheranlia" to print the rerun information.
Apply the standard deprecation procedure to the old APIs, to
be removed in Moodle 4.2 (MDL-69882). Existing unit tests
cover the deprecation debugging.
Originally MDL-64600
In charge of taking over the, now removed/archived, phpunit/dbunit
package. It supports loading of CSV/XML files and strings and
PHP arrays, allowing to send the loaded information to database.
Perform some basic controls about the consistency of information,
surely not super-exhaustive but fair enough.
100% covered with unit test.
Planned like an "interim" replacement for phpunit/dbunit uses in
core that, ideally, should be moved to generators stuff at some
point.
Note, expect a few tests in core to fail with this commit, I've
changed some fixtures around. Next commit will fix existing uses.
Originally MDL-64600
Constraints are now declared final, so we cannot extend them anymore.
Hence, instead of extending PHPUnit\Framework\Constraint\IsEqual we
are just wrapping it into our constraint.
All the setup/teardown/pre/post/conditions template methods
now are required to return void. This was warned with phpunit 7
and now is enforced.
At the same time, fix a few wrong function names,
provider data and param types, return statements...
We are already cleaning all sort of caches, statics, singletons
there and it's better to ensure they are always reset to avoid
myterious failures @ distance.
In PHPUnit 7.x and above, IsEqual->value became private and, as far
as our with exceptions class inherits from it, we cannot access to
that anymore.
So, in order to avoid that, we are overriding the constructor, capturing
the original value for own use and forgetting.
A more formal, alternative, solution would be to make our
exceptional class to inherit from Constraint and make the
class a pure dispatcher to different constraints, with IsEqual being
just one of them.
But we followed the easiest path here. Not ideal, but efective.
This chagne adds support for a new feature known as Context Locking.
This allows a context to be locked, thereby removing all write
capabilities for all users (including admin) for that context, and all
child contexts.
Thanks to MDL-49398, we can separate the combined user session and role
definition cache clearing function into two separate functions. At the
same time, we want to identify and remove mark_dirty() calls that were
added for role definition changes but were incorrectly left behind.
Change highlights:
- Remove unnecessary mark_dirty() calls performed after
assign_capability(), unassign_capability(), delete_role(),
deleted contexts, brand new contexts
- Move role definition cache clear from the user-centric
accesslib_clear_all_caches() to the newly created,
role-dedicated accesslib_reset_role_cache()
Also deprecated the following functions -
1. message_move_userfrom_unread2read - It is not necessary
for us to mark a message as read on user deletion.
2. message_get_blocked_users - Horrible logic used to
determine if a user is blocked via reference on some
randomly chosen 'isblocked' variable.
3. message_get_contacts - The same as above. This can be
done in a much nicer way.
4. message_mark_message_read - We want two functions to do
this to avoid confusing messages and notifications.
5. message_can_delete_message - This assumed the variable
$message contained the 'useridto' property, which
was present in the old table structure. We do not want
future usages where a query is done on the new table
and is simply passed as this won't contain this property.
6. message_delete_message - Same as above.
- count() can only be called on arrays or Countable, it can not be called on null
- recordset is neither so iterator_count() should be used
- instanceof or get_class() can not be applied to non-objects
- class methods must have the same arguments as methods in parent class