Skip to content

Commit

Permalink
MDL-71036 phpunit: Renamed various file-related assertions
Browse files Browse the repository at this point in the history
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'
  • Loading branch information
stronk7 committed Mar 11, 2021
1 parent 87680e8 commit cbf01aa
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion cache/tests/cache_test.php
Expand Up @@ -1321,7 +1321,7 @@ public function test_disable() {
// 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();
Expand Down
4 changes: 2 additions & 2 deletions lib/antivirus/clamav/tests/scanner_test.php
Expand Up @@ -49,7 +49,7 @@ public function test_scan_file_not_exists() {

// 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();
Expand Down Expand Up @@ -263,7 +263,7 @@ public function test_scan_file_error_tryagain() {
$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() {
Expand Down
4 changes: 2 additions & 2 deletions lib/filestorage/tests/file_storage_test.php
Expand Up @@ -86,7 +86,7 @@ public function test_create_file_from_string() {
// 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);
Expand Down Expand Up @@ -158,7 +158,7 @@ public function test_create_file_from_pathname() {
// 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);
Expand Down
20 changes: 10 additions & 10 deletions lib/filestorage/tests/zip_packer_test.php
Expand Up @@ -143,7 +143,7 @@ public function test_archive_to_pathname() {
$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);
Expand All @@ -157,15 +157,15 @@ public function test_archive_to_pathname() {

// 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);
Expand All @@ -175,7 +175,7 @@ public function test_archive_to_pathname() {
$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);
Expand Down Expand Up @@ -338,7 +338,7 @@ public function test_extract_to_pathname_onlyfiles() {
}
foreach ($donotextract as $file) {
$this->assertFalse(isset($result[$file]));
$this->assertFileNotExists($target.$file);
$this->assertFileDoesNotExist($target.$file);
}

}
Expand Down Expand Up @@ -429,7 +429,7 @@ public function test_add_files() {
$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);

Expand Down Expand Up @@ -469,7 +469,7 @@ public function test_close_archive() {
$textfile = "$CFG->tempdir/textfile.txt";
touch($textfile);

$this->assertFileNotExists($archive);
$this->assertFileDoesNotExist($archive);
$this->assertFileExists($textfile);

// Create archive and close it without files.
Expand Down Expand Up @@ -524,7 +524,7 @@ public function test_close_archive() {
$this->assertInstanceOf('PHPUnit\Framework\ExpectationFailedException', $e);
$this->assertTrue($result);
}
$this->assertFileNotExists($archive);
$this->assertFileDoesNotExist($archive);
}

/**
Expand All @@ -537,7 +537,7 @@ public function test_open_archive() {

$archive = "$CFG->tempdir/archive.zip";

$this->assertFileNotExists($archive);
$this->assertFileDoesNotExist($archive);

$zip_archive = new zip_archive();
$result = $zip_archive->open($archive, file_archive::OPEN);
Expand Down
2 changes: 1 addition & 1 deletion lib/tests/antivirus_test.php
Expand Up @@ -82,7 +82,7 @@ public function test_manager_scan_file_virus() {
$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() {
Expand Down
2 changes: 1 addition & 1 deletion lib/tests/component_test.php
Expand Up @@ -419,7 +419,7 @@ public function test_get_subplugins() {

// 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'));

Expand Down
2 changes: 1 addition & 1 deletion lib/tests/filterlib_test.php
Expand Up @@ -704,7 +704,7 @@ public function test_set() {

$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);
Expand Down
4 changes: 2 additions & 2 deletions lib/tests/plugin_manager_test.php
Expand Up @@ -251,8 +251,8 @@ public function test_plugin_states() {
$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');
Expand Down
12 changes: 6 additions & 6 deletions lib/tests/setuplib_test.php
Expand Up @@ -112,7 +112,7 @@ public function test_localcachedir() {
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));

Expand All @@ -123,7 +123,7 @@ public function test_localcachedir() {
$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);
Expand All @@ -146,8 +146,8 @@ public function test_localcachedir() {
$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);
Expand All @@ -163,8 +163,8 @@ public function test_localcachedir() {
$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));
}
Expand Down

0 comments on commit cbf01aa

Please sign in to comment.