Skip to content

Commit

Permalink
MDL-67673 phpunit: Remove deprecated assertContains() uses on strings
Browse files Browse the repository at this point in the history
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: sebastianbergmann/phpunit#3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
  • Loading branch information
stronk7 committed Sep 1, 2020
1 parent 8968342 commit 50f6e3b
Show file tree
Hide file tree
Showing 41 changed files with 468 additions and 468 deletions.
18 changes: 9 additions & 9 deletions analytics/tests/dataset_manager_test.php
Expand Up @@ -60,10 +60,10 @@ public function test_create_dataset() {
$f1 = $dataset1->store($dataset1data);

$f1contents = $f1->get_content();
$this->assertContains('yeah', $f1contents);
$this->assertContains('var1', $f1contents);
$this->assertContains('value1', $f1contents);
$this->assertContains('header1', $f1contents);
$this->assertStringContainsString('yeah', $f1contents);
$this->assertStringContainsString('var1', $f1contents);
$this->assertStringContainsString('value1', $f1contents);
$this->assertStringContainsString('header1', $f1contents);
}

/**
Expand All @@ -86,11 +86,11 @@ public function test_merge_datasets() {
\core_analytics\dataset_manager::LABELLED_FILEAREA);

$mergedfilecontents = $merged->get_content();
$this->assertContains('yeah', $mergedfilecontents);
$this->assertContains('no', $mergedfilecontents);
$this->assertContains('var1', $mergedfilecontents);
$this->assertContains('value1', $mergedfilecontents);
$this->assertContains('header1', $mergedfilecontents);
$this->assertStringContainsString('yeah', $mergedfilecontents);
$this->assertStringContainsString('no', $mergedfilecontents);
$this->assertStringContainsString('var1', $mergedfilecontents);
$this->assertStringContainsString('value1', $mergedfilecontents);
$this->assertStringContainsString('header1', $mergedfilecontents);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions availability/condition/completion/tests/condition_test.php
Expand Up @@ -116,7 +116,7 @@ public function test_constructor() {
$cond = new condition($structure);
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('Missing or invalid ->cm', $e->getMessage());
$this->assertStringContainsString('Missing or invalid ->cm', $e->getMessage());
}

// Invalid $cm.
Expand All @@ -125,7 +125,7 @@ public function test_constructor() {
$cond = new condition($structure);
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('Missing or invalid ->cm', $e->getMessage());
$this->assertStringContainsString('Missing or invalid ->cm', $e->getMessage());
}

// Missing $e.
Expand All @@ -134,7 +134,7 @@ public function test_constructor() {
$cond = new condition($structure);
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('Missing or invalid ->e', $e->getMessage());
$this->assertStringContainsString('Missing or invalid ->e', $e->getMessage());
}

// Invalid $e.
Expand All @@ -143,7 +143,7 @@ public function test_constructor() {
$cond = new condition($structure);
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('Missing or invalid ->e', $e->getMessage());
$this->assertStringContainsString('Missing or invalid ->e', $e->getMessage());
}

// Successful construct & display with all different expected values.
Expand Down
8 changes: 4 additions & 4 deletions availability/condition/date/tests/condition_test.php
Expand Up @@ -96,7 +96,7 @@ public function test_constructor() {
$date = new condition($structure);
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('Missing or invalid ->d', $e->getMessage());
$this->assertStringContainsString('Missing or invalid ->d', $e->getMessage());
}

// Invalid ->d.
Expand All @@ -105,7 +105,7 @@ public function test_constructor() {
$date = new condition($structure);
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('Missing or invalid ->d', $e->getMessage());
$this->assertStringContainsString('Missing or invalid ->d', $e->getMessage());
}

// Missing ->t.
Expand All @@ -114,7 +114,7 @@ public function test_constructor() {
$date = new condition($structure);
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('Missing or invalid ->t', $e->getMessage());
$this->assertStringContainsString('Missing or invalid ->t', $e->getMessage());
}

// Invalid ->t.
Expand All @@ -123,7 +123,7 @@ public function test_constructor() {
$date = new condition($structure);
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('Missing or invalid ->t', $e->getMessage());
$this->assertStringContainsString('Missing or invalid ->t', $e->getMessage());
}

// Valid conditions of both types.
Expand Down
8 changes: 4 additions & 4 deletions availability/condition/grade/tests/condition_test.php
Expand Up @@ -149,7 +149,7 @@ public function test_constructor() {
$cond = new condition($structure);
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('Missing or invalid ->id', $e->getMessage());
$this->assertStringContainsString('Missing or invalid ->id', $e->getMessage());
}

// Invalid id (not int).
Expand All @@ -158,7 +158,7 @@ public function test_constructor() {
$cond = new condition($structure);
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('Missing or invalid ->id', $e->getMessage());
$this->assertStringContainsString('Missing or invalid ->id', $e->getMessage());
}

// Invalid min (not number).
Expand All @@ -168,7 +168,7 @@ public function test_constructor() {
$cond = new condition($structure);
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('Missing or invalid ->min', $e->getMessage());
$this->assertStringContainsString('Missing or invalid ->min', $e->getMessage());
}

// Invalid max (not number).
Expand All @@ -178,7 +178,7 @@ public function test_constructor() {
$cond = new condition($structure);
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('Missing or invalid ->max', $e->getMessage());
$this->assertStringContainsString('Missing or invalid ->max', $e->getMessage());
}

// All valid.
Expand Down
2 changes: 1 addition & 1 deletion availability/condition/group/tests/condition_test.php
Expand Up @@ -122,7 +122,7 @@ public function test_constructor() {
$cond = new condition($structure);
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('Invalid ->id', $e->getMessage());
$this->assertStringContainsString('Invalid ->id', $e->getMessage());
}

// Valid (with id).
Expand Down
8 changes: 4 additions & 4 deletions availability/condition/grouping/tests/condition_test.php
Expand Up @@ -132,7 +132,7 @@ public function test_constructor() {
$cond = new condition($structure);
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('Missing ->id / ->activity', $e->getMessage());
$this->assertStringContainsString('Missing ->id / ->activity', $e->getMessage());
}

// Invalid id (not int).
Expand All @@ -141,7 +141,7 @@ public function test_constructor() {
$cond = new condition($structure);
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('Invalid ->id', $e->getMessage());
$this->assertStringContainsString('Invalid ->id', $e->getMessage());
}

// Invalid activity option (not bool).
Expand All @@ -151,7 +151,7 @@ public function test_constructor() {
$cond = new condition($structure);
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('Invalid ->activity', $e->getMessage());
$this->assertStringContainsString('Invalid ->activity', $e->getMessage());
}

// Invalid activity option (false).
Expand All @@ -160,7 +160,7 @@ public function test_constructor() {
$cond = new condition($structure);
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('Invalid ->activity', $e->getMessage());
$this->assertStringContainsString('Invalid ->activity', $e->getMessage());
}

// Valid with id.
Expand Down
18 changes: 9 additions & 9 deletions availability/condition/profile/tests/condition_test.php
Expand Up @@ -105,7 +105,7 @@ public function test_constructor() {
$cond = new condition($structure);
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('Missing or invalid ->op', $e->getMessage());
$this->assertStringContainsString('Missing or invalid ->op', $e->getMessage());
}

// Invalid op.
Expand All @@ -114,7 +114,7 @@ public function test_constructor() {
$cond = new condition($structure);
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('Missing or invalid ->op', $e->getMessage());
$this->assertStringContainsString('Missing or invalid ->op', $e->getMessage());
}

// Missing value.
Expand All @@ -123,7 +123,7 @@ public function test_constructor() {
$cond = new condition($structure);
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('Missing or invalid ->v', $e->getMessage());
$this->assertStringContainsString('Missing or invalid ->v', $e->getMessage());
}

// Invalid value (not string).
Expand All @@ -132,7 +132,7 @@ public function test_constructor() {
$cond = new condition($structure);
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('Missing or invalid ->v', $e->getMessage());
$this->assertStringContainsString('Missing or invalid ->v', $e->getMessage());
}

// Unexpected value.
Expand All @@ -141,7 +141,7 @@ public function test_constructor() {
$cond = new condition($structure);
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('Unexpected ->v', $e->getMessage());
$this->assertStringContainsString('Unexpected ->v', $e->getMessage());
}

// Missing field.
Expand All @@ -151,7 +151,7 @@ public function test_constructor() {
$cond = new condition($structure);
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('Missing ->sf or ->cf', $e->getMessage());
$this->assertStringContainsString('Missing ->sf or ->cf', $e->getMessage());
}

// Invalid field (not string).
Expand All @@ -160,7 +160,7 @@ public function test_constructor() {
$cond = new condition($structure);
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('Invalid ->sf', $e->getMessage());
$this->assertStringContainsString('Invalid ->sf', $e->getMessage());
}

// Both fields.
Expand All @@ -170,7 +170,7 @@ public function test_constructor() {
$cond = new condition($structure);
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('Both ->sf and ->cf', $e->getMessage());
$this->assertStringContainsString('Both ->sf and ->cf', $e->getMessage());
}

// Invalid ->cf field (not string).
Expand All @@ -180,7 +180,7 @@ public function test_constructor() {
$cond = new condition($structure);
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('Invalid ->cf', $e->getMessage());
$this->assertStringContainsString('Invalid ->cf', $e->getMessage());
}

// Valid examples (checks values are correctly included).
Expand Down
4 changes: 2 additions & 2 deletions availability/tests/info_test.php
Expand Up @@ -91,7 +91,7 @@ public function test_info_module() {
$debugging = $this->getDebuggingMessages();
$this->resetDebugging();
$this->assertEquals(1, count($debugging));
$this->assertContains('Invalid availability', $debugging[0]->message);
$this->assertStringContainsString('Invalid availability', $debugging[0]->message);

// Check empty one.
$info = new info_module($cm4);
Expand Down Expand Up @@ -145,7 +145,7 @@ public function test_info_section() {
$debugging = $this->getDebuggingMessages();
$this->resetDebugging();
$this->assertEquals(1, count($debugging));
$this->assertContains('Invalid availability', $debugging[0]->message);
$this->assertStringContainsString('Invalid availability', $debugging[0]->message);

// Check empty one.
$info = new info_section($sections[4]);
Expand Down
28 changes: 14 additions & 14 deletions availability/tests/tree_test.php
Expand Up @@ -49,83 +49,83 @@ public function test_construct_errors() {
new tree('frog');
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('not object', $e->getMessage());
$this->assertStringContainsString('not object', $e->getMessage());
}
try {
new tree((object)array());
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('missing ->op', $e->getMessage());
$this->assertStringContainsString('missing ->op', $e->getMessage());
}
try {
new tree((object)array('op' => '*'));
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('unknown ->op', $e->getMessage());
$this->assertStringContainsString('unknown ->op', $e->getMessage());
}
try {
new tree((object)array('op' => '|'));
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('missing ->show', $e->getMessage());
$this->assertStringContainsString('missing ->show', $e->getMessage());
}
try {
new tree((object)array('op' => '|', 'show' => 0));
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('->show not bool', $e->getMessage());
$this->assertStringContainsString('->show not bool', $e->getMessage());
}
try {
new tree((object)array('op' => '&'));
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('missing ->showc', $e->getMessage());
$this->assertStringContainsString('missing ->showc', $e->getMessage());
}
try {
new tree((object)array('op' => '&', 'showc' => 0));
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('->showc not array', $e->getMessage());
$this->assertStringContainsString('->showc not array', $e->getMessage());
}
try {
new tree((object)array('op' => '&', 'showc' => array(0)));
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('->showc value not bool', $e->getMessage());
$this->assertStringContainsString('->showc value not bool', $e->getMessage());
}
try {
new tree((object)array('op' => '|', 'show' => true));
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('missing ->c', $e->getMessage());
$this->assertStringContainsString('missing ->c', $e->getMessage());
}
try {
new tree((object)array('op' => '|', 'show' => true,
'c' => 'side'));
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('->c not array', $e->getMessage());
$this->assertStringContainsString('->c not array', $e->getMessage());
}
try {
new tree((object)array('op' => '|', 'show' => true,
'c' => array(3)));
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('child not object', $e->getMessage());
$this->assertStringContainsString('child not object', $e->getMessage());
}
try {
new tree((object)array('op' => '|', 'show' => true,
'c' => array((object)array('type' => 'doesnotexist'))));
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('Unknown condition type: doesnotexist', $e->getMessage());
$this->assertStringContainsString('Unknown condition type: doesnotexist', $e->getMessage());
}
try {
new tree((object)array('op' => '|', 'show' => true,
'c' => array((object)array())));
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('missing ->op', $e->getMessage());
$this->assertStringContainsString('missing ->op', $e->getMessage());
}
try {
new tree((object)array('op' => '&',
Expand All @@ -134,7 +134,7 @@ public function test_construct_errors() {
));
$this->fail();
} catch (coding_exception $e) {
$this->assertContains('->c, ->showc mismatch', $e->getMessage());
$this->assertStringContainsString('->c, ->showc mismatch', $e->getMessage());
}
}

Expand Down

0 comments on commit 50f6e3b

Please sign in to comment.