Issue #3397890 by mstrelan, dww: Fix strict type errors in unit tests
(cherry picked from commit 910b569f8e
)
merge-requests/5443/head
parent
eab4bfa9a6
commit
f66861ddd1
|
@ -78,7 +78,7 @@ class BanMiddlewareTest extends UnitTestCase {
|
|||
|
||||
$request = Request::create('/test-path');
|
||||
$request->server->set('REMOTE_ADDR', $unbanned_ip);
|
||||
$expected_response = new Response(200);
|
||||
$expected_response = new Response(status: 200);
|
||||
$this->kernel->expects($this->once())
|
||||
->method('handle')
|
||||
->with($request, HttpKernelInterface::MAIN_REQUEST, TRUE)
|
||||
|
|
|
@ -48,7 +48,7 @@ class MigrationStateUnitTest extends UnitTestCase {
|
|||
|
||||
foreach ($files as $module => $contents) {
|
||||
$path = $url . '/' . $module . '/migrations/state';
|
||||
mkdir($path, '0755', TRUE);
|
||||
mkdir($path, 0755, TRUE);
|
||||
file_put_contents($path . '/' . $module . '.migrate_drupal.yml', $contents);
|
||||
}
|
||||
$moduleHandler->getModuleDirectories()
|
||||
|
|
|
@ -149,7 +149,7 @@ class PasswordVerifyTest extends UnitTestCase {
|
|||
|
||||
// Check a string of 3-byte UTF-8 characters, 510 byte long password is
|
||||
// allowed.
|
||||
$len = floor(PasswordInterface::PASSWORD_MAX_LENGTH / 3);
|
||||
$len = (int) floor(PasswordInterface::PASSWORD_MAX_LENGTH / 3);
|
||||
$diff = PasswordInterface::PASSWORD_MAX_LENGTH % 3;
|
||||
$passwords['utf8'] = [str_repeat('€', $len), TRUE];
|
||||
// 512 byte long password is allowed.
|
||||
|
|
|
@ -178,7 +178,7 @@ class UpdateFetcherTest extends UnitTestCase {
|
|||
// First, try without the HTTP fallback setting, and HTTPS mocked to fail.
|
||||
$settings = new Settings([]);
|
||||
$this->mockClient(
|
||||
new Response('500', [], 'HTTPS failed'),
|
||||
new Response(500, [], 'HTTPS failed'),
|
||||
);
|
||||
$update_fetcher = new UpdateFetcher($this->mockConfigFactory, $this->mockHttpClient, $settings, $this->logger);
|
||||
|
||||
|
@ -206,8 +206,8 @@ class UpdateFetcherTest extends UnitTestCase {
|
|||
public function testUpdateFetcherHttpFallback() {
|
||||
$settings = new Settings(['update_fetch_with_http_fallback' => TRUE]);
|
||||
$this->mockClient(
|
||||
new Response('500', [], 'HTTPS failed'),
|
||||
new Response('200', [], 'HTTP worked'),
|
||||
new Response(500, [], 'HTTPS failed'),
|
||||
new Response(200, [], 'HTTP worked'),
|
||||
);
|
||||
$update_fetcher = new UpdateFetcher($this->mockConfigFactory, $this->mockHttpClient, $settings, $this->logger);
|
||||
|
||||
|
|
|
@ -186,7 +186,7 @@ class DateTimePlusTest extends TestCase {
|
|||
*
|
||||
* @param \Drupal\Component\Datetime\DateTimePlus $date
|
||||
* DateTimePlus to test.
|
||||
* @param string $input
|
||||
* @param string|int $input
|
||||
* The original input passed to the test method.
|
||||
* @param array $initial
|
||||
* @see testTimestamp()
|
||||
|
@ -195,7 +195,7 @@ class DateTimePlusTest extends TestCase {
|
|||
*
|
||||
* @internal
|
||||
*/
|
||||
public function assertDateTimestamp(DateTimePlus $date, string $input, array $initial, array $transform): void {
|
||||
public function assertDateTimestamp(DateTimePlus $date, string|int $input, array $initial, array $transform): void {
|
||||
// Check format.
|
||||
$value = $date->format($initial['format']);
|
||||
$this->assertEquals($initial['expected_date'], $value, sprintf("Test new DateTimePlus(%s, %s): should be %s, found %s.", $input, $initial['timezone'], $initial['expected_date'], $value));
|
||||
|
@ -694,7 +694,7 @@ class DateTimePlusTest extends TestCase {
|
|||
],
|
||||
[
|
||||
'input1' => DateTimePlus::createFromFormat('U', 3600),
|
||||
'input2' => \DateTime::createFromFormat('U', 0),
|
||||
'input2' => \DateTime::createFromFormat('U', '0'),
|
||||
'absolute' => FALSE,
|
||||
'expected' => $negative_1_hour,
|
||||
],
|
||||
|
@ -706,7 +706,7 @@ class DateTimePlusTest extends TestCase {
|
|||
],
|
||||
[
|
||||
'input1' => DateTimePlus::createFromFormat('U', 3600),
|
||||
'input2' => \DateTime::createFromFormat('U', 0),
|
||||
'input2' => \DateTime::createFromFormat('U', '0'),
|
||||
'absolute' => TRUE,
|
||||
'expected' => $positive_1_hour,
|
||||
],
|
||||
|
|
|
@ -554,7 +554,7 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
|
|||
public function testGetServiceDefinitionForDecoratedService() {
|
||||
$bar_definition = new Definition('\stdClass');
|
||||
$bar_definition->setPublic(TRUE);
|
||||
$bar_definition->setDecoratedService(new Reference('foo'));
|
||||
$bar_definition->setDecoratedService((string) new Reference('foo'));
|
||||
$services['bar'] = $bar_definition;
|
||||
|
||||
$this->containerBuilder->getDefinitions()->willReturn($services);
|
||||
|
|
|
@ -109,7 +109,7 @@ class DrupalDateTimeTest extends UnitTestCase {
|
|||
],
|
||||
[
|
||||
'input1' => DrupalDateTime::createFromFormat('U', 3600, $utc_tz, $settings),
|
||||
'input2' => \DateTime::createFromFormat('U', 0),
|
||||
'input2' => \DateTime::createFromFormat('U', '0'),
|
||||
'absolute' => FALSE,
|
||||
'expected' => $negative_1_hour,
|
||||
],
|
||||
|
@ -121,7 +121,7 @@ class DrupalDateTimeTest extends UnitTestCase {
|
|||
],
|
||||
[
|
||||
'input1' => DrupalDateTime::createFromFormat('U', 3600, $utc_tz, $settings),
|
||||
'input2' => \DateTime::createFromFormat('U', 0),
|
||||
'input2' => \DateTime::createFromFormat('U', '0'),
|
||||
'absolute' => TRUE,
|
||||
'expected' => $positive_1_hour,
|
||||
],
|
||||
|
|
|
@ -184,7 +184,7 @@ class FormAjaxSubscriberTest extends UnitTestCase {
|
|||
$container->set('renderer', $renderer);
|
||||
\Drupal::setContainer($container);
|
||||
|
||||
$exception = new BrokenPostRequestException(32 * 1e6);
|
||||
$exception = new BrokenPostRequestException((int) (32 * 1e6));
|
||||
$request = new Request([FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]);
|
||||
|
||||
$event = new ExceptionEvent($this->httpKernel, $request, HttpKernelInterface::MAIN_REQUEST, $exception);
|
||||
|
|
|
@ -368,10 +368,10 @@ class FormStateTest extends UnitTestCase {
|
|||
$this->assertFalse($form_state->hasTemporaryValue('rainbow_sparkles'));
|
||||
$form_state->setTemporaryValue('rainbow_sparkles', 'yes');
|
||||
$this->assertSame($form_state->getTemporaryValue('rainbow_sparkles'), 'yes');
|
||||
$this->assertTrue($form_state->hasTemporaryValue('rainbow_sparkles'), TRUE);
|
||||
$this->assertTrue($form_state->hasTemporaryValue('rainbow_sparkles'));
|
||||
$form_state->setTemporaryValue(['rainbow_sparkles', 'magic_ponies'], 'yes');
|
||||
$this->assertSame($form_state->getTemporaryValue(['rainbow_sparkles', 'magic_ponies']), 'yes');
|
||||
$this->assertTrue($form_state->hasTemporaryValue(['rainbow_sparkles', 'magic_ponies']), TRUE);
|
||||
$this->assertTrue($form_state->hasTemporaryValue(['rainbow_sparkles', 'magic_ponies']));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -112,7 +112,7 @@ class PhpPasswordTest extends UnitTestCase {
|
|||
|
||||
// Check a string of 3-byte UTF-8 characters, 510 byte long password is
|
||||
// allowed.
|
||||
$len = floor(PasswordInterface::PASSWORD_MAX_LENGTH / 3);
|
||||
$len = (int) floor(PasswordInterface::PASSWORD_MAX_LENGTH / 3);
|
||||
$diff = PasswordInterface::PASSWORD_MAX_LENGTH % 3;
|
||||
$passwords['utf8'] = [str_repeat('€', $len), TRUE];
|
||||
// 512 byte long password is allowed.
|
||||
|
|
|
@ -471,7 +471,7 @@ class RendererBubblingTest extends RendererTestBase {
|
|||
);
|
||||
|
||||
// Simulate the rendering of an entire response (i.e. a root call).
|
||||
$output = $this->renderer->renderRoot($test_element);
|
||||
$output = (string) $this->renderer->renderRoot($test_element);
|
||||
|
||||
// First, assert the render array is of the expected form.
|
||||
$this->assertEquals('Cache context!Cache tag!Asset!Placeholder!barquxNested!Cached nested!', trim($output), 'Expected HTML generated.');
|
||||
|
|
|
@ -70,7 +70,7 @@ class RendererRecursionTest extends RendererTestBase {
|
|||
$this->setUpRequest();
|
||||
|
||||
$callable = function ($markup) {
|
||||
$this->assertStringStartsWith('<drupal-render-placeholder', $markup, 'Rendered complex child output as expected, without the placeholder replaced, i.e. with just the placeholder.');
|
||||
$this->assertStringStartsWith('<drupal-render-placeholder', (string) $markup, 'Rendered complex child output as expected, without the placeholder replaced, i.e. with just the placeholder.');
|
||||
return $markup;
|
||||
};
|
||||
|
||||
|
|
|
@ -497,7 +497,7 @@ class RendererTest extends RendererTestBase {
|
|||
'#markup' => $first,
|
||||
],
|
||||
];
|
||||
$output = $this->renderer->renderRoot($elements);
|
||||
$output = (string) $this->renderer->renderRoot($elements);
|
||||
|
||||
// The lowest weight element should appear last in $output.
|
||||
$this->assertGreaterThan(strpos($output, $first), strpos($output, $second));
|
||||
|
@ -533,7 +533,7 @@ class RendererTest extends RendererTestBase {
|
|||
],
|
||||
'#sorted' => TRUE,
|
||||
];
|
||||
$output = $this->renderer->renderRoot($elements);
|
||||
$output = (string) $this->renderer->renderRoot($elements);
|
||||
|
||||
// The elements should appear in output in the same order as the array.
|
||||
$this->assertLessThan(strpos($output, $first), strpos($output, $second));
|
||||
|
|
|
@ -107,7 +107,7 @@ class TwigExtensionTest extends UnitTestCase {
|
|||
$nodes = $twig->parse($twig->tokenize(new Source($template, $name)));
|
||||
|
||||
$this->assertSame($expected, $nodes->getNode('body')
|
||||
->getNode(0)
|
||||
->getNode('0')
|
||||
->getNode('expr') instanceof FilterExpression);
|
||||
}
|
||||
|
||||
|
|
|
@ -411,7 +411,7 @@ class LinkGeneratorTest extends UnitTestCase {
|
|||
$url = new Url('test_route_4');
|
||||
$url->setUrlGenerator($this->urlGenerator);
|
||||
$result = $this->linkGenerator->generate("<script>alert('XSS!')</script>", $url);
|
||||
$this->assertNoXPathResults('//a[@href="/test-route-4"]/script', $result);
|
||||
$this->assertNoXPathResults('//a[@href="/test-route-4"]/script', (string) $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -450,7 +450,7 @@ class LinkGeneratorTest extends UnitTestCase {
|
|||
'tag' => 'em',
|
||||
],
|
||||
], $result);
|
||||
$this->assertStringContainsString('<em>HTML output</em>', $result);
|
||||
$this->assertStringContainsString('<em>HTML output</em>', (string) $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -499,7 +499,7 @@ class LinkGeneratorTest extends UnitTestCase {
|
|||
$url = new Url('test_route_1', [], ['set_active_class' => FALSE]);
|
||||
$url->setUrlGenerator($this->urlGenerator);
|
||||
$result = $this->linkGenerator->generate('Test', $url);
|
||||
$this->assertNoXPathResults('//a[@data-drupal-link-system-path="test-route-1"]', $result);
|
||||
$this->assertNoXPathResults('//a[@data-drupal-link-system-path="test-route-1"]', (string) $result);
|
||||
|
||||
// Render a link with an associated language.
|
||||
$url = new Url('test_route_1', [], [
|
||||
|
|
Loading…
Reference in New Issue