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

register SonataFormBundle and SonataTwigBundle in AppKernel
  • Loading branch information
peter-gribanov committed Jun 25, 2020
1 parent 86905e6 commit 6f1e419
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
13 changes: 11 additions & 2 deletions tests/App/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use Sonata\BlockBundle\SonataBlockBundle;
use Sonata\CoreBundle\SonataCoreBundle;
use Sonata\Doctrine\Bridge\Symfony\Bundle\SonataDoctrineBundle;
use Sonata\Form\Bridge\Symfony\SonataFormBundle;
use Sonata\Twig\Bridge\Symfony\SonataTwigBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Bundle\SecurityBundle\SecurityBundle;
Expand All @@ -39,17 +41,24 @@ 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(),
new SonataTwigBundle(),
new SonataFormBundle(),
];

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 @@ -15,6 +15,7 @@

use PHPUnit\Framework\TestCase;
use Sonata\AdminBundle\Export\Exporter;
use Sonata\CoreBundle\Exporter\Exporter as CoreExporter;
use Sonata\Exporter\Source\ArraySourceIterator;
use Sonata\Exporter\Source\SourceIteratorInterface;
use Symfony\Component\HttpFoundation\Response;
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 6f1e419

Please sign in to comment.