Commit 309a65a6 authored by Eloy Lafuente's avatar Eloy Lafuente
Browse files

MDL-71036 phpunit: Renamed various file-related assertions

In PHPUnit 9.1, the following file-related assertions
have been deprecated and there are new alternatives for
all them:
- assertNotIsReadable()         -> assertIsNotReadable()
- assertNotIsWritable()         -> assertIsNotWritable()
- assertDirectoryNotExists()    -> assertDirectoryDoesNotExist()
- assertDirectoryNotIsReadable()-> assertDirectoryIsNotReadable()
- assertDirectoryNotIsWritable()-> assertDirectoryIsNotWritable()
- assertFileNotExists()         -> assertFileDoesNotExist()
- assertFileNotIsReadable()     -> assertFileIsNotReadable()
- assertFileNotIsWritable()     -> assertFileIsNotWritable()

This is about to, simply, move all cases to the new alternatives.

Source: https://github.com/sebastianbergmann/phpunit/blob/9.1.0/ChangeLog-9.1.md

Regexp to find all them:

ag 'assertNotIsReadable|assertNotIsWritable|assertDirectoryNotExists|\
assertDirectoryNotIsReadable|assertDirectoryNotIsWritable|\
assertFileNotExists|assertFileNotIsReadable|assertFileNotIsWritable'
parent 5fcd5e1c
......@@ -1321,7 +1321,7 @@ class core_cache_testcase extends advanced_testcase {
// The config file will not exist yet as we've not done anything with the cache.
// reset_all_data removes the file and without a call to create a configuration it doesn't exist
// as yet.
$this->assertFileNotExists($configfile);
$this->assertFileDoesNotExist($configfile);
// Disable the cache
cache_phpunit_factory::phpunit_disable();
......
......@@ -49,7 +49,7 @@ class antivirus_clamav_scanner_testcase extends advanced_testcase {
// Test specifying file that does not exist.
$nonexistingfile = $this->tempfile . '_';
$this->assertFileNotExists($nonexistingfile);
$this->assertFileDoesNotExist($nonexistingfile);
// Run mock scanning, we expect SCAN_RESULT_ERROR.
$this->assertEquals(2, $antivirus->scan_file($nonexistingfile, ''));
$this->assertDebuggingCalled();
......@@ -263,7 +263,7 @@ class antivirus_clamav_scanner_testcase extends advanced_testcase {
$this->expectException(\core\antivirus\scanner_exception::class);
$antivirus->scan_file($this->tempfile, '');
$this->assertEquals('antivirusfailed', $this->getExpectedExceptionCode());
$this->assertFileNotExists($this->tempfile);
$this->assertFileDoesNotExist($this->tempfile);
}
public function test_scan_data_no_virus() {
......
......@@ -86,7 +86,7 @@ class core_files_file_storage_testcase extends advanced_testcase {
// Tests that missing content file is recreated.
unlink($location);
$this->assertFileNotExists($location);
$this->assertFileDoesNotExist($location);
$filerecord['filename'] = 'testfile2.txt';
$file2 = $fs->create_file_from_string($filerecord, $content);
......@@ -158,7 +158,7 @@ class core_files_file_storage_testcase extends advanced_testcase {
// Tests that missing content file is recreated.
unlink($location);
$this->assertFileNotExists($location);
$this->assertFileDoesNotExist($location);
$filerecord['filename'] = 'testfile2.jpg';
$file2 = $fs->create_file_from_pathname($filerecord, $filepath);
......
......@@ -143,7 +143,7 @@ class core_files_zip_packer_testcase extends advanced_testcase implements file_p
$packer = get_file_packer('application/zip');
$archive = "$CFG->tempdir/archive.zip";
$this->assertFileNotExists($archive);
$this->assertFileDoesNotExist($archive);
$result = $packer->archive_to_pathname($this->files, $archive);
$this->assertTrue($result);
$this->assertFileExists($archive);
......@@ -157,15 +157,15 @@ class core_files_zip_packer_testcase extends advanced_testcase implements file_p
// Test invalid files parameter.
$archive = "$CFG->tempdir/archive2.zip";
$this->assertFileNotExists($archive);
$this->assertFileDoesNotExist($archive);
$this->assertFileNotExists(__DIR__.'/xx/yy/ee.txt');
$this->assertFileDoesNotExist(__DIR__.'/xx/yy/ee.txt');
$files = array('xtest.txt'=>__DIR__.'/xx/yy/ee.txt');
$result = $packer->archive_to_pathname($files, $archive, false);
$this->assertFalse($result);
$this->assertDebuggingCalled();
$this->assertFileNotExists($archive);
$this->assertFileDoesNotExist($archive);
$result = $packer->archive_to_pathname($files, $archive);
$this->assertTrue($result);
......@@ -175,7 +175,7 @@ class core_files_zip_packer_testcase extends advanced_testcase implements file_p
$this->assertSame(array(), $archivefiles);
unlink($archive);
$this->assertFileNotExists(__DIR__.'/xx/yy/ee.txt');
$this->assertFileDoesNotExist(__DIR__.'/xx/yy/ee.txt');
$this->assertFileExists(__DIR__.'/fixtures/test.txt');
$files = array('xtest.txt'=>__DIR__.'/xx/yy/ee.txt', 'test.txt'=>__DIR__.'/fixtures/test.txt', 'ytest.txt'=>__DIR__.'/xx/yy/yy.txt');
$result = $packer->archive_to_pathname($files, $archive);
......@@ -338,7 +338,7 @@ class core_files_zip_packer_testcase extends advanced_testcase implements file_p
}
foreach ($donotextract as $file) {
$this->assertFalse(isset($result[$file]));
$this->assertFileNotExists($target.$file);
$this->assertFileDoesNotExist($target.$file);
}
}
......@@ -429,7 +429,7 @@ class core_files_zip_packer_testcase extends advanced_testcase implements file_p
$packer = get_file_packer('application/zip');
$archive = "$CFG->tempdir/archive.zip";
$this->assertFileNotExists($archive);
$this->assertFileDoesNotExist($archive);
$packer->archive_to_pathname(array(), $archive);
$this->assertFileExists($archive);
......@@ -469,7 +469,7 @@ class core_files_zip_packer_testcase extends advanced_testcase implements file_p
$textfile = "$CFG->tempdir/textfile.txt";
touch($textfile);
$this->assertFileNotExists($archive);
$this->assertFileDoesNotExist($archive);
$this->assertFileExists($textfile);
// Create archive and close it without files.
......@@ -524,7 +524,7 @@ class core_files_zip_packer_testcase extends advanced_testcase implements file_p
$this->assertInstanceOf('PHPUnit\Framework\ExpectationFailedException', $e);
$this->assertTrue($result);
}
$this->assertFileNotExists($archive);
$this->assertFileDoesNotExist($archive);
}
/**
......@@ -537,7 +537,7 @@ class core_files_zip_packer_testcase extends advanced_testcase implements file_p
$archive = "$CFG->tempdir/archive.zip";
$this->assertFileNotExists($archive);
$this->assertFileDoesNotExist($archive);
$zip_archive = new zip_archive();
$result = $zip_archive->open($archive, file_archive::OPEN);
......
......@@ -82,7 +82,7 @@ class core_antivirus_testcase extends advanced_testcase {
$this->expectException(\core\antivirus\scanner_exception::class);
$this->assertEmpty(\core\antivirus\manager::scan_file($this->tempfile, 'FOUND', true));
// File expected to be deleted.
$this->assertFileNotExists($this->tempfile);
$this->assertFileDoesNotExist($this->tempfile);
}
public function test_manager_send_message_to_user_email_scan_file_virus() {
......
......@@ -419,7 +419,7 @@ class core_component_testcase extends advanced_testcase {
// Any plugin without subtypes is ok here.
$this->assertFileExists("$CFG->dirroot/mod/choice");
$this->assertFileNotExists("$CFG->dirroot/mod/choice/db/subplugins.json");
$this->assertFileDoesNotExist("$CFG->dirroot/mod/choice/db/subplugins.json");
$this->assertNull(core_component::get_subplugins('mod_choice'));
......
......@@ -704,7 +704,7 @@ class core_filterlib_testcase extends advanced_testcase {
$this->assertFileExists("$CFG->dirroot/filter/emailprotect"); // Any standard filter.
$this->assertFileExists("$CFG->dirroot/filter/tidy"); // Any standard filter.
$this->assertFileNotExists("$CFG->dirroot/filter/grgrggr"); // Any non-existent filter
$this->assertFileDoesNotExist("$CFG->dirroot/filter/grgrggr"); // Any non-existent filter
// Setup fixture.
set_config('filterall', 0);
......
......@@ -251,8 +251,8 @@ class core_plugin_manager_testcase extends advanced_testcase {
$this->assertFileExists("$CFG->dirroot/mod/assign", 'assign module is not present');
$this->assertFileExists("$CFG->dirroot/mod/forum", 'forum module is not present');
$this->assertFileExists("$CFG->dirroot/$CFG->admin/tool/phpunit", 'phpunit tool is not present');
$this->assertFileNotExists("$CFG->dirroot/mod/xxxxxxx");
$this->assertFileNotExists("$CFG->dirroot/enrol/autorize");
$this->assertFileDoesNotExist("$CFG->dirroot/mod/xxxxxxx");
$this->assertFileDoesNotExist("$CFG->dirroot/enrol/autorize");
// Ready for upgrade.
$assignversion = get_config('mod_assign', 'version');
......
......@@ -112,7 +112,7 @@ class core_setuplib_testcase extends advanced_testcase {
remove_dir($CFG->localcachedir, true);
$dir = make_localcache_directory('', false);
$this->assertSame($CFG->localcachedir, $dir);
$this->assertFileNotExists("$CFG->localcachedir/.htaccess");
$this->assertFileDoesNotExist("$CFG->localcachedir/.htaccess");
$this->assertFileExists($timestampfile);
$this->assertTimeCurrent(filemtime($timestampfile));
......@@ -123,7 +123,7 @@ class core_setuplib_testcase extends advanced_testcase {
$CFG->localcachedir = "$CFG->dataroot/testlocalcache";
$this->setCurrentTimeStart();
$timestampfile = "$CFG->localcachedir/.lastpurged";
$this->assertFileNotExists($timestampfile);
$this->assertFileDoesNotExist($timestampfile);
$dir = make_localcache_directory('', false);
$this->assertSame($CFG->localcachedir, $dir);
......@@ -146,8 +146,8 @@ class core_setuplib_testcase extends advanced_testcase {
$now = $this->setCurrentTimeStart();
set_config('localcachedirpurged', $now - 2);
purge_all_caches();
$this->assertFileNotExists($testfile);
$this->assertFileNotExists(dirname($testfile));
$this->assertFileDoesNotExist($testfile);
$this->assertFileDoesNotExist(dirname($testfile));
$this->assertFileExists($timestampfile);
$this->assertTimeCurrent(filemtime($timestampfile));
$this->assertTimeCurrent($CFG->localcachedirpurged);
......@@ -163,8 +163,8 @@ class core_setuplib_testcase extends advanced_testcase {
$this->setCurrentTimeStart();
$dir = make_localcache_directory('', false);
$this->assertSame("$CFG->localcachedir", $dir);
$this->assertFileNotExists($testfile);
$this->assertFileNotExists(dirname($testfile));
$this->assertFileDoesNotExist($testfile);
$this->assertFileDoesNotExist(dirname($testfile));
$this->assertFileExists($timestampfile);
$this->assertTimeCurrent(filemtime($timestampfile));
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment