Skip to content

Commit

Permalink
EZP-30675: Replaced deprecated PHPUnit asserts with proper ones (#2669)
Browse files Browse the repository at this point in the history
* Changed deprecated assertions

* Changed deprecated assertions - assertAttribute and similar

* [CS] Enabled CS rules for PHPUnit dedicated asserts
  • Loading branch information
mikadamczyk authored and alongosz committed Jun 19, 2019
1 parent 6a97051 commit 322f11c
Show file tree
Hide file tree
Showing 90 changed files with 315 additions and 959 deletions.
2 changes: 2 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ return PhpCsFixer\Config::create()
'phpdoc_types_order' => false,
'php_unit_mock_short_will_return' => false,
'php_unit_construct' => false,
'php_unit_dedicate_assert' => true,
'php_unit_dedicate_assert_internal_type' => true,
'standardize_increment' => false,
'fopen_flags' => false,
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testProcess()

$expressionString = 'service("ezpublish.config.complex_setting_value.resolver").resolveSetting("/mnt/nfs/$var_dir$/$storage_dir$", "var_dir", service("ezpublish.config.resolver").getParameter("var_dir", null, null), "storage_dir", service("ezpublish.config.resolver").getParameter("storage_dir", null, null))';
$arguments = $definition->getArguments();
self::assertSame(1, count($arguments));
self::assertCount(1, $arguments);
self::assertInstanceOf(Expression::class, $arguments[0]);
self::assertSame($expressionString, (string)$arguments[0]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ public function testRepositoriesConfigurationFieldGroups($repositories, $expecte
foreach ($repositoriesPar as $key => $repo) {
$this->assertArrayHasKey($key, $expectedRepositories);
$this->assertArrayHasKey('fields_groups', $repo);
$this->assertEquals($expectedRepositories[$key]['fields_groups'], $repo['fields_groups'], 'Invalid fields groups element', 0.0, 10, true);
$this->assertEqualsCanonicalizing($expectedRepositories[$key]['fields_groups'], $repo['fields_groups'], 'Invalid fields groups element');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function testFindBadPathRoot()
try {
$this->binaryLoader->find($path);
} catch (NotLoadableException $e) {
$this->assertContains(
$this->assertStringContainsString(
"Suggested value: '1/2/3/123-name/name.png'",
$e->getMessage()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,40 @@

class PlaceholderProviderRegistryTest extends TestCase
{
private const FOO = 'foo';
private const BAR = 'bar';

/**
* @covers \eZ\Bundle\EzPublishCoreBundle\Imagine\PlaceholderProviderRegistry::__construct
* @uses \eZ\Bundle\EzPublishCoreBundle\Imagine\PlaceholderProviderRegistry::getProvider
* @depends testGetProviderKnown
*/
public function testConstructor()
{
$providers = [
'foo' => $this->getPlaceholderProviderMock(),
'bar' => $this->getPlaceholderProviderMock(),
self::FOO => $this->getPlaceholderProviderMock(),
self::BAR => $this->getPlaceholderProviderMock(),
];

$registry = new PlaceholderProviderRegistry($providers);

$this->assertAttributeSame($providers, 'providers', $registry);
$this->assertSame($providers[self::FOO], $registry->getProvider(self::FOO));
$this->assertSame($providers[self::BAR], $registry->getProvider(self::BAR));
}

public function testAddProvider()
/**
* @covers \eZ\Bundle\EzPublishCoreBundle\Imagine\PlaceholderProviderRegistry::addProvider
* @uses \eZ\Bundle\EzPublishCoreBundle\Imagine\PlaceholderProviderRegistry::getProvider
* @depends testGetProviderKnown
*/
public function testAddProvider(): void
{
$provider = $this->getPlaceholderProviderMock();

$registry = new PlaceholderProviderRegistry();
$registry->addProvider('foo', $provider);
$registry->addProvider(self::FOO, $provider);

$this->assertAttributeSame(['foo' => $provider], 'providers', $registry);
$this->assertSame($provider, $registry->getProvider(self::FOO));
}

public function testSupports()
Expand All @@ -51,21 +65,21 @@ public function testGetProviderKnown()
$provider = $this->getPlaceholderProviderMock();

$registry = new PlaceholderProviderRegistry([
'foo' => $provider,
self::FOO => $provider,
]);

$this->assertEquals($provider, $registry->getProvider('foo'));
$this->assertEquals($provider, $registry->getProvider(self::FOO));
}

public function testGetProviderUnknown()
{
$this->expectException(\InvalidArgumentException::class);

$registry = new PlaceholderProviderRegistry([
'foo' => $this->getPlaceholderProviderMock(),
self::FOO => $this->getPlaceholderProviderMock(),
]);

$registry->getProvider('bar');
$registry->getProvider(self::BAR);
}

private function getPlaceholderProviderMock(): PlaceholderProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function testCollect()
$collector = new GlobCollector($translationRootDir);

$files = $collector->collect();
$this->assertEquals(3, count($files));
$this->assertCount(3, $files);
foreach ($files as $file) {
$this->assertTrue(in_array($file['domain'], ['messages', 'dashboard']));
$this->assertTrue(in_array($file['locale'], ['fr', 'ach_UG']));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1627,9 +1627,9 @@ public function testLoadRelationsWithUnauthorizedRelations()
}

// verify all expected relations were found
$this->assertEquals(
$this->assertCount(
0,
count($expectedRelations),
$expectedRelations,
"Expected to find '" . (count($expectedRelations) + count($actualRelations))
. "' relations found '" . count($actualRelations) . "'"
);
Expand Down
38 changes: 19 additions & 19 deletions eZ/Publish/API/Repository/Tests/ContentServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2051,7 +2051,7 @@ public function testPublishVersionNotCreatingUnlimitedArchives()

// load first to make sure list gets updated also (cache)
$versionInfoList = $contentService->loadVersions($content->contentInfo);
$this->assertEquals(1, count($versionInfoList));
$this->assertCount(1, $versionInfoList);
$this->assertEquals(1, $versionInfoList[0]->versionNo);

// Create a new draft with versionNo = 2
Expand Down Expand Up @@ -2080,7 +2080,7 @@ public function testPublishVersionNotCreatingUnlimitedArchives()

$versionInfoList = $contentService->loadVersions($content->contentInfo);

$this->assertEquals(6, count($versionInfoList));
$this->assertCount(6, $versionInfoList);
$this->assertEquals(2, $versionInfoList[0]->versionNo);
$this->assertEquals(7, $versionInfoList[5]->versionNo);

Expand Down Expand Up @@ -3366,9 +3366,9 @@ public function testCopyContent()
$contentCopied->id
);

$this->assertEquals(
$this->assertCount(
2,
count($contentService->loadVersions($contentCopied->contentInfo))
$contentService->loadVersions($contentCopied->contentInfo)
);

$this->assertEquals(2, $contentCopied->getVersionInfo()->versionNo);
Expand Down Expand Up @@ -3489,9 +3489,9 @@ public function testCopyContentWithThirdParameter()
$contentCopied->id
);

$this->assertEquals(
$this->assertCount(
1,
count($contentService->loadVersions($contentCopied->contentInfo))
$contentService->loadVersions($contentCopied->contentInfo)
);

$this->assertEquals(1, $contentCopied->getVersionInfo()->versionNo);
Expand Down Expand Up @@ -3549,9 +3549,9 @@ public function testAddRelation()
*/
public function testAddRelationAddsRelationToContent($relations)
{
$this->assertEquals(
$this->assertCount(
1,
count($relations)
$relations
);
}

Expand Down Expand Up @@ -3630,9 +3630,9 @@ public function testCreateContentDraftWithRelations()
*/
public function testCreateContentDraftWithRelationsCreatesRelations($relations)
{
$this->assertEquals(
$this->assertCount(
1,
count($relations)
$relations
);

return $relations;
Expand Down Expand Up @@ -3939,8 +3939,8 @@ public function testLoadReverseRelations()
$this->assertEquals($contentInfo->id, $relation2->getDestinationContentInfo()->id);
$this->assertEquals($demoDesignDraft->id, $relation2->getSourceContentInfo()->id);

$this->assertEquals(0, count($relations));
$this->assertEquals(2, count($reverseRelations));
$this->assertCount(0, $relations);
$this->assertCount(2, $reverseRelations);

usort(
$reverseRelations,
Expand Down Expand Up @@ -4041,8 +4041,8 @@ public function testLoadReverseRelationsSkipsArchivedContent()
$this->assertEquals($contentInfo->id, $relation2->getDestinationContentInfo()->id);
$this->assertEquals($demoDesignDraft->id, $relation2->getSourceContentInfo()->id);

$this->assertEquals(0, count($relations));
$this->assertEquals(1, count($reverseRelations));
$this->assertCount(0, $relations);
$this->assertCount(1, $reverseRelations);

$this->assertEquals(
array(
Expand Down Expand Up @@ -4117,8 +4117,8 @@ public function testLoadReverseRelationsSkipsDraftContent()
$this->assertEquals($media->contentInfo->id, $relation2->getDestinationContentInfo()->id);
$this->assertEquals($demoDesignDraft->id, $relation2->getSourceContentInfo()->id);

$this->assertEquals(0, count($relations));
$this->assertEquals(1, count($reverseRelations));
$this->assertCount(0, $relations);
$this->assertCount(1, $reverseRelations);

$this->assertEquals(
array(
Expand Down Expand Up @@ -4170,7 +4170,7 @@ public function testDeleteRelation()
$relations = $contentService->loadRelations($draft->getVersionInfo());
/* END: Use Case */

$this->assertEquals(1, count($relations));
$this->assertCount(1, $relations);
}

/**
Expand Down Expand Up @@ -5086,7 +5086,7 @@ public function testCopyContentInTransactionWithRollback()
)->locations;
/* END: Use Case */

$this->assertEquals(1, count($locations));
$this->assertCount(1, $locations);
}

/**
Expand Down Expand Up @@ -5146,7 +5146,7 @@ public function testCopyContentInTransactionWithCommit()
)->locations;
/* END: Use Case */

$this->assertEquals(2, count($locations));
$this->assertCount(2, $locations);
}

public function testURLAliasesCreatedForNewContent()
Expand Down
18 changes: 8 additions & 10 deletions eZ/Publish/API/Repository/Tests/ContentTypeServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,7 @@ public function testLoadContentTypeGroups()
$loadedGroups = $contentTypeService->loadContentTypeGroups();
/* END: Use Case */

$this->assertInternalType(
'array',
$loadedGroups
$this->assertIsArray($loadedGroups
);

foreach ($loadedGroups as $loadedGroup) {
Expand Down Expand Up @@ -366,7 +364,7 @@ public function testLoadContentTypeGroups()
*/
public function testLoadContentTypeGroupsIdentifiers($groups)
{
$this->assertEquals(4, count($groups));
$this->assertCount(4, $groups);

$expectedIdentifiers = array(
'Content' => true,
Expand Down Expand Up @@ -1123,10 +1121,10 @@ public function testCreateContentTypeThrowsContentTypeFieldDefinitionValidationE

/* @var $validationErrors */
$this->assertTrue(isset($validationErrors));
$this->assertInternalType('array', $validationErrors);
$this->assertIsArray($validationErrors);
$this->assertCount(1, $validationErrors);
$this->assertArrayHasKey('temperature', $validationErrors);
$this->assertInternalType('array', $validationErrors['temperature']);
$this->assertIsArray($validationErrors['temperature']);
$this->assertCount(1, $validationErrors['temperature']);
$this->assertInstanceOf('eZ\\Publish\\Core\\FieldType\\ValidationError', $validationErrors['temperature'][0]);

Expand Down Expand Up @@ -1618,10 +1616,10 @@ public function testAddFieldDefinitionThrowsContentTypeFieldDefinitionValidation

/* @var $validationErrors */
$this->assertTrue(isset($validationErrors));
$this->assertInternalType('array', $validationErrors);
$this->assertIsArray($validationErrors);
$this->assertCount(1, $validationErrors);
$this->assertArrayHasKey('temperature', $validationErrors);
$this->assertInternalType('array', $validationErrors['temperature']);
$this->assertIsArray($validationErrors['temperature']);
$this->assertCount(1, $validationErrors['temperature']);
$this->assertInstanceOf('eZ\\Publish\\Core\\FieldType\\ValidationError', $validationErrors['temperature'][0]);

Expand Down Expand Up @@ -2953,7 +2951,7 @@ public function testLoadContentTypeList()

$types = $contentTypeService->loadContentTypeList([3, 4]);

$this->assertInternalType('iterable', $types);
$this->assertIsIterable($types);

$this->assertEquals(
[
Expand Down Expand Up @@ -2985,7 +2983,7 @@ public function testLoadContentTypes()
$types = $contentTypeService->loadContentTypes($contentTypeGroup);
/* END: Use Case */

$this->assertInternalType('array', $types);
$this->assertIsArray($types);

return $types;
}
Expand Down
2 changes: 1 addition & 1 deletion eZ/Publish/API/Repository/Tests/FieldTypeServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function testGetFieldTypes()
/* END: Use Case */

// Require at least 1 field type
$this->assertNotEquals(0, count($fieldTypes));
$this->assertNotCount(0, $fieldTypes);

foreach ($fieldTypes as $fieldType) {
$this->assertInstanceOf(
Expand Down
12 changes: 6 additions & 6 deletions eZ/Publish/API/Repository/Tests/LanguageServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function testLoadLanguageById()

$languages = $languageService->loadLanguageListById([$languageId]);

$this->assertInternalType('iterable', $languages);
$this->assertIsIterable($languages);
$this->assertCount(1, $languages);
$this->assertInstanceOf(Language::class, $languages[$languageId]);
}
Expand All @@ -200,7 +200,7 @@ public function testLoadLanguageByIdThrowsNotFoundException()

$languages = $languageService->loadLanguageListById([$nonExistentLanguageId]);

$this->assertInternalType('iterable', $languages);
$this->assertIsIterable($languages);
$this->assertCount(0, $languages);

$this->expectException(NotFoundException::class);
Expand Down Expand Up @@ -368,7 +368,7 @@ public function testLoadLanguage()

$languages = $languageService->loadLanguageListByCode(['eng-NZ']);

$this->assertInternalType('iterable', $languages);
$this->assertIsIterable($languages);
$this->assertCount(1, $languages);

$this->assertPropertiesCorrect(
Expand Down Expand Up @@ -397,7 +397,7 @@ public function testLoadLanguageThrowsNotFoundException()

$languages = $languageService->loadLanguageListByCode(['fre-FR']);

$this->assertInternalType('iterable', $languages);
$this->assertIsIterable($languages);
$this->assertCount(0, $languages);

$this->expectException(NotFoundException::class);
Expand Down Expand Up @@ -449,7 +449,7 @@ public function testLoadLanguages()
$languageService->createLanguage($languageCreateFrench);

$languages = $languageService->loadLanguages();
self::assertInternalType('array', $languages);
self::assertIsArray($languages);
foreach ($languages as $language) {
self::assertInstanceOf(Language::class, $language);
$singleLanguage = $languageService->loadLanguage($language->languageCode);
Expand All @@ -462,7 +462,7 @@ public function testLoadLanguages()
/* END: Use Case */

// eng-US, eng-GB, ger-DE + 2 newly created
$this->assertEquals(5, count($languages));
$this->assertCount(5, $languages);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function testLoadLocationListFiltersUnauthorizedLocations(): void

$locations = $locationService->loadLocationList([13]);

self::assertInternalType('iterable', $locations);
self::assertIsIterable($locations);
self::assertCount(0, $locations);
}

Expand Down
Loading

0 comments on commit 322f11c

Please sign in to comment.