Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jordisala1991 committed Jul 1, 2022
1 parent 4c500c9 commit 9cad8ab
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 89 deletions.
29 changes: 2 additions & 27 deletions tests/Type/BasePickerTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,20 @@

namespace Sonata\Form\Tests\Type;

use PHPUnit\Framework\MockObject\Stub;
use PHPUnit\Framework\TestCase;
use Sonata\Form\Tests\Fixtures\Type\DummyPickerType;
use Symfony\Component\Form\Form;
use Symfony\Component\Form\FormConfigInterface;
use Symfony\Component\Form\FormView;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* @author Hugo Briand <[email protected]>
*/
final class BasePickerTypeTest extends TestCase
{
/**
* @var Stub&TranslatorInterface
*/
private TranslatorInterface $translator;

protected function setUp(): void
{
parent::setUp();

$this->translator = $this->createStub(TranslatorInterface::class);
}

/**
Expand All @@ -46,10 +37,7 @@ protected function setUp(): void
*/
public function testFinishView(array $expectedOptions, array $options): void
{
$type = new DummyPickerType(
$this->translator,
'en'
);
$type = new DummyPickerType();

$view = new FormView();
$form = new Form($this->createStub(FormConfigInterface::class));
Expand Down Expand Up @@ -83,10 +71,7 @@ public function testFinishView(array $expectedOptions, array $options): void
*/
public function testTimePickerIntlFormater(array $expectedOptions, array $options): void
{
$type = new DummyPickerType(
$this->translator,
'en'
);
$type = new DummyPickerType();

$view = new FormView();
$form = new Form($this->createStub(FormConfigInterface::class));
Expand Down Expand Up @@ -152,14 +137,4 @@ public function provideTypeOptions(): iterable
],
];
}

public function testTimePickerUsesDefaultLocaleWithoutRequest(): void
{
$type = new DummyPickerType(
$this->translator,
'en'
);

static::assertSame('en', $type->getLocale());
}
}
30 changes: 2 additions & 28 deletions tests/Type/DatePickerTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,30 @@

namespace Sonata\Form\Tests\Type;

use PHPUnit\Framework\MockObject\Stub;
use Sonata\Form\Type\DatePickerType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\FormExtensionInterface;
use Symfony\Component\Form\PreloadedExtension;
use Symfony\Component\Form\Test\TypeTestCase;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* @author Hugo Briand <[email protected]>
*/
final class DatePickerTypeTest extends TypeTestCase
{
/**
* @var Stub&TranslatorInterface
*/
private TranslatorInterface $translator;

protected function setUp(): void
{
$this->translator = $this->createStub(TranslatorInterface::class);

parent::setUp();
}

public function testParentIsDateType(): void
{
$form = new DatePickerType(
$this->translator,
'en'
);
$form = new DatePickerType();

static::assertSame(DateType::class, $form->getParent());
}

public function testGetName(): void
{
$type = new DatePickerType($this->translator, 'en');
$type = new DatePickerType();

static::assertSame('sonata_type_date_picker', $type->getBlockPrefix());
}
Expand All @@ -68,16 +54,4 @@ public function testSubmitValidData(): void
static::assertSame('2018-06-05', $form->getData()->format('Y-m-d'));
static::assertTrue($form->isSynchronized());
}

/**
* @return FormExtensionInterface[]
*/
protected function getExtensions(): array
{
$type = new DatePickerType($this->translator, 'en');

return [
new PreloadedExtension([$type], []),
];
}
}
36 changes: 2 additions & 34 deletions tests/Type/DateTimePickerTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,30 @@

namespace Sonata\Form\Tests\Type;

use PHPUnit\Framework\MockObject\Stub;
use Sonata\Form\Type\DateTimePickerType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\FormExtensionInterface;
use Symfony\Component\Form\PreloadedExtension;
use Symfony\Component\Form\Test\TypeTestCase;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* @author Hugo Briand <[email protected]>
*/
final class DateTimePickerTypeTest extends TypeTestCase
{
/**
* @var Stub&TranslatorInterface
*/
private TranslatorInterface $translator;

protected function setUp(): void
{
$this->translator = $this->createStub(TranslatorInterface::class);

parent::setUp();
}

public function testParentIsDateTimeType(): void
{
$form = new DateTimePickerType(
$this->translator,
'en'
);
$form = new DateTimePickerType();

static::assertSame(DateTimeType::class, $form->getParent());
}

public function testGetName(): void
{
$type = new DateTimePickerType(
$this->translator,
'en'
);
$type = new DateTimePickerType();

static::assertSame('sonata_type_datetime_picker', $type->getBlockPrefix());
}
Expand Down Expand Up @@ -88,19 +71,4 @@ public function testSubmitMatchingDateFormat(): void
static::assertSame('1970-01-01 05:23:00', $form->getData()->format('Y-m-d H:i:s'));
static::assertTrue($form->isSynchronized());
}

/**
* @return FormExtensionInterface[]
*/
protected function getExtensions(): array
{
$type = new DateTimePickerType(
$this->translator,
'en'
);

return [
new PreloadedExtension([$type], []),
];
}
}

0 comments on commit 9cad8ab

Please sign in to comment.