Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
not test Exporter if not Sonata\CoreBundle\Exporter\Exporter

not test ChoiceTypeExtension if no SonataCoreBundle

remove SonataCoreBundle from AppKernel if it is not exists
  • Loading branch information
peter-gribanov committed Jun 25, 2020
1 parent 86905e6 commit de19b5a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
9 changes: 7 additions & 2 deletions tests/App/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,22 @@ public function __construct()

public function registerBundles()
{
return [
$bundles = [
new FrameworkBundle(),
new TwigBundle(),
new TwigExtraBundle(),
new SecurityBundle(),
new KnpMenuBundle(),
new SonataBlockBundle(),
new SonataCoreBundle(),
new SonataDoctrineBundle(),
new SonataAdminBundle(),
];

if (class_exists(SonataCoreBundle::class)) {
$bundles[] = new SonataCoreBundle();
}

return $bundles;
}

public function getCacheDir(): string
Expand Down
6 changes: 6 additions & 0 deletions tests/Export/ExporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Sonata\Exporter\Source\ArraySourceIterator;
use Sonata\Exporter\Source\SourceIteratorInterface;
use Symfony\Component\HttpFoundation\Response;
use Sonata\CoreBundle\Exporter\Exporter as CoreExporter;

/**
* NEXT_MAJOR: remove this class.
Expand All @@ -41,6 +42,11 @@ public function testFilter(): void
*/
public function testGetResponse(string $format, string $filename, string $contentType): void
{
if (!class_exists(CoreExporter::class)) {
$this->markTestSkipped('Not test Exporter from removed SonataCoreBundle.');
}

$this->markTestSkipped();
$source = new ArraySourceIterator([
['foo' => 'bar'],
]);
Expand Down
4 changes: 4 additions & 0 deletions tests/Form/Extension/ChoiceTypeExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class ChoiceTypeExtensionTest extends TestCase
{
protected function setup(): void
{
if (!class_exists(DependencyInjectionExtension::class)) {
$this->markTestIncomplete(sprintf('%s class was removed.', DependencyInjectionExtension::class));
}

$container = $this->getMockForAbstractClass(ContainerInterface::class);
$container->method('has')->willReturn(true);
$container->method('get')
Expand Down
6 changes: 3 additions & 3 deletions tests/Form/Widget/BaseWidgetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ abstract class BaseWidgetTest extends AbstractWidgetTestCase
/**
* {@inheritdoc}
*/
protected function getEnvironment()
protected function getEnvironment(): Environment
{
$environment = parent::getEnvironment();
$environment->addGlobal('sonata_admin', $this->getSonataAdmin());
Expand All @@ -67,7 +67,7 @@ protected function getEnvironment()
/**
* {@inheritdoc}
*/
protected function getRenderingEngine(?Environment $environment = null)
protected function getRenderingEngine(?Environment $environment = null): TwigRendererEngine
{
if (!\in_array($this->type, ['form', 'filter'], true)) {
throw new \Exception('Please override $this->type in your test class specifying template to use (either form or filter)');
Expand All @@ -90,7 +90,7 @@ protected function getSonataAdmin()
/**
* {@inheritdoc}
*/
protected function getTemplatePaths()
protected function getTemplatePaths(): array
{
return array_merge(parent::getTemplatePaths(), [
__DIR__.'/../../../src/Resources/views/Form',
Expand Down
2 changes: 0 additions & 2 deletions tests/Resources/XliffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

namespace Sonata\AdminBundle\Tests\Resources;

use Sonata\CoreBundle\Test\XliffValidatorTestCase;

class XliffTest extends XliffValidatorTestCase
{
/**
Expand Down

0 comments on commit de19b5a

Please sign in to comment.