Issue #3397890 by mstrelan, dww: Fix strict type errors in unit tests

(cherry picked from commit 910b569f8e)
merge-requests/5443/head
xjm 2023-11-15 19:57:15 -06:00
parent eab4bfa9a6
commit f66861ddd1
No known key found for this signature in database
GPG Key ID: 206B0B8743BDF4C2
15 changed files with 25 additions and 25 deletions

View File

@ -78,7 +78,7 @@ class BanMiddlewareTest extends UnitTestCase {
$request = Request::create('/test-path'); $request = Request::create('/test-path');
$request->server->set('REMOTE_ADDR', $unbanned_ip); $request->server->set('REMOTE_ADDR', $unbanned_ip);
$expected_response = new Response(200); $expected_response = new Response(status: 200);
$this->kernel->expects($this->once()) $this->kernel->expects($this->once())
->method('handle') ->method('handle')
->with($request, HttpKernelInterface::MAIN_REQUEST, TRUE) ->with($request, HttpKernelInterface::MAIN_REQUEST, TRUE)

View File

@ -48,7 +48,7 @@ class MigrationStateUnitTest extends UnitTestCase {
foreach ($files as $module => $contents) { foreach ($files as $module => $contents) {
$path = $url . '/' . $module . '/migrations/state'; $path = $url . '/' . $module . '/migrations/state';
mkdir($path, '0755', TRUE); mkdir($path, 0755, TRUE);
file_put_contents($path . '/' . $module . '.migrate_drupal.yml', $contents); file_put_contents($path . '/' . $module . '.migrate_drupal.yml', $contents);
} }
$moduleHandler->getModuleDirectories() $moduleHandler->getModuleDirectories()

View File

@ -149,7 +149,7 @@ class PasswordVerifyTest extends UnitTestCase {
// Check a string of 3-byte UTF-8 characters, 510 byte long password is // Check a string of 3-byte UTF-8 characters, 510 byte long password is
// allowed. // allowed.
$len = floor(PasswordInterface::PASSWORD_MAX_LENGTH / 3); $len = (int) floor(PasswordInterface::PASSWORD_MAX_LENGTH / 3);
$diff = PasswordInterface::PASSWORD_MAX_LENGTH % 3; $diff = PasswordInterface::PASSWORD_MAX_LENGTH % 3;
$passwords['utf8'] = [str_repeat('€', $len), TRUE]; $passwords['utf8'] = [str_repeat('€', $len), TRUE];
// 512 byte long password is allowed. // 512 byte long password is allowed.

View File

@ -178,7 +178,7 @@ class UpdateFetcherTest extends UnitTestCase {
// First, try without the HTTP fallback setting, and HTTPS mocked to fail. // First, try without the HTTP fallback setting, and HTTPS mocked to fail.
$settings = new Settings([]); $settings = new Settings([]);
$this->mockClient( $this->mockClient(
new Response('500', [], 'HTTPS failed'), new Response(500, [], 'HTTPS failed'),
); );
$update_fetcher = new UpdateFetcher($this->mockConfigFactory, $this->mockHttpClient, $settings, $this->logger); $update_fetcher = new UpdateFetcher($this->mockConfigFactory, $this->mockHttpClient, $settings, $this->logger);
@ -206,8 +206,8 @@ class UpdateFetcherTest extends UnitTestCase {
public function testUpdateFetcherHttpFallback() { public function testUpdateFetcherHttpFallback() {
$settings = new Settings(['update_fetch_with_http_fallback' => TRUE]); $settings = new Settings(['update_fetch_with_http_fallback' => TRUE]);
$this->mockClient( $this->mockClient(
new Response('500', [], 'HTTPS failed'), new Response(500, [], 'HTTPS failed'),
new Response('200', [], 'HTTP worked'), new Response(200, [], 'HTTP worked'),
); );
$update_fetcher = new UpdateFetcher($this->mockConfigFactory, $this->mockHttpClient, $settings, $this->logger); $update_fetcher = new UpdateFetcher($this->mockConfigFactory, $this->mockHttpClient, $settings, $this->logger);

View File

@ -186,7 +186,7 @@ class DateTimePlusTest extends TestCase {
* *
* @param \Drupal\Component\Datetime\DateTimePlus $date * @param \Drupal\Component\Datetime\DateTimePlus $date
* DateTimePlus to test. * DateTimePlus to test.
* @param string $input * @param string|int $input
* The original input passed to the test method. * The original input passed to the test method.
* @param array $initial * @param array $initial
* @see testTimestamp() * @see testTimestamp()
@ -195,7 +195,7 @@ class DateTimePlusTest extends TestCase {
* *
* @internal * @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. // Check format.
$value = $date->format($initial['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)); $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), 'input1' => DateTimePlus::createFromFormat('U', 3600),
'input2' => \DateTime::createFromFormat('U', 0), 'input2' => \DateTime::createFromFormat('U', '0'),
'absolute' => FALSE, 'absolute' => FALSE,
'expected' => $negative_1_hour, 'expected' => $negative_1_hour,
], ],
@ -706,7 +706,7 @@ class DateTimePlusTest extends TestCase {
], ],
[ [
'input1' => DateTimePlus::createFromFormat('U', 3600), 'input1' => DateTimePlus::createFromFormat('U', 3600),
'input2' => \DateTime::createFromFormat('U', 0), 'input2' => \DateTime::createFromFormat('U', '0'),
'absolute' => TRUE, 'absolute' => TRUE,
'expected' => $positive_1_hour, 'expected' => $positive_1_hour,
], ],

View File

@ -554,7 +554,7 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper {
public function testGetServiceDefinitionForDecoratedService() { public function testGetServiceDefinitionForDecoratedService() {
$bar_definition = new Definition('\stdClass'); $bar_definition = new Definition('\stdClass');
$bar_definition->setPublic(TRUE); $bar_definition->setPublic(TRUE);
$bar_definition->setDecoratedService(new Reference('foo')); $bar_definition->setDecoratedService((string) new Reference('foo'));
$services['bar'] = $bar_definition; $services['bar'] = $bar_definition;
$this->containerBuilder->getDefinitions()->willReturn($services); $this->containerBuilder->getDefinitions()->willReturn($services);

View File

@ -109,7 +109,7 @@ class DrupalDateTimeTest extends UnitTestCase {
], ],
[ [
'input1' => DrupalDateTime::createFromFormat('U', 3600, $utc_tz, $settings), 'input1' => DrupalDateTime::createFromFormat('U', 3600, $utc_tz, $settings),
'input2' => \DateTime::createFromFormat('U', 0), 'input2' => \DateTime::createFromFormat('U', '0'),
'absolute' => FALSE, 'absolute' => FALSE,
'expected' => $negative_1_hour, 'expected' => $negative_1_hour,
], ],
@ -121,7 +121,7 @@ class DrupalDateTimeTest extends UnitTestCase {
], ],
[ [
'input1' => DrupalDateTime::createFromFormat('U', 3600, $utc_tz, $settings), 'input1' => DrupalDateTime::createFromFormat('U', 3600, $utc_tz, $settings),
'input2' => \DateTime::createFromFormat('U', 0), 'input2' => \DateTime::createFromFormat('U', '0'),
'absolute' => TRUE, 'absolute' => TRUE,
'expected' => $positive_1_hour, 'expected' => $positive_1_hour,
], ],

View File

@ -184,7 +184,7 @@ class FormAjaxSubscriberTest extends UnitTestCase {
$container->set('renderer', $renderer); $container->set('renderer', $renderer);
\Drupal::setContainer($container); \Drupal::setContainer($container);
$exception = new BrokenPostRequestException(32 * 1e6); $exception = new BrokenPostRequestException((int) (32 * 1e6));
$request = new Request([FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]); $request = new Request([FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]);
$event = new ExceptionEvent($this->httpKernel, $request, HttpKernelInterface::MAIN_REQUEST, $exception); $event = new ExceptionEvent($this->httpKernel, $request, HttpKernelInterface::MAIN_REQUEST, $exception);

View File

@ -368,10 +368,10 @@ class FormStateTest extends UnitTestCase {
$this->assertFalse($form_state->hasTemporaryValue('rainbow_sparkles')); $this->assertFalse($form_state->hasTemporaryValue('rainbow_sparkles'));
$form_state->setTemporaryValue('rainbow_sparkles', 'yes'); $form_state->setTemporaryValue('rainbow_sparkles', 'yes');
$this->assertSame($form_state->getTemporaryValue('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'); $form_state->setTemporaryValue(['rainbow_sparkles', 'magic_ponies'], 'yes');
$this->assertSame($form_state->getTemporaryValue(['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']));
} }
/** /**

View File

@ -112,7 +112,7 @@ class PhpPasswordTest extends UnitTestCase {
// Check a string of 3-byte UTF-8 characters, 510 byte long password is // Check a string of 3-byte UTF-8 characters, 510 byte long password is
// allowed. // allowed.
$len = floor(PasswordInterface::PASSWORD_MAX_LENGTH / 3); $len = (int) floor(PasswordInterface::PASSWORD_MAX_LENGTH / 3);
$diff = PasswordInterface::PASSWORD_MAX_LENGTH % 3; $diff = PasswordInterface::PASSWORD_MAX_LENGTH % 3;
$passwords['utf8'] = [str_repeat('€', $len), TRUE]; $passwords['utf8'] = [str_repeat('€', $len), TRUE];
// 512 byte long password is allowed. // 512 byte long password is allowed.

View File

@ -471,7 +471,7 @@ class RendererBubblingTest extends RendererTestBase {
); );
// Simulate the rendering of an entire response (i.e. a root call). // 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. // 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.'); $this->assertEquals('Cache context!Cache tag!Asset!Placeholder!barquxNested!Cached nested!', trim($output), 'Expected HTML generated.');

View File

@ -70,7 +70,7 @@ class RendererRecursionTest extends RendererTestBase {
$this->setUpRequest(); $this->setUpRequest();
$callable = function ($markup) { $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; return $markup;
}; };

View File

@ -497,7 +497,7 @@ class RendererTest extends RendererTestBase {
'#markup' => $first, '#markup' => $first,
], ],
]; ];
$output = $this->renderer->renderRoot($elements); $output = (string) $this->renderer->renderRoot($elements);
// The lowest weight element should appear last in $output. // The lowest weight element should appear last in $output.
$this->assertGreaterThan(strpos($output, $first), strpos($output, $second)); $this->assertGreaterThan(strpos($output, $first), strpos($output, $second));
@ -533,7 +533,7 @@ class RendererTest extends RendererTestBase {
], ],
'#sorted' => TRUE, '#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. // The elements should appear in output in the same order as the array.
$this->assertLessThan(strpos($output, $first), strpos($output, $second)); $this->assertLessThan(strpos($output, $first), strpos($output, $second));

View File

@ -107,7 +107,7 @@ class TwigExtensionTest extends UnitTestCase {
$nodes = $twig->parse($twig->tokenize(new Source($template, $name))); $nodes = $twig->parse($twig->tokenize(new Source($template, $name)));
$this->assertSame($expected, $nodes->getNode('body') $this->assertSame($expected, $nodes->getNode('body')
->getNode(0) ->getNode('0')
->getNode('expr') instanceof FilterExpression); ->getNode('expr') instanceof FilterExpression);
} }

View File

@ -411,7 +411,7 @@ class LinkGeneratorTest extends UnitTestCase {
$url = new Url('test_route_4'); $url = new Url('test_route_4');
$url->setUrlGenerator($this->urlGenerator); $url->setUrlGenerator($this->urlGenerator);
$result = $this->linkGenerator->generate("<script>alert('XSS!')</script>", $url); $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', 'tag' => 'em',
], ],
], $result); ], $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 = new Url('test_route_1', [], ['set_active_class' => FALSE]);
$url->setUrlGenerator($this->urlGenerator); $url->setUrlGenerator($this->urlGenerator);
$result = $this->linkGenerator->generate('Test', $url); $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. // Render a link with an associated language.
$url = new Url('test_route_1', [], [ $url = new Url('test_route_1', [], [