Skip to content

Commit

Permalink
minor #32971 Use assertStringContainsString when needed (jderusse)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.4 branch.

Discussion
----------

Use assertStringContainsString when needed

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #32844
| License       | MIT
| Doc PR        | NA

This PR replaces deprecated assertContains to comparre string by the dedicated method `assertStringContainsString`

Commits
-------

058ef39 Use assertStringContainsString when needed
  • Loading branch information
nicolas-grekas committed Aug 6, 2019
2 parents 611f57c + 058ef39 commit 08573a1
Show file tree
Hide file tree
Showing 51 changed files with 205 additions and 205 deletions.
Expand Up @@ -197,12 +197,12 @@ public function testLogsFromListeners()

$event = new ConsoleCommandEvent(new Command('foo'), $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock(), $output);
$dispatcher->dispatch(ConsoleEvents::COMMAND, $event);
$this->assertContains('Before command message.', $out = $output->fetch());
$this->assertContains('After command message.', $out);
$this->assertStringContainsString('Before command message.', $out = $output->fetch());
$this->assertStringContainsString('After command message.', $out);

$event = new ConsoleTerminateEvent(new Command('foo'), $this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock(), $output, 0);
$dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
$this->assertContains('Before terminate message.', $out = $output->fetch());
$this->assertContains('After terminate message.', $out);
$this->assertStringContainsString('Before terminate message.', $out = $output->fetch());
$this->assertStringContainsString('After terminate message.', $out);
}
}
12 changes: 6 additions & 6 deletions src/Symfony/Bridge/PhpUnit/Tests/CoverageListenerTest.php
Expand Up @@ -33,14 +33,14 @@ public function test()

exec("$php $phpunit -c $dir/phpunit-without-listener.xml.dist $dir/tests/ --coverage-text 2> /dev/null", $output);
$output = implode("\n", $output);
$this->assertContains('FooCov', $output);
$this->assertStringContainsString('FooCov', $output);

exec("$php $phpunit -c $dir/phpunit-with-listener.xml.dist $dir/tests/ --coverage-text 2> /dev/null", $output);
$output = implode("\n", $output);
$this->assertNotContains('FooCov', $output);
$this->assertContains("SutNotFoundTest::test\nCould not find the tested class.", $output);
$this->assertNotContains("CoversTest::test\nCould not find the tested class.", $output);
$this->assertNotContains("CoversDefaultClassTest::test\nCould not find the tested class.", $output);
$this->assertNotContains("CoversNothingTest::test\nCould not find the tested class.", $output);
$this->assertStringNotContainsString('FooCov', $output);
$this->assertStringContainsString("SutNotFoundTest::test\nCould not find the tested class.", $output);
$this->assertStringNotContainsString("CoversTest::test\nCould not find the tested class.", $output);
$this->assertStringNotContainsString("CoversDefaultClassTest::test\nCould not find the tested class.", $output);
$this->assertStringNotContainsString("CoversNothingTest::test\nCould not find the tested class.", $output);
}
}
6 changes: 3 additions & 3 deletions src/Symfony/Bridge/Twig/Tests/Command/DebugCommandTest.php
Expand Up @@ -26,7 +26,7 @@ public function testDebugCommand()
$ret = $tester->execute([], ['decorated' => false]);

$this->assertEquals(0, $ret, 'Returns 0 in case of success');
$this->assertContains('Functions', trim($tester->getDisplay()));
$this->assertStringContainsString('Functions', trim($tester->getDisplay()));
}

public function testLineSeparatorInLoaderPaths()
Expand Down Expand Up @@ -59,7 +59,7 @@ public function testLineSeparatorInLoaderPaths()
TXT;

$this->assertEquals(0, $ret, 'Returns 0 in case of success');
$this->assertContains($loaderPaths, trim($tester->getDisplay(true)));
$this->assertStringContainsString($loaderPaths, trim($tester->getDisplay(true)));
}

public function testWithGlobals()
Expand All @@ -70,7 +70,7 @@ public function testWithGlobals()

$display = $tester->getDisplay();

$this->assertContains(json_encode($message), $display);
$this->assertStringContainsString(json_encode($message), $display);
}

public function testWithGlobalsJson()
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Tests/Command/LintCommandTest.php
Expand Up @@ -31,7 +31,7 @@ public function testLintCorrectFile()
$ret = $tester->execute(['filename' => [$filename]], ['verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false]);

$this->assertEquals(0, $ret, 'Returns 0 in case of success');
$this->assertContains('OK in', trim($tester->getDisplay()));
$this->assertStringContainsString('OK in', trim($tester->getDisplay()));
}

public function testLintIncorrectFile()
Expand Down
Expand Up @@ -27,7 +27,7 @@ public function testDebugAllRoutes()
$ret = $tester->execute(['name' => null], ['decorated' => false]);

$this->assertEquals(0, $ret, 'Returns 0 in case of success');
$this->assertContains('Name Method Scheme Host Path', $tester->getDisplay());
$this->assertStringContainsString('Name Method Scheme Host Path', $tester->getDisplay());
}

public function testDebugSingleRoute()
Expand All @@ -36,7 +36,7 @@ public function testDebugSingleRoute()
$ret = $tester->execute(['name' => 'foo'], ['decorated' => false]);

$this->assertEquals(0, $ret, 'Returns 0 in case of success');
$this->assertContains('Route Name | foo', $tester->getDisplay());
$this->assertStringContainsString('Route Name | foo', $tester->getDisplay());
}

public function testDebugInvalidRoute()
Expand Down
Expand Up @@ -29,7 +29,7 @@ public function testWithMatchPath()
$ret = $tester->execute(['path_info' => '/foo', 'foo'], ['decorated' => false]);

$this->assertEquals(0, $ret, 'Returns 0 in case of success');
$this->assertContains('Route Name | foo', $tester->getDisplay());
$this->assertStringContainsString('Route Name | foo', $tester->getDisplay());
}

public function testWithNotMatchPath()
Expand All @@ -38,7 +38,7 @@ public function testWithNotMatchPath()
$ret = $tester->execute(['path_info' => '/test', 'foo'], ['decorated' => false]);

$this->assertEquals(1, $ret, 'Returns 1 in case of failure');
$this->assertContains('None of the routes match the path "/test"', $tester->getDisplay());
$this->assertStringContainsString('None of the routes match the path "/test"', $tester->getDisplay());
}

/**
Expand All @@ -56,7 +56,7 @@ public function testLegacyMatchCommand()

$tester->execute(['path_info' => '/']);

$this->assertContains('None of the routes match the path "/"', $tester->getDisplay());
$this->assertStringContainsString('None of the routes match the path "/"', $tester->getDisplay());
}

/**
Expand Down
Expand Up @@ -239,7 +239,7 @@ public function testLegacyDebugCommand()
$tester = new CommandTester($application->find('debug:translation'));
$tester->execute(['locale' => 'en']);

$this->assertContains('No defined or extracted', $tester->getDisplay());
$this->assertStringContainsString('No defined or extracted', $tester->getDisplay());
}

private function getBundle($path)
Expand Down
Expand Up @@ -231,7 +231,7 @@ public function testLegacyUpdateCommand()
$tester = new CommandTester($application->find('translation:update'));
$tester->execute(['locale' => 'en']);

$this->assertContains('You must choose one of --force or --dump-messages', $tester->getDisplay());
$this->assertStringContainsString('You must choose one of --force or --dump-messages', $tester->getDisplay());
}

private function getBundle($path)
Expand Down
Expand Up @@ -41,7 +41,7 @@ public function testLintCorrectFile()
);

$this->assertEquals(0, $tester->getStatusCode(), 'Returns 0 in case of success');
$this->assertContains('OK', trim($tester->getDisplay()));
$this->assertStringContainsString('OK', trim($tester->getDisplay()));
}

public function testLintIncorrectFile()
Expand All @@ -55,7 +55,7 @@ public function testLintIncorrectFile()
$tester->execute(['filename' => $filename], ['decorated' => false]);

$this->assertEquals(1, $tester->getStatusCode(), 'Returns 1 in case of error');
$this->assertContains('Unable to parse at line 3 (near "bar").', trim($tester->getDisplay()));
$this->assertStringContainsString('Unable to parse at line 3 (near "bar").', trim($tester->getDisplay()));
}

public function testLintFileNotReadable()
Expand Down Expand Up @@ -106,7 +106,7 @@ public function testLintFilesFromBundleDirectory()
);

$this->assertEquals(0, $tester->getStatusCode(), 'Returns 0 in case of success');
$this->assertContains('[OK] All 0 YAML files contain valid syntax', trim($tester->getDisplay()));
$this->assertStringContainsString('[OK] All 0 YAML files contain valid syntax', trim($tester->getDisplay()));
}

/**
Expand Down
Expand Up @@ -160,9 +160,9 @@ public function testRunOnlyWarnsOnUnregistrableCommand()
$output = $tester->getDisplay();

$this->assertSame(0, $tester->getStatusCode());
$this->assertContains('Some commands could not be registered:', $output);
$this->assertContains('throwing', $output);
$this->assertContains('fine', $output);
$this->assertStringContainsString('Some commands could not be registered:', $output);
$this->assertStringContainsString('throwing', $output);
$this->assertStringContainsString('fine', $output);
}

public function testRegistrationErrorsAreDisplayedOnCommandNotFound()
Expand All @@ -188,8 +188,8 @@ public function testRegistrationErrorsAreDisplayedOnCommandNotFound()
$output = $tester->getDisplay();

$this->assertSame(1, $tester->getStatusCode());
$this->assertContains('Some commands could not be registered:', $output);
$this->assertContains('Command "fine" is not defined.', $output);
$this->assertStringContainsString('Some commands could not be registered:', $output);
$this->assertStringContainsString('Command "fine" is not defined.', $output);
}

private function getKernel(array $bundles, $useDispatcher = false)
Expand Down
Expand Up @@ -127,9 +127,9 @@ public function testInvalidBundleName($bundleName, $suggestedBundleName)

if (false === $suggestedBundleName) {
// make sure we don't have a suggestion
$this->assertNotContains('Did you mean', $e->getMessage());
$this->assertStringNotContainsString('Did you mean', $e->getMessage());
} else {
$this->assertContains(sprintf('Did you mean "%s"', $suggestedBundleName), $e->getMessage());
$this->assertStringContainsString(sprintf('Did you mean "%s"', $suggestedBundleName), $e->getMessage());
}
}
}
Expand Down
Expand Up @@ -186,8 +186,8 @@ public function testFile()
if ($response->headers->get('content-type')) {
$this->assertSame('text/x-php', $response->headers->get('content-type'));
}
$this->assertContains(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $response->headers->get('content-disposition'));
$this->assertContains(basename(__FILE__), $response->headers->get('content-disposition'));
$this->assertStringContainsString(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $response->headers->get('content-disposition'));
$this->assertStringContainsString(basename(__FILE__), $response->headers->get('content-disposition'));
}

public function testFileAsInline()
Expand All @@ -202,8 +202,8 @@ public function testFileAsInline()
if ($response->headers->get('content-type')) {
$this->assertSame('text/x-php', $response->headers->get('content-type'));
}
$this->assertContains(ResponseHeaderBag::DISPOSITION_INLINE, $response->headers->get('content-disposition'));
$this->assertContains(basename(__FILE__), $response->headers->get('content-disposition'));
$this->assertStringContainsString(ResponseHeaderBag::DISPOSITION_INLINE, $response->headers->get('content-disposition'));
$this->assertStringContainsString(basename(__FILE__), $response->headers->get('content-disposition'));
}

public function testFileWithOwnFileName()
Expand All @@ -219,8 +219,8 @@ public function testFileWithOwnFileName()
if ($response->headers->get('content-type')) {
$this->assertSame('text/x-php', $response->headers->get('content-type'));
}
$this->assertContains(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $response->headers->get('content-disposition'));
$this->assertContains($fileName, $response->headers->get('content-disposition'));
$this->assertStringContainsString(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $response->headers->get('content-disposition'));
$this->assertStringContainsString($fileName, $response->headers->get('content-disposition'));
}

public function testFileWithOwnFileNameAsInline()
Expand All @@ -236,8 +236,8 @@ public function testFileWithOwnFileNameAsInline()
if ($response->headers->get('content-type')) {
$this->assertSame('text/x-php', $response->headers->get('content-type'));
}
$this->assertContains(ResponseHeaderBag::DISPOSITION_INLINE, $response->headers->get('content-disposition'));
$this->assertContains($fileName, $response->headers->get('content-disposition'));
$this->assertStringContainsString(ResponseHeaderBag::DISPOSITION_INLINE, $response->headers->get('content-disposition'));
$this->assertStringContainsString($fileName, $response->headers->get('content-disposition'));
}

public function testFileFromPath()
Expand All @@ -252,8 +252,8 @@ public function testFileFromPath()
if ($response->headers->get('content-type')) {
$this->assertSame('text/x-php', $response->headers->get('content-type'));
}
$this->assertContains(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $response->headers->get('content-disposition'));
$this->assertContains(basename(__FILE__), $response->headers->get('content-disposition'));
$this->assertStringContainsString(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $response->headers->get('content-disposition'));
$this->assertStringContainsString(basename(__FILE__), $response->headers->get('content-disposition'));
}

public function testFileFromPathWithCustomizedFileName()
Expand All @@ -268,8 +268,8 @@ public function testFileFromPathWithCustomizedFileName()
if ($response->headers->get('content-type')) {
$this->assertSame('text/x-php', $response->headers->get('content-type'));
}
$this->assertContains(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $response->headers->get('content-disposition'));
$this->assertContains('test.php', $response->headers->get('content-disposition'));
$this->assertStringContainsString(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $response->headers->get('content-disposition'));
$this->assertStringContainsString('test.php', $response->headers->get('content-disposition'));
}

public function testFileWhichDoesNotExist()
Expand Down
Expand Up @@ -824,9 +824,9 @@ public function testValidationMapping()

$this->assertSame('addYamlMappings', $calls[4][0]);
$this->assertCount(3, $calls[4][1][0]);
$this->assertContains('foo.yml', $calls[4][1][0][0]);
$this->assertContains('validation.yml', $calls[4][1][0][1]);
$this->assertContains('validation.yaml', $calls[4][1][0][2]);
$this->assertStringContainsString('foo.yml', $calls[4][1][0][0]);
$this->assertStringContainsString('validation.yml', $calls[4][1][0][1]);
$this->assertStringContainsString('validation.yaml', $calls[4][1][0][2]);
}

public function testFormsCanBeEnabledWithoutCsrfProtection()
Expand Down
Expand Up @@ -31,8 +31,8 @@ public function testClearPrivatePool()
$tester->execute(['pools' => ['cache.private_pool']], ['decorated' => false]);

$this->assertSame(0, $tester->getStatusCode(), 'cache:pool:clear exits with 0 in case of success');
$this->assertContains('Clearing cache pool: cache.private_pool', $tester->getDisplay());
$this->assertContains('[OK] Cache was successfully cleared.', $tester->getDisplay());
$this->assertStringContainsString('Clearing cache pool: cache.private_pool', $tester->getDisplay());
$this->assertStringContainsString('[OK] Cache was successfully cleared.', $tester->getDisplay());
}

public function testClearPublicPool()
Expand All @@ -41,8 +41,8 @@ public function testClearPublicPool()
$tester->execute(['pools' => ['cache.public_pool']], ['decorated' => false]);

$this->assertSame(0, $tester->getStatusCode(), 'cache:pool:clear exits with 0 in case of success');
$this->assertContains('Clearing cache pool: cache.public_pool', $tester->getDisplay());
$this->assertContains('[OK] Cache was successfully cleared.', $tester->getDisplay());
$this->assertStringContainsString('Clearing cache pool: cache.public_pool', $tester->getDisplay());
$this->assertStringContainsString('[OK] Cache was successfully cleared.', $tester->getDisplay());
}

public function testClearPoolWithCustomClearer()
Expand All @@ -51,8 +51,8 @@ public function testClearPoolWithCustomClearer()
$tester->execute(['pools' => ['cache.pool_with_clearer']], ['decorated' => false]);

$this->assertSame(0, $tester->getStatusCode(), 'cache:pool:clear exits with 0 in case of success');
$this->assertContains('Clearing cache pool: cache.pool_with_clearer', $tester->getDisplay());
$this->assertContains('[OK] Cache was successfully cleared.', $tester->getDisplay());
$this->assertStringContainsString('Clearing cache pool: cache.pool_with_clearer', $tester->getDisplay());
$this->assertStringContainsString('[OK] Cache was successfully cleared.', $tester->getDisplay());
}

public function testCallClearer()
Expand All @@ -61,8 +61,8 @@ public function testCallClearer()
$tester->execute(['pools' => ['cache.app_clearer']], ['decorated' => false]);

$this->assertSame(0, $tester->getStatusCode(), 'cache:pool:clear exits with 0 in case of success');
$this->assertContains('Calling cache clearer: cache.app_clearer', $tester->getDisplay());
$this->assertContains('[OK] Cache was successfully cleared.', $tester->getDisplay());
$this->assertStringContainsString('Calling cache clearer: cache.app_clearer', $tester->getDisplay());
$this->assertStringContainsString('[OK] Cache was successfully cleared.', $tester->getDisplay());
}

public function testClearUnexistingPool()
Expand All @@ -86,7 +86,7 @@ public function testLegacyClearCommand()

$tester->execute(['pools' => []]);

$this->assertContains('Cache was successfully cleared', $tester->getDisplay());
$this->assertStringContainsString('Cache was successfully cleared', $tester->getDisplay());
}

private function createCommandTester()
Expand Down

0 comments on commit 08573a1

Please sign in to comment.