Skip to content

Commit

Permalink
Address assertContains() deprecations
Browse files Browse the repository at this point in the history
assertContains() is no longer supposed to be used with strings.
  • Loading branch information
greg0ire committed Sep 26, 2020
1 parent 427aec6 commit 440f681
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 12 deletions.
15 changes: 12 additions & 3 deletions Tests/Command/CreateDatabaseDoctrineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ public function testExecute() : void
array_merge(['command' => $command->getName()])
);

$this->assertContains('Created database ' . sys_get_temp_dir() . '/' . $dbName . ' for connection named ' . $connectionName, $commandTester->getDisplay());
$this->assertStringContainsString(
'Created database ' . sys_get_temp_dir() . '/' . $dbName . ' for connection named ' . $connectionName,
$commandTester->getDisplay()
);
}

/**
Expand Down Expand Up @@ -81,12 +84,18 @@ public function testExecuteWithShardAlias(string $shardOption) : void
$commandTester = new CommandTester($command);
$commandTester->execute(['command' => $command->getName(), $shardOption => 1]);

$this->assertContains('Created database ' . sys_get_temp_dir() . '/shard_1 for connection named ' . $connectionName, $commandTester->getDisplay());
$this->assertStringContainsString(
'Created database ' . sys_get_temp_dir() . '/shard_1 for connection named ' . $connectionName,
$commandTester->getDisplay()
);

$commandTester = new CommandTester($command);
$commandTester->execute(['command' => $command->getName(), $shardOption => 2]);

$this->assertContains('Created database ' . sys_get_temp_dir() . '/shard_2 for connection named ' . $connectionName, $commandTester->getDisplay());
$this->assertStringContainsString(
'Created database ' . sys_get_temp_dir() . '/shard_2 for connection named ' . $connectionName,
$commandTester->getDisplay()
);
}

public function provideShardOption() : Generator
Expand Down
9 changes: 6 additions & 3 deletions Tests/Command/DropDatabaseDoctrineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function testExecute(array $options) : void
array_merge(['command' => $command->getName()], $options)
);

$this->assertContains(
$this->assertStringContainsString(
sprintf(
'Dropped database %s for connection named %s',
sys_get_temp_dir() . '/' . $dbName,
Expand Down Expand Up @@ -77,15 +77,18 @@ public function testExecuteWithoutOptionForceWillFailWithAttentionMessage() : vo
array_merge(['command' => $command->getName()])
);

$this->assertContains(
$this->assertStringContainsString(
sprintf(
'Would drop the database %s for connection named %s.',
sys_get_temp_dir() . '/' . $dbName,
$connectionName
),
$commandTester->getDisplay()
);
$this->assertContains('Please run the operation with --force to execute', $commandTester->getDisplay());
$this->assertStringContainsString(
'Please run the operation with --force to execute',
$commandTester->getDisplay()
);
}

public function provideForceOption() : Generator
Expand Down
24 changes: 20 additions & 4 deletions Tests/Command/ImportMappingDoctrineCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ public function testExecuteXmlWithBundle() : void

$expectedMetadataPath = sys_get_temp_dir() . '/import_mapping_bundle/Resources/config/doctrine/Product.orm.xml';
$this->assertFileExists($expectedMetadataPath);
$this->assertContains('"Doctrine\Bundle\DoctrineBundle\Tests\Command\Entity\Product"', file_get_contents($expectedMetadataPath), 'Metadata contains correct namespace');
$this->assertStringContainsString(
'"Doctrine\Bundle\DoctrineBundle\Tests\Command\Entity\Product"',
file_get_contents($expectedMetadataPath),
'Metadata contains correct namespace'
);
}

public function testExecuteAnnotationsWithBundle() : void
Expand All @@ -82,7 +86,11 @@ public function testExecuteAnnotationsWithBundle() : void

$expectedMetadataPath = sys_get_temp_dir() . '/import_mapping_bundle/Entity/Product.php';
$this->assertFileExists($expectedMetadataPath);
$this->assertContains('namespace Doctrine\Bundle\DoctrineBundle\Tests\Command\Entity;', file_get_contents($expectedMetadataPath), 'File contains correct namespace');
$this->assertStringContainsString(
'namespace Doctrine\Bundle\DoctrineBundle\Tests\Command\Entity;',
file_get_contents($expectedMetadataPath),
'File contains correct namespace'
);
}

/**
Expand All @@ -103,7 +111,11 @@ public function testExecuteXmlWithNamespace() : void

$expectedMetadataPath = $this->kernel->getProjectDir() . '/config/doctrine/Product.orm.xml';
$this->assertFileExists($expectedMetadataPath);
$this->assertContains('"Some\Namespace\Entity\Product"', file_get_contents($expectedMetadataPath), 'Metadata contains correct namespace');
$this->assertStringContainsString(
'"Some\Namespace\Entity\Product"',
file_get_contents($expectedMetadataPath),
'Metadata contains correct namespace'
);
}

public function testExecuteAnnotationsWithNamespace() : void
Expand All @@ -116,7 +128,11 @@ public function testExecuteAnnotationsWithNamespace() : void

$expectedMetadataPath = $this->kernel->getProjectDir() . '/src/Entity/Product.php';
$this->assertFileExists($expectedMetadataPath);
$this->assertContains('namespace Some\Namespace\Entity;', file_get_contents($expectedMetadataPath), 'Metadata contains correct namespace');
$this->assertStringContainsString(
'namespace Some\Namespace\Entity;',
file_get_contents($expectedMetadataPath),
'Metadata contains correct namespace'
);
}
}

Expand Down
5 changes: 4 additions & 1 deletion Tests/DependencyInjection/AbstractDoctrineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,10 @@ public function testSecondLevelCache() : void
$this->assertEquals(600, $myEntityRegionArgs[2]);

$this->assertEquals('doctrine.orm.default_second_level_cache.region.my_query_region', $myQueryRegionArgs[0]);
$this->assertContains('/doctrine/orm/slc/filelock', $myQueryRegionArgs[1]);
$this->assertStringContainsString(
'/doctrine/orm/slc/filelock',
$myQueryRegionArgs[1]
);
$this->assertEquals(60, $myQueryRegionArgs[2]);

$this->assertEquals('doctrine.orm.default_second_level_cache.regions_configuration', $slcFactoryArgs[0]);
Expand Down
2 changes: 1 addition & 1 deletion Tests/ProfilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function testRender() : void
html_entity_decode($expectedEscapedSql)
);

$this->assertContains($expectedEscapedSql, $output);
$this->assertStringContainsString($expectedEscapedSql, $output);

$this->assertSame(1, preg_match('/' . str_replace(
' ',
Expand Down

0 comments on commit 440f681

Please sign in to comment.