Skip to content

Commit

Permalink
Address PHPUnit's warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
greg0ire authored and OskarStark committed Feb 17, 2020
1 parent 467a143 commit d516656
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 30 deletions.
16 changes: 10 additions & 6 deletions tests/Admin/AdminTest.php
Expand Up @@ -32,6 +32,7 @@
use Sonata\AdminBundle\Builder\ShowBuilderInterface;
use Sonata\AdminBundle\Datagrid\DatagridInterface;
use Sonata\AdminBundle\Datagrid\PagerInterface;
use Sonata\AdminBundle\Filter\Persister\FilterPersisterInterface;
use Sonata\AdminBundle\Model\AuditManagerInterface;
use Sonata\AdminBundle\Model\ModelManagerInterface;
use Sonata\AdminBundle\Route\DefaultRouteGenerator;
Expand Down Expand Up @@ -1440,14 +1441,17 @@ public function testTransChoiceWithMessageDomain(): void

public function testSetFilterPersister(): void
{
$admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle:PostAdmin');
$admin = new class('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'SonataNewsBundle\Controller\PostAdminController') extends PostAdmin {
public function persistFilters(): bool
{
return $this->persistFilters;
}
};

$filterPersister = $this->createMock('Sonata\AdminBundle\Filter\Persister\FilterPersisterInterface');
$filterPersister = $this->createMock(FilterPersisterInterface::class);

$this->assertAttributeSame(null, 'filterPersister', $admin);
$admin->setFilterPersister($filterPersister);
$this->assertAttributeSame($filterPersister, 'filterPersister', $admin);
$this->assertAttributeSame(true, 'persistFilters', $admin);
$this->assertTrue($admin->persistFilters());
}

public function testGetRootCode(): void
Expand Down Expand Up @@ -1578,7 +1582,7 @@ public function testGetFormWithCollectionParentValue(): void

$tagAdmin->getForm();

$this->assertInternalType('array', $tag->getPosts());
$this->assertIsArray($tag->getPosts());
$this->assertCount(2, $tag->getPosts());
$this->assertContains($post, $tag->getPosts());
}
Expand Down
2 changes: 0 additions & 2 deletions tests/Controller/CRUDControllerTest.php
Expand Up @@ -439,7 +439,6 @@ public function testConfigure(): void
$this->protectedTestedMethods['configure']->invoke($this->controller);

$this->assertSame(123456, $uniqueId);
$this->assertAttributeSame($this->admin, 'admin', $this->controller);
}

public function testConfigureChild(): void
Expand Down Expand Up @@ -467,7 +466,6 @@ public function testConfigureChild(): void
$this->protectedTestedMethods['configure']->invoke($this->controller);

$this->assertSame(123456, $uniqueId);
$this->assertAttributeInstanceOf(\get_class($adminParent), 'admin', $this->controller);
}

public function testConfigureWithException(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/Datagrid/ListMapperTest.php
Expand Up @@ -168,7 +168,7 @@ public function testAddOptionIdentifierWithWrongValue(bool $expected, $value): v
$this->assertFalse($this->listMapper->has('fooName'));

$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageRegExp('{^Value for "identifier" option must be boolean, [^]+ given.$}');
$this->expectExceptionMessageMatches('{^Value for "identifier" option must be boolean, [^]+ given.$}');

$this->listMapper->add('fooName', null, ['identifier' => $value]);
}
Expand Down
Expand Up @@ -140,7 +140,7 @@ public function testProcessParsingFullValidConfig(): void

$this->assertArrayHasKey('sonata_group_two', $dashboardGroupsSettings);
$this->assertArrayHasKey('provider', $dashboardGroupsSettings['sonata_group_two']);
$this->assertContains('my_menu', $dashboardGroupsSettings['sonata_group_two']['provider']);
$this->assertStringContainsString('my_menu', $dashboardGroupsSettings['sonata_group_two']['provider']);

$this->assertArrayHasKey('sonata_group_five', $dashboardGroupsSettings);
$this->assertTrue($dashboardGroupsSettings['sonata_group_five']['keep_open']);
Expand Down Expand Up @@ -183,15 +183,18 @@ public function testProcessResultingConfig(): void
$this->assertFalse($adminGroups['sonata_group_one']['on_top']);
$this->assertTrue($adminGroups['sonata_group_three']['on_top']);
$this->assertFalse($adminGroups['sonata_group_one']['keep_open']);
$this->assertContains('sonata_post_admin', $adminGroups['sonata_group_one']['items'][0]['admin']);
$this->assertStringContainsString(
'sonata_post_admin',
$adminGroups['sonata_group_one']['items'][0]['admin']
);
$this->assertContains('sonata_news_admin', $adminGroups['sonata_group_one']['items']);
$this->assertContains('sonata_news_admin', $adminGroups['sonata_group_one']['item_adds']);
$this->assertNotContains('sonata_article_admin', $adminGroups['sonata_group_one']['items']);
$this->assertContains('ROLE_ONE', $adminGroups['sonata_group_one']['roles']);

$this->assertArrayHasKey('sonata_group_two', $adminGroups);
$this->assertArrayHasKey('provider', $adminGroups['sonata_group_two']);
$this->assertContains('my_menu', $adminGroups['sonata_group_two']['provider']);
$this->assertStringContainsString('my_menu', $adminGroups['sonata_group_two']['provider']);

$this->assertArrayHasKey('sonata_group_five', $adminGroups);
$this->assertTrue($adminGroups['sonata_group_five']['keep_open']);
Expand Down
10 changes: 8 additions & 2 deletions tests/Filter/FilterTest.php
Expand Up @@ -152,7 +152,10 @@ public function testGetFieldMappingException(): void
try {
$filter->getFieldMapping();
} catch (\RuntimeException $e) {
$this->assertContains('The option `field_mapping` must be set for field: `foo`', $e->getMessage());
$this->assertStringContainsString(
'The option `field_mapping` must be set for field: `foo`',
$e->getMessage()
);

return;
}
Expand Down Expand Up @@ -207,7 +210,10 @@ public function testGetAssociationMappingException(): void
try {
$filter->getAssociationMapping();
} catch (\RuntimeException $e) {
$this->assertContains('The option `association_mapping` must be set for field: `foo`', $e->getMessage());
$this->assertStringContainsString(
'The option `association_mapping` must be set for field: `foo`',
$e->getMessage()
);

return;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Form/Type/ChoiceFieldMaskTypeTest.php
Expand Up @@ -59,7 +59,7 @@ public function setAllowedTypesProvider(): array
public function testSetAllowedTypes($map): void
{
$this->expectException(InvalidOptionsException::class);
$this->expectExceptionMessageRegExp('/The option "map" with value .* is expected to be of type "array", but is of type ".*"/');
$this->expectExceptionMessageMatches('/The option "map" with value .* is expected to be of type "array", but is of type ".*"/');

$this->resolveOptions(['map' => $map]);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Form/Widget/FilterChoiceWidgetTest.php
Expand Up @@ -34,7 +34,7 @@ public function testDefaultValueRendering(): void

$html = $this->renderWidget($choice->createView());

$this->assertContains(
$this->assertStringContainsString(
'<option value="" selected="selected">[trans]Choose an option[/trans]</option>',
$this->cleanHtmlWhitespace($html)
);
Expand All @@ -50,7 +50,7 @@ public function testRequiredIsDisabledForEmptyPlaceholder(): void

$html = $this->renderWidget($choice->createView());

$this->assertNotContains(
$this->assertStringNotContainsString(
'required="required"',
$this->cleanHtmlWhitespace($html)
);
Expand All @@ -66,7 +66,7 @@ public function testRequiredIsEnabledIfPlaceholderIsSet(): void

$html = $this->renderWidget($choice->createView());

$this->assertContains(
$this->assertStringContainsString(
'required="required"',
$this->cleanHtmlWhitespace($html)
);
Expand Down
8 changes: 4 additions & 4 deletions tests/Form/Widget/FormChoiceWidgetTest.php
Expand Up @@ -43,7 +43,7 @@ public function testLabelRendering(): void

$html = $this->renderWidget($choice->createView());

$this->assertContains(
$this->assertStringContainsString(
'<li><div class="checkbox"><label><input type="checkbox" id="choice_0" name="choice[]" value="0" /><span class="control-label__text">[trans]some[/trans]</span></label></div></li>',
$this->cleanHtmlWhitespace($html)
);
Expand All @@ -59,7 +59,7 @@ public function testDefaultValueRendering(): void

$html = $this->renderWidget($choice->createView());

$this->assertContains(
$this->assertStringContainsString(
'<option value="" selected="selected">[trans]Choose an option[/trans]</option>',
$this->cleanHtmlWhitespace($html)
);
Expand All @@ -75,7 +75,7 @@ public function testRequiredIsDisabledForEmptyPlaceholder(): void

$html = $this->renderWidget($choice->createView());

$this->assertNotContains(
$this->assertStringNotContainsString(
'required="required"',
$this->cleanHtmlWhitespace($html)
);
Expand All @@ -91,7 +91,7 @@ public function testRequiredIsEnabledIfPlaceholderIsSet(): void

$html = $this->renderWidget($choice->createView());

$this->assertContains(
$this->assertStringContainsString(
'required="required"',
$this->cleanHtmlWhitespace($html)
);
Expand Down
6 changes: 3 additions & 3 deletions tests/Form/Widget/FormSonataFilterChoiceWidgetTest.php
Expand Up @@ -40,17 +40,17 @@ public function testDefaultValueRendering(): void
$html = $this->cleanHtmlWhitespace($this->renderWidget($choice->createView()));
$html = $this->cleanHtmlAttributeWhitespace($html);

$this->assertContains(
$this->assertStringContainsString(
'<option value="1">[trans]label_type_contains[/trans]</option>',
$html
);

$this->assertContains(
$this->assertStringContainsString(
'<option value="2">[trans]label_type_not_contains[/trans]</option>',
$html
);

$this->assertContains(
$this->assertStringContainsString(
'<option value="3">[trans]label_type_equals[/trans]</option></select>',
$html
);
Expand Down
2 changes: 1 addition & 1 deletion tests/Form/Widget/FormSonataNativeCollectionWidgetTest.php
Expand Up @@ -48,7 +48,7 @@ public function testPrototypeIsDeletableNoMatterTheShrinkability(array $options)

$html = $this->renderWidget($choice->createView());

$this->assertContains(
$this->assertStringContainsString(
'sonata-collection-delete',
$this->cleanHtmlWhitespace($html)
);
Expand Down
8 changes: 4 additions & 4 deletions tests/Menu/Integration/TabMenuTest.php
Expand Up @@ -47,7 +47,7 @@ public function testLabelTranslationNominalCase(): void
$factory = new MenuFactory();
$menu = new MenuItem('test-menu', $factory);
$menu->addChild('some-label', ['uri' => '/whatever']);
$this->assertContains('my-translation', $this->renderMenu($menu));
$this->assertStringContainsString('my-translation', $this->renderMenu($menu));
}

public function testLabelTranslationWithParameters(): void
Expand All @@ -69,7 +69,7 @@ public function testLabelTranslationWithParameters(): void
$menu->addChild('some-label', ['uri' => '/whatever'])
->setExtra('translation_params', $params);

$this->assertContains('my-translation', $this->renderMenu($menu));
$this->assertStringContainsString('my-translation', $this->renderMenu($menu));
}

public function testLabelTranslationDomainOverride(): void
Expand All @@ -91,8 +91,8 @@ public function testLabelTranslationDomainOverride(): void
$menu->addChild('some-other-label', ['uri' => '/whatever']);

$html = $this->renderMenu($menu);
$this->assertContains('my-translation', $html);
$this->assertContains('my-other-translation', $html);
$this->assertStringContainsString('my-translation', $html);
$this->assertStringContainsString('my-other-translation', $html);
}

protected function getTemplate()
Expand Down

0 comments on commit d516656

Please sign in to comment.