Skip to content

replace assertEmpty() with stricter assertions #59898

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public function testClassNoAutoMapping()
$this->assertSame(AutoMappingStrategy::DISABLED, $classMetadata->getAutoMappingStrategy());

$maxLengthMetadata = $classMetadata->getPropertyMetadata('maxLength');
$this->assertEmpty($maxLengthMetadata);
$this->assertSame([], $maxLengthMetadata);

/** @var PropertyMetadata[] $autoMappingExplicitlyEnabledMetadata */
$autoMappingExplicitlyEnabledMetadata = $classMetadata->getPropertyMetadata('autoMappingExplicitlyEnabled');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function testAttributesAreCached()
$reader = new AttributeReader();
$cacheRef = new \ReflectionProperty(AttributeReader::class, 'cache');

self::assertEmpty($cacheRef->getValue($reader));
self::assertSame([], $cacheRef->getValue($reader));

$reader->forClass(FooBar::class, TimeSensitive::class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1592,7 +1592,7 @@ public function testDateErrorBubbling()
$form->get('date')->addError(new FormError('[trans]Error![/trans]'));
$view = $form->createView();

$this->assertEmpty($this->renderErrors($view));
$this->assertSame('', $this->renderErrors($view));
$this->assertNotEmpty($this->renderErrors($view['date']));
}

Expand Down Expand Up @@ -2213,7 +2213,7 @@ public function testTimeErrorBubbling()
$form->get('time')->addError(new FormError('[trans]Error![/trans]'));
$view = $form->createView();

$this->assertEmpty($this->renderErrors($view));
$this->assertSame('', $this->renderErrors($view));
$this->assertNotEmpty($this->renderErrors($view['time']));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,6 @@ public function testCustomDumper()
'Custom dumper should be used to dump data.'
);

$this->assertEmpty($output, 'Dumper output should be ignored.');
$this->assertSame('', $output, 'Dumper output should be ignored.');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ public function testMessengerServicesRemovedWhenDisabled()
\ARRAY_FILTER_USE_KEY
);

$this->assertEmpty($messengerDefinitions);
$this->assertSame([], $messengerDefinitions);
$this->assertFalse($container->hasDefinition('console.command.messenger_consume_messages'));
$this->assertFalse($container->hasDefinition('console.command.messenger_debug'));
$this->assertFalse($container->hasDefinition('console.command.messenger_stop_workers'));
Expand Down Expand Up @@ -1941,7 +1941,7 @@ public function testRemovesResourceCheckerConfigCacheFactoryArgumentOnlyIfNoDebu

$container = $this->createContainer(['kernel.debug' => false]);
(new FrameworkExtension())->load([['annotations' => false, 'http_method_override' => false, 'handle_all_throwables' => true, 'php_errors' => ['log' => true]]], $container);
$this->assertEmpty($container->getDefinition('config_cache_factory')->getArguments());
$this->assertSame([], $container->getDefinition('config_cache_factory')->getArguments());
}

public function testLoggerAwareRegistration()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testMapQueryString(string $uri, array $query, string $expectedRe
if ($expectedResponse) {
self::assertJsonStringEqualsJsonString($expectedResponse, $response->getContent());
} else {
self::assertEmpty($response->getContent());
self::assertSame('', $response->getContent());
}
self::assertSame($expectedStatusCode, $response->getStatusCode());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function testCollectWhenSecurityIsDisabled()
$this->assertFalse($collector->supportsRoleHierarchy());
$this->assertCount(0, $collector->getRoles());
$this->assertCount(0, $collector->getInheritedRoles());
$this->assertEmpty($collector->getUser());
$this->assertSame('', $collector->getUser());
$this->assertNull($collector->getFirewall());
}

Expand All @@ -73,7 +73,7 @@ public function testCollectWhenAuthenticationTokenIsNull()
$this->assertTrue($collector->supportsRoleHierarchy());
$this->assertCount(0, $collector->getRoles());
$this->assertCount(0, $collector->getInheritedRoles());
$this->assertEmpty($collector->getUser());
$this->assertSame('', $collector->getUser());
$this->assertNull($collector->getFirewall());
}

Expand Down Expand Up @@ -425,7 +425,7 @@ public function testGetVotersIfAccessDecisionManagerHasNoVoters()

$dataCollector->collect(new Request(), new Response());

$this->assertEmpty($dataCollector->getVoters());
$this->assertSame([], $dataCollector->getVoters());
}

public static function provideRoles(): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function testGetBasePath()
{
$nullContext = new NullContext();

$this->assertEmpty($nullContext->getBasePath());
$this->assertSame('', $nullContext->getBasePath());
}

public function testIsSecure()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testGetBasePathEmpty()
{
$requestStackContext = new RequestStackContext(new RequestStack());

$this->assertEmpty($requestStackContext->getBasePath());
$this->assertSame('', $requestStackContext->getBasePath());
}

public function testGetBasePathSet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function testGetVersion()
$emptyVersionStrategy = new EmptyVersionStrategy();
$path = 'test-path';

$this->assertEmpty($emptyVersionStrategy->getVersion($path));
$this->assertSame('', $emptyVersionStrategy->getVersion($path));
}

public function testApplyVersion()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,10 +642,10 @@ public function testFollowRedirectDropPostMethod()
$client->request('POST', 'http://www.example.com/foo/foobar', $parameters, $files, $server, $content);

$this->assertSame('http://www.example.com/redirected', $client->getRequest()->getUri(), '->followRedirect() follows a redirect with POST method on response code: '.$code.'.');
$this->assertEmpty($client->getRequest()->getParameters(), '->followRedirect() drops parameters with POST method on response code: '.$code.'.');
$this->assertEmpty($client->getRequest()->getFiles(), '->followRedirect() drops files with POST method on response code: '.$code.'.');
$this->assertSame([], $client->getRequest()->getParameters(), '->followRedirect() drops parameters with POST method on response code: '.$code.'.');
$this->assertSame([], $client->getRequest()->getFiles(), '->followRedirect() drops files with POST method on response code: '.$code.'.');
$this->assertArrayHasKey('X_TEST_FOO', $client->getRequest()->getServer(), '->followRedirect() keeps $_SERVER with POST method on response code: '.$code.'.');
$this->assertEmpty($client->getRequest()->getContent(), '->followRedirect() drops content with POST method on response code: '.$code.'.');
$this->assertNull($client->getRequest()->getContent(), '->followRedirect() drops content with POST method on response code: '.$code.'.');
$this->assertSame('GET', $client->getRequest()->getMethod(), '->followRedirect() drops request method to GET on response code: '.$code.'.');
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/BrowserKit/Tests/CookieJarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,6 @@ public function testCookieWithWildcardDomain()
$cookieJar->set(new Cookie('foo', 'bar', null, '/', '.example.com'));

$this->assertEquals(['foo' => 'bar'], $cookieJar->allValues('http://www.example.com'));
$this->assertEmpty($cookieJar->allValues('http://wwwexample.com'));
$this->assertSame([], $cookieJar->allValues('http://wwwexample.com'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function testConfigureSchemaTableExists()
$adapter = new DoctrineDbalAdapter($connection);
$adapter->configureSchema($schema, $connection, fn () => true);
$table = $schema->getTable('cache_items');
$this->assertEmpty($table->getColumns(), 'The table was not overwritten');
$this->assertSame([], $table->getColumns(), 'The table was not overwritten');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function testGetDefaultValueReturnsAnEmptyArrayForPrototypes()
$node = new PrototypedArrayNode('root');
$prototype = new ArrayNode(null, $node);
$node->setPrototype($prototype);
$this->assertEmpty($node->getDefaultValue());
$this->assertSame([], $node->getDefaultValue());
}

public function testGetDefaultValueReturnsDefaultValueForPrototypes()
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public function testSilentHelp()
$tester = new ApplicationTester($application);
$tester->run(['-h' => true, '-q' => true], ['decorated' => false]);

$this->assertEmpty($tester->getDisplay(true));
$this->assertSame('', $tester->getDisplay(true));
}

public function testGetInvalidCommand()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public function testProcessMovesTagsFromDecoratedDefinitionToDecoratingDefinitio

$this->process($container);

$this->assertEmpty($container->getDefinition('baz.inner')->getTags());
$this->assertSame([], $container->getDefinition('baz.inner')->getTags());
$this->assertEquals(['bar' => ['attr' => 'baz'], 'foobar' => ['attr' => 'bar'], 'container.decorator' => [['id' => 'foo', 'inner' => 'baz.inner']]], $container->getDefinition('baz')->getTags());
}

Expand All @@ -220,7 +220,7 @@ public function testProcessMovesTagsFromDecoratedDefinitionToDecoratingDefinitio

$this->process($container);

$this->assertEmpty($container->getDefinition('deco1')->getTags());
$this->assertSame([], $container->getDefinition('deco1')->getTags());
$this->assertEquals(['bar' => ['attr' => 'baz'], 'container.decorator' => [['id' => 'foo', 'inner' => 'deco1.inner']]], $container->getDefinition('deco2')->getTags());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public function testPassOrderingWithoutPasses()
$config->setOptimizationPasses([]);
$config->setRemovingPasses([]);

$this->assertEmpty($config->getBeforeOptimizationPasses());
$this->assertEmpty($config->getAfterRemovingPasses());
$this->assertEmpty($config->getBeforeRemovingPasses());
$this->assertEmpty($config->getOptimizationPasses());
$this->assertEmpty($config->getRemovingPasses());
$this->assertSame([], $config->getBeforeOptimizationPasses());
$this->assertSame([], $config->getAfterRemovingPasses());
$this->assertSame([], $config->getBeforeRemovingPasses());
$this->assertSame([], $config->getOptimizationPasses());
$this->assertSame([], $config->getRemovingPasses());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testProcess()

$parent = '.instanceof.'.parent::class.'.0.foo';
$def = $container->getDefinition('foo');
$this->assertEmpty($def->getInstanceofConditionals());
$this->assertSame([], $def->getInstanceofConditionals());
$this->assertInstanceOf(ChildDefinition::class, $def);
$this->assertTrue($def->isAutowired());
$this->assertSame($parent, $def->getParent());
Expand Down Expand Up @@ -266,10 +266,10 @@ public function testMergeReset()

$abstract = $container->getDefinition('.abstract.instanceof.bar');

$this->assertEmpty($abstract->getArguments());
$this->assertEmpty($abstract->getMethodCalls());
$this->assertSame([], $abstract->getArguments());
$this->assertSame([], $abstract->getMethodCalls());
$this->assertNull($abstract->getDecoratedService());
$this->assertEmpty($abstract->getTags());
$this->assertSame([], $abstract->getTags());
$this->assertTrue($abstract->isAbstract());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ public function testAddObjectResource()
$container->setResourceTracking(false);
$container->addObjectResource(new \BarClass());

$this->assertEmpty($container->getResources(), 'No resources get registered without resource tracking');
$this->assertSame([], $container->getResources(), 'No resources get registered without resource tracking');

$container->setResourceTracking(true);
$container->addObjectResource(new \BarClass());
Expand All @@ -1173,7 +1173,7 @@ public function testGetReflectionClass()
$container->setResourceTracking(false);
$r1 = $container->getReflectionClass('BarClass');

$this->assertEmpty($container->getResources(), 'No resources get registered without resource tracking');
$this->assertSame([], $container->getResources(), 'No resources get registered without resource tracking');

$container->setResourceTracking(true);
$r2 = $container->getReflectionClass('BarClass');
Expand Down Expand Up @@ -1213,7 +1213,7 @@ public function testCompilesClassDefinitionsOfLazyServices()
{
$container = new ContainerBuilder();

$this->assertEmpty($container->getResources(), 'No resources get registered without resource tracking');
$this->assertSame([], $container->getResources(), 'No resources get registered without resource tracking');

$container->register('foo', 'BarClass')->setPublic(true);
$container->getDefinition('foo')->setLazy(true);
Expand Down Expand Up @@ -1372,7 +1372,7 @@ public function testExtensionConfig()
$container = new ContainerBuilder();

$configs = $container->getExtensionConfig('foo');
$this->assertEmpty($configs);
$this->assertSame([], $configs);

$first = ['foo' => 'bar'];
$container->prependExtensionConfig('foo', $first);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ public function testLazyArgumentProvideGenerator()
}
}

$this->assertEmpty(iterator_to_array($lazyContext->lazyEmptyValues));
$this->assertSame([], iterator_to_array($lazyContext->lazyEmptyValues));
}

public function testNormalizedId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ public function testAnonymousServicesInInstanceof()
$anonymous = $container->getDefinition((string) $args['foo']);
$this->assertEquals('Anonymous', $anonymous->getClass());
$this->assertFalse($anonymous->isPublic());
$this->assertEmpty($anonymous->getInstanceofConditionals());
$this->assertSame([], $anonymous->getInstanceofConditionals());

$this->assertFalse($container->has('Bar'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function testMergeWhereFirstBagIsEmptyWillWork()
// initialize placeholder only in second bag
$secondBag->get($parameter);

$this->assertEmpty($firstBag->getEnvPlaceholders());
$this->assertSame([], $firstBag->getEnvPlaceholders());

$firstBag->mergeEnvPlaceholders($secondBag);
$mergedPlaceholders = $firstBag->getEnvPlaceholders();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testHtml5ParserWithInvalidHeadedContent(string $content)
{
$crawler = $this->createCrawler();
$crawler->addHtmlContent($content);
self::assertEmpty($crawler->filterXPath('//h1')->text(), '->addHtmlContent failed as expected');
self::assertSame('', $crawler->filterXPath('//h1')->text(), '->addHtmlContent failed as expected');
}

public function testHtml5ParserNotSameAsNativeParserForSpecificHtml()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public function testItReturnsNoOrphanedEventsWhenCreated()
{
$tdispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch());
$events = $tdispatcher->getOrphanedEvents();
$this->assertEmpty($events);
$this->assertSame([], $events);
}

public function testItReturnsOrphanedEventsAfterDispatch()
Expand All @@ -200,7 +200,7 @@ public function testItDoesNotReturnHandledEvents()
$tdispatcher->addListener('foo', function () {});
$tdispatcher->dispatch(new Event(), 'foo');
$events = $tdispatcher->getOrphanedEvents();
$this->assertEmpty($events);
$this->assertSame([], $events);
}

public function testLogger()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ public function testSubmitSingleExpandedRequired()

$this->assertSame('b', $form->getData());
$this->assertSame('b', $form->getViewData());
$this->assertEmpty($form->getExtraData());
$this->assertSame([], $form->getExtraData());
$this->assertTrue($form->isSynchronized());

$this->assertFalse($form[0]->getData());
Expand Down Expand Up @@ -906,7 +906,7 @@ public function testSubmitSingleExpandedRequiredInvalidChoice()

$this->assertNull($form->getData());
$this->assertSame('foobar', $form->getViewData());
$this->assertEmpty($form->getExtraData());
$this->assertSame([], $form->getExtraData());
$this->assertFalse($form->isSynchronized());

$this->assertFalse($form[0]->getData());
Expand Down Expand Up @@ -934,7 +934,7 @@ public function testSubmitSingleExpandedNonRequired()

$this->assertSame('b', $form->getData());
$this->assertSame('b', $form->getViewData());
$this->assertEmpty($form->getExtraData());
$this->assertSame([], $form->getExtraData());
$this->assertTrue($form->isSynchronized());

$this->assertFalse($form['placeholder']->getData());
Expand Down Expand Up @@ -964,7 +964,7 @@ public function testSubmitSingleExpandedNonRequiredInvalidChoice()

$this->assertNull($form->getData());
$this->assertSame('foobar', $form->getViewData());
$this->assertEmpty($form->getExtraData());
$this->assertSame([], $form->getExtraData());
$this->assertFalse($form->isSynchronized());

$this->assertFalse($form[0]->getData());
Expand Down Expand Up @@ -1348,7 +1348,7 @@ public function testSubmitMultipleExpanded()

$this->assertSame(['a', 'c'], $form->getData());
$this->assertSame(['a', 'c'], $form->getViewData());
$this->assertEmpty($form->getExtraData());
$this->assertSame([], $form->getExtraData());
$this->assertTrue($form->isSynchronized());

$this->assertTrue($form[0]->getData());
Expand All @@ -1375,7 +1375,7 @@ public function testSubmitMultipleExpandedInvalidScalarChoice()

$this->assertNull($form->getData());
$this->assertSame('foobar', $form->getViewData());
$this->assertEmpty($form->getExtraData());
$this->assertSame([], $form->getExtraData());
$this->assertFalse($form->isSynchronized());

$this->assertFalse($form[0]->getData());
Expand All @@ -1402,7 +1402,7 @@ public function testSubmitMultipleExpandedInvalidArrayChoice()

$this->assertSame(['a'], $form->getData());
$this->assertSame(['a'], $form->getViewData());
$this->assertEmpty($form->getExtraData());
$this->assertSame([], $form->getExtraData());
$this->assertFalse($form->isValid());

$this->assertTrue($form[0]->getData());
Expand Down
Loading
Loading