8000 minor #37831 stop using deprecated PHPUnit APIs (xabbuh) · symfony/symfony@dbe4e83 · GitHub
[go: up one dir, main page]

Skip to content

Commit dbe4e83

Browse files
committed
minor #37831 stop using deprecated PHPUnit APIs (xabbuh)
This PR was merged into the 4.4 branch. Discussion ---------- stop using deprecated PHPUnit APIs | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | Commits ------- 3d209c4 stop using deprecated PHPUnit APIs
2 parents 85090fc + 3d209c4 commit dbe4e83

File tree

28 files changed

+224
-177
lines changed

28 files changed

+224
-177
lines changed

src/Symfony/Bridge/Twig/Tests/Command/LintCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function testLintFileWithReportedDeprecation()
9191
$ret = $tester->execute(['filename' => [$filename], '--show-deprecations' => true], ['verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false]);
9292

9393
$this->assertEquals(1, $ret, 'Returns 1 in case of error');
94-
$this->assertRegExp('/ERROR in \S+ \(line 1\)/', trim($tester->getDisplay()));
94+
$this->assertMatchesRegularExpression('/ERROR in \S+ \(line 1\)/', trim($tester->getDisplay()));
9595
$this->assertStringContainsString('Filter "deprecated_filter" is deprecated', trim($tester->getDisplay()));
9696
}
9797

src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ public function testDebugLegacyDefaultDirectory()
7878
$tester = $this->createCommandTester(['foo' => 'foo'], ['bar' => 'bar']);
7979
$tester->execute(['locale' => 'en']);
8080

81-
$this->assertRegExp('/missing/', $tester->getDisplay());
82-
$this->assertRegExp('/unused/', $tester->getDisplay());
81+
$this->assertMatchesRegularExpression('/missing/', $tester->getDisplay());
82+
$this->assertMatchesRegularExpression('/unused/', $tester->getDisplay());
8383
}
8484

8585
public function testDebugDefaultRootDirectory()

src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,31 @@ public function testDumpSortedMessagesAndClean()
3636
{
3737
$tester = $this->createCommandTester(['messages' => ['foo' => 'foo', 'test' => 'test', 'bar' => 'bar']]);
3838
$tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--sort' => 'asc']);
39-
$this->assertRegExp("/\*bar\*foo\*test/", preg_replace('/\s+/', '', $tester->getDisplay()));
40-
$this->assertRegExp('/3 messages were successfully extracted/', $tester->getDisplay());
39+
$this->assertMatchesRegularExpression("/\*bar\*foo\*test/", preg_replace('/\s+/', '', $tester->getDisplay()));
40+
$this->assertMatchesRegularExpression('/3 messages were successfully extracted/', $tester->getDisplay());
4141
}
4242

4343
public function testDumpReverseSortedMessagesAndClean()
4444
{
4545
$tester = $this->createCommandTester(['messages' => ['foo' => 'foo', 'test' => 'test', 'bar' => 'bar']]);
4646
$tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--sort' => 'desc']);
47-
$this->assertRegExp("/\*test\*foo\*bar/", preg_replace('/\s+/', '', $tester->getDisplay()));
48-
$this->assertRegExp('/3 messages were successfully extracted/', $tester->getDisplay());
47+
$this->assertMatchesRegularExpression("/\*test\*foo\*bar/", preg_replace('/\s+/', '', $tester->getDisplay()));
48+
$this->assertMatchesRegularExpression('/3 messages were successfully extracted/', $tester->getDisplay());
4949
}
5050

5151
public function testDumpSortWithoutValueAndClean()
5252
{
5353
$tester = $this->createCommandTester(['messages' => ['foo' => 'foo', 'test' => 'test', 'bar' => 'bar']]);
5454
$tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--sort']);
55-
$this->assertRegExp("/\*bar\*foo\*test/", preg_replace('/\s+/', '', $tester->getDisplay()));
56-
$this->assertRegExp('/3 messages were successfully extracted/', $tester->getDisplay());
55+
$this->assertMatchesRegularExpression("/\*bar\*foo\*test/", preg_replace('/\s+/', '', $tester->getDisplay()));
56+
$this->assertMatchesRegularExpression('/3 messages were successfully extracted/', $tester->getDisplay());
5757
}
5858

5959
public function testDumpWrongSortAndClean()
6060
{
6161
$tester = $this->createCommandTester(['messages' => ['foo' => 'foo', 'test' => 'test', 'bar' => 'bar']]);
6262
$tester->execute(['command' => 'translation:update', 'locale' => 'en', 'bundle' => 'foo', '--dump-messages' => true, '--clean' => true, '--sort' => 'test']);
63-
$this->assertRegExp('/\[ERROR\] Wrong sort order/', $tester->getDisplay());
63+
$this->assertMatchesRegularExpression('/\[ERROR\] Wrong sort order/', $tester->getDisplay());
6464
}
6565

6666
public function testDumpMessagesAndCleanInRootDirectory()
@@ -126,7 +126,7 @@ public function testWriteMessagesInLegacyRootDirectory()
126126

127127
$tester = $this->createCommandTester(['messages' => ['foo' => 'foo']]);
128128
$tester->execute(['command' => 'translation:update', 'locale' => 'en', '--force' => true]);
129-
$this->assertRegExp('/Translation files were successfully updated./', $tester->getDisplay());
129+
$this->assertMatchesRegularExpression('/Translation files were successfully updated./', $tester->getDisplay());
130130
}
131131

132132
public function testWriteMessagesForSpecificDomain()

src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,19 +232,19 @@ public function testRunOnlyWarnsOnUnregistrableCommandAtTheEnd()
232232
public function testSuggestingPackagesWithExactMatch()
233233
{
234234
$result = $this->createEventForSuggestingPackages('server:dump', []);
235-
$this->assertRegExp('/You may be looking for a command provided by/', $result);
235+
$this->assertMatchesRegularExpression('/You may be looking for a command provided by/', $result);
236236
}
237237

238238
public function testSuggestingPackagesWithPartialMatchAndNoAlternatives()
239239
{
240240
$result = $this->createEventForSuggestingPackages('server', []);
241-
$this->assertRegExp('/You may be looking for a command provided by/', $result);
241+
$this->assertMatchesRegularExpression('/You may be looking for a command provided by/', $result);
242242
}
243243

244244
public function testSuggestingPackagesWithPartialMatchAndAlternatives()
245245
{
246246
$result = $this->createEventForSuggestingPackages('server', ['server:run']);
247-
$this->assertNotRegExp('/You may be looking for a command provided by/', $result);
247+
$this->assertDoesNotMatchRegularExpression('/You may be looking for a command provided by/', $result);
248248
}
249249

250250
private function createEventForSuggestingPackages(string $command, array $alternatives = []): string

src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ public function testParentClassNotFoundThrowsException()
417417
$pass->process($container);
418418
$this->fail('AutowirePass should have thrown an exception');
419419
} catch (AutowiringFailedException $e) {
420-
$this->assertRegExp('{^Cannot autowire service "a": argument "\$r" of method "(Symfony\\\\Component\\\\DependencyInjection\\\\Tests\\\\Compiler\\\\)BadParentTypeHintedArgument::__construct\(\)" has type "\1OptionalServiceClass" but this class is missing a parent class \(Class "?Symfony\\\\Bug\\\\NotExistClass"? not found}', (string) $e->getMessage());
420+
$this->assertMatchesRegularExpression('{^Cannot autowire service "a": argument "\$r" of method "(Symfony\\\\Component\\\\DependencyInjection\\\\Tests\\\\Compiler\\\\ F438 )BadParentTypeHintedArgument::__construct\(\)" has type "\1OptionalServiceClass" but this class is missing a parent class \(Class "?Symfony\\\\Bug\\\\NotExistClass"? not found}', (string) $e->getMessage());
421421
}
422422
}
423423

src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,23 +196,23 @@ public function testLoadImports()
196196
$this->fail('->load() throws a LoaderLoadException if the imported xml file configuration does not exist');
197197
} catch (\Exception $e) {
198198
$this->assertInstanceOf('Symfony\\Component\\Config\\Exception\\LoaderLoadException', $e, '->load() throws a LoaderLoadException if the imported xml file configuration does not exist');
199-
$this->assertRegExp(sprintf('#^The file "%1$s" does not exist \(in: .+\) in %1$s \(which is being imported from ".+%2$s"\)\.$#', 'foo_fake\.xml', 'services4_bad_import_with_errors\.xml'), $e->getMessage(), '->load() throws a LoaderLoadException if the imported xml file configuration does not exist');
199+
$this->assertMatchesRegularExpression(sprintf('#^The file "%1$s" does not exist \(in: .+\) in %1$s \(which is being imported from ".+%2$s"\)\.$#', 'foo_fake\.xml', 'services4_bad_import_with_errors\.xml'), $e->getMessage(), '->load() throws a LoaderLoadException if the imported xml file configuration does not exist');
200200

201201
$e = $e->getPrevious();
202202
$this->assertInstanceOf('Symfony\\Component\\Config\\Exception\\FileLocatorFileNotFoundException', $e, '->load() throws a FileLocatorFileNotFoundException if the imported xml file configuration does not exist');
203-
$this->assertRegExp(sprintf('#^The file "%s" does not exist \(in: .+\)\.$#', 'foo_fake\.xml'), $e->getMessage(), '->load() throws a FileLocatorFileNotFoundException if the imported xml file configuration does not exist');
203+
$this->assertMatchesRegularExpression(sprintf('#^The file "%s" does not exist \(in: .+\)\.$#', 'foo_fake\.xml'), $e->getMessage(), '->load() throws a FileLocatorFileNotFoundException if the imported xml file configuration does not exist');
204204
}
205205

206206
try {
207207
$loader->load('services4_bad_import_nonvalid.xml');
208208
$this->fail('->load() throws an LoaderLoadException if the imported configuration does not validate the XSD');
209209
} catch (\Exception $e) {
210210
$this->assertInstanceOf('Symfony\\Component\\Config\\Exception\\LoaderLoadException', $e, '->load() throws a LoaderLoadException if the imported configuration does not validate the XSD');
211-
$this->assertRegExp(sprintf('#^Unable to parse file ".+%s": .+.$#', 'nonvalid\.xml'), $e->getMessage(), '->load() throws a LoaderLoadException if the imported configuration does not validate the XSD');
211+
$this->assertMatchesRegularExpression(sprintf('#^Unable to parse file ".+%s": .+.$#', 'nonvalid\.xml'), $e->getMessage(), '->load() throws a LoaderLoadException if the imported configuration does not validate the XSD');
212212

213213
$e = $e->getPrevious();
214214
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Exception\\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
215-
$this->assertRegExp(sprintf('#^Unable to parse file ".+%s": .+.$#', 'nonvalid\.xml'), $e->getMessage(), '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
215+
$this->assertMatchesRegularExpression(sprintf('#^Unable to parse file ".+%s": .+.$#', 'nonvalid\.xml'), $e->getMessage(), '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
216216

217217
$e = $e->getPrevious();
218218
$this->assertInstanceOf('Symfony\\Component\\Config\\Util\\Exception\\XmlParsingException', $e, '->load() throws a XmlParsingException if the configuration does not validate the XSD');

src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,23 +144,23 @@ public function testLoadImports()
144144
$this->fail('->load() throws a LoaderLoadException if the imported yaml file does not exist');
145145
} catch (\Exception $e) {
146146
$this->assertInstanceOf('Symfony\\Component\\Config\\Exception\\LoaderLoadException', $e, '->load() throws a LoaderLoadException if the imported yaml file does not exist');
147-
$this->assertRegExp(sprintf('#^The file "%1$s" does not exist \(in: .+\) in %1$s \(which is being imported from ".+%2$s"\)\.$#', 'foo_fake\.yml', 'services4_bad_import_with_errors\.yml'), $e->getMessage(), '->load() throws a LoaderLoadException if the imported yaml file does not exist');
147+
$this->assertMatchesRegularExpression(sprintf('#^The file "%1$s" does not exist \(in: .+\) in %1$s \(which is being imported from ".+%2$s"\)\.$#', 'foo_fake\.yml', 'services4_bad_import_with_errors\.yml'), $e->getMessage(), '->load() throws a LoaderLoadException if the imported yaml file does not exist');
148148

149149
$e = $e->getPrevious();
150150
$this->assertInstanceOf('Symfony\\Component\\Config\\Exception\\FileLocatorFileNotFoundException', $e, '->load() throws a FileLocatorFileNotFoundException if the imported yaml file does not exist');
151-
$this->assertRegExp(sprintf('#^The file "%s" does not exist \(in: .+\)\.$#', 'foo_fake\.yml'), $e->getMessage(), '->load() throws a FileLocatorFileNotFoundException if the imported yaml file does not exist');
151+
$this->assertMatchesRegularExpression(sprintf('#^The file "%s" does not exist \(in: .+\)\.$#', 'foo_fake\.yml'), $e->getMessage(), '->load() throws a FileLocatorFileNotFoundException if the imported yaml file does not exist');
152152
}
153153

154154
try {
155155
$loader->load('services4_bad_import_nonvalid.yml');
156156
$this->fail('->load() throws a LoaderLoadException if the tag in the imported yaml file is not valid');
157157
} catch (\Exception $e) {
158158
$this->assertInstanceOf('Symfony\\Component\\Config\\Exception\\LoaderLoadException', $e, '->load() throws a LoaderLoadException if the tag in the imported yaml file is not valid');
159-
$this->assertRegExp(sprintf('#^The service file ".+%1$s" is not valid\. It should contain an array\. Check your YAML syntax in .+%1$s \(which is being imported from ".+%2$s"\)\.$#', 'nonvalid2\.yml', 'services4_bad_import_nonvalid.yml'), $e->getMessage(), '->load() throws a LoaderLoadException if the tag in the imported yaml file is not valid');
159+
$this->assertMatchesRegularExpression(sprintf('#^The service file ".+%1$s" is not valid\. It should contain an array\. Check your YAML syntax in .+%1$s \(which is being imported from ".+%2$s"\)\.$#', 'nonvalid2\.yml', 'services4_bad_import_nonvalid.yml'), $e->getMessage(), '->load() throws a LoaderLoadException if the tag in the imported yaml file is not valid');
160160

161161
$e = $e->getPrevious();
162162
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Exception\\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the tag in the imported yaml file is not valid');
163-
$this->assertRegExp(sprintf('#^The service file ".+%s" is not valid\. It should contain an array\. Check your YAML syntax\.$#', 'nonvalid2\.yml'), $e->getMessage(), '->load() throws an InvalidArgumentException if the tag in the imported yaml file is not valid');
163+
$this->assertMatchesRegularExpression(sprintf('#^The service file ".+%s" is not valid\. It should contain an array\. Check your YAML syntax\.$#', 'nonvalid2\.yml'), $e->getMessage(), '->load() throws an InvalidArgumentException if the tag in the imported yaml file is not valid');
164164
}
165165
}
166166

src/Symfony/Component/ErrorHandler/Tests/ErrorHandlerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ public function testNotice()
9393
// if an exception is thrown, the test passed
9494
if (\PHP_VERSION_ID < 80000) {
9595
$this->assertEquals(E_NOTICE, $exception->getSeverity());
96-
$this->assertRegExp('/^Notice: Undefined variable: (foo|bar)/', $exception->getMessage());
96+
$this->assertMatchesRegularExpression('/^Notice: Undefined variable: (foo|bar)/', $exception->getMessage());
9797
} else {
9898
$this->assertEquals(E_WARNING, $exception->getSeverity());
99-
$this->assertRegExp('/^Warning: Undefined variable \$(foo|bar)/', $exception->getMessage());
99+
$this->assertMatchesRegularExpression('/^Warning: Undefined variable \$(foo|bar)/', $exception->getMessage());
100100
}
101101
$this->assertEquals(__FILE__, $exception->getFile());
102102

src/Symfony/Component/Filesystem/Tests/FilesystemTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ public function testRemoveSymlink()
821821

822822
$this->assertFalse(is_link($link));
823823
$this->assertFalse(is_file($link));
824-
$this->assertDirectoryNotExists($link);
824+
$this->assertDirectoryDoesNotExist($link);
825825
}
826826

827827
public function testSymlinkIsOverwrittenIfPointsToDifferentTarget()

src/Symfony/Component/Finder/Tests/GitignoreTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ public function testCases(string $patterns, array $matchingCases, array $nonMatc
2323
$regex = Gitignore::toRegex($patterns);
2424

2525
foreach ($matchingCases as $matchingCase) {
26-
$this->assertRegExp($regex, $matchingCase, sprintf('Failed asserting path [%s] matches gitignore patterns [%s] using regex [%s]', $matchingCase, $patterns, $regex));
26+
$this->assertMatchesRegularExpression($regex, $matchingCase, sprintf('Failed asserting path [%s] matches gitignore patterns [%s] using regex [%s]', $matchingCase, $patterns, $regex));
2727
}
2828

2929
foreach ($nonMatchingCases as $nonMatchingCase) {
30-
$this->assertNotRegExp($regex, $nonMatchingCase, sprintf('Failed asserting path [%s] not matching gitignore patterns [%s] using regex [%s]', $nonMatchingCase, $patterns, $regex));
30+
$this->assertDoesNotMatchRegularExpression($regex, $nonMatchingCase, sprintf('Failed asserting path [%s] not matching gitignore patterns [%s] using regex [%s]', $nonMatchingCase, $patterns, $regex));
3131
}
3232
}
3333

src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleAwareListenerTest.php

+16Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ public function testLocaleIsSetInOnKernelRequest()
4747
public function testDefaultLocaleIsUsedOnExceptionsInOnKernelRequest()
4848
{
4949
$this->localeAwareService
50-
->expects($this->at(0))
50+
->expects($this->exactly(2))
5151
->method('setLocale')
52-
->will($this->throwException(new \InvalidArgumentException()));
53-
$this->localeAwareService
54-
->expects($this->at(1))
55-
->method('setLocale')
56-
->with($this->equalTo('en'));
52+
->withConsecutive(
53+
[$this->anything()],
54+
['en']
55+
)
56+
->willReturnOnConsecutiveCalls(
57+
$this->throwException(new \InvalidArgumentException())
58+
);
5759

5860
$event = new RequestEvent($this->createHttpKernel(), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST);
5961
$this->listener->onKernelRequest($event);
@@ -89,13 +91,15 @@ public function testLocaleIsSetToDefaultOnKernelFinishRequestWhenParentRequestDo
8991
public function testDefaultLocaleIsUsedOnExceptionsInOnKernelFinishRequest()
9092
{
9193
$this->localeAwareService
92-
->expects($this->at(0))
94+
->expects($this->exactly(2))
9395
->method('setLocale')
94-
->will($this->throwException(new \InvalidArgumentException()));
95-
$this->localeAwareService
96-
->expects($this->at(1))
97-
->method('setLocale')
98-
->with($this->equalTo('en'));
96+
->withConsecutive(
97+
[$this->anything()],
98+
['en']
99+
)
100+
->willReturnOnConsecutiveCalls(
101+
$this->throwException(new \InvalidArgumentException())
102+
);
99103

100104
$this->requestStack->push($this->createRequest('fr'));
101105
$this->requestStack->push($subRequest = $this->createRequest('de'));

src/Symfony/Component/HttpKernel/Tests/KernelTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ public function getContainerClass(): string
662662
}
663663
};
664664

665-
$this->assertRegExp('/^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*TestDebugContainer$/', $kernel->getContainerClass());
665+
$this->assertMatchesRegularExpression('/^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*TestDebugContainer$/', $kernel->getContainerClass());
666666
}
667667

668668
/**

0 commit comments

Comments
 (0)
0