@@ -23,7 +24,10 @@ class FormChoiceWidgetTest extends AbstractWidgetTestCase
{
public function testLabelRendering()
{
- $choices = ['some' => 0, 'choices' => 1];
+ $choices = ['some', 'choices'];
+ if (!method_exists(FormTypeInterface::class, 'setDefaultOptions')) {
+ $choices = array_flip($choices);
+ }
$choice = $this->factory->create(
$this->getChoiceClass(),
@@ -37,21 +41,12 @@ public function testLabelRendering()
$html = $this->renderWidget($choice->createView());
$this->assertStringContainsString(
- $this->cleanHtmlWhitespace(
- <<<'HTML'
-
-
-
-
-
-
-HTML
- ),
+ '',
$this->cleanHtmlWhitespace($html)
);
}
- public function testDefaultValueRendering(): void
+ public function testDefaultValueRendering()
{
$choice = $this->factory->create(
$this->getChoiceClass(),
@@ -67,7 +62,7 @@ public function testDefaultValueRendering(): void
);
}
- public function testRequiredIsDisabledForEmptyPlaceholder(): void
+ public function testRequiredIsDisabledForEmptyPlaceholder()
{
$choice = $this->factory->create(
$this->getChoiceClass(),
@@ -83,7 +78,7 @@ public function testRequiredIsDisabledForEmptyPlaceholder(): void
);
}
- public function testRequiredIsEnabledIfPlaceholderIsSet(): void
+ public function testRequiredIsEnabledIfPlaceholderIsSet()
{
$choice = $this->factory->create(
$this->getChoiceClass(),
diff --git a/tests/Type/ImmutableArrayTypeTest.php b/tests/Type/ImmutableArrayTypeTest.php
index f572eb4a..c0b082dd 100644
--- a/tests/Type/ImmutableArrayTypeTest.php
+++ b/tests/Type/ImmutableArrayTypeTest.php
@@ -16,21 +16,53 @@
use Sonata\Form\Type\ImmutableArrayType;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
+use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Test\FormBuilderInterface as TestFormBuilderInterface;
use Symfony\Component\Form\Test\TypeTestCase;
+use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
use Symfony\Component\OptionsResolver\OptionsResolver;
class ImmutableArrayTypeTest extends TypeTestCase
{
- public function testGetDefaultOptions(): void
+ /**
+ * @doesNotPerformAssertions
+ */
+ public function testBuildForm()
+ {
+ $formBuilder = $this->createMock(FormBuilder::class);
+ $formBuilder
+ ->expects($this->any())
+ ->method('add')
+ ->willReturnCallback(function ($name, $type = null) {
+ if (null !== $type) {
+ $this->assertTrue(class_exists($type), sprintf('Unable to ensure %s is a FQCN', $type));
+ }
+ });
+
+ $type = new ImmutableArrayType();
+ $type->buildForm($formBuilder, [
+ 'keys' => [],
+ ]);
+ }
+
+ public function testGetParent()
+ {
+ $form = new ImmutableArrayType();
+
+ $parentRef = $form->getParent();
+
+ $this->assertTrue(class_exists($parentRef), sprintf('Unable to ensure %s is a FQCN', $parentRef));
+ }
+
+ public function testGetDefaultOptions()
{
$type = new ImmutableArrayType();
- $this->assertSame('sonata_type_immutable_array', $type->getBlockPrefix());
+ $this->assertSame('sonata_type_immutable_array', $type->getName());
- $this->assertSame(FormType::class, $type->getParent());
+ $this->assertSame(version_compare(Kernel::VERSION, '2.8', '<') ? 'form' : FormType::class, $type->getParent());
$type->configureOptions($resolver = new OptionsResolver());
@@ -43,7 +75,7 @@ public function testGetDefaultOptions(): void
$this->assertSame($expected, $options);
}
- public function testCallback(): void
+ public function testCallback()
{
$type = new ImmutableArrayType();
@@ -79,7 +111,7 @@ public function testCallback(): void
$type->buildForm($builder, $options);
}
- public function testWithIncompleteOptions(): void
+ public function testWithIncompleteOptions()
{
$optionsResolver = new OptionsResolver();
@@ -94,7 +126,7 @@ public function testWithIncompleteOptions(): void
$optionsResolver->resolve(['keys' => [['test']]]);
}
- public function testFormBuilderIsAValidElement(): void
+ public function testFormBuilderIsAValidElement()
{
$optionsResolver = new OptionsResolver();
@@ -103,9 +135,9 @@ public function testFormBuilderIsAValidElement(): void
$this->assertArrayHasKey(
'keys',
- $optionsResolver->resolve(['keys' => [$this->createMock(
+ $optionsResolver->resolve(['keys' => [$this->getMockBuilder(
FormBuilderInterface::class
- )]])
+ )->getMock()]])
);
}
}
diff --git a/tests/Validator/Constraints/InlineConstraintTest.php b/tests/Validator/Constraints/InlineConstraintTest.php
index cf0ca8e5..313abad7 100755
--- a/tests/Validator/Constraints/InlineConstraintTest.php
+++ b/tests/Validator/Constraints/InlineConstraintTest.php
@@ -21,13 +21,13 @@
*/
class InlineConstraintTest extends TestCase
{
- public function testValidatedBy(): void
+ public function testValidatedBy()
{
$constraint = new InlineConstraint(['service' => 'foo', 'method' => 'bar']);
$this->assertSame('sonata.form.validator.inline', $constraint->validatedBy());
}
- public function testIsClosure(): void
+ public function testIsClosure()
{
$constraint = new InlineConstraint(['service' => 'foo', 'method' => 'bar']);
$this->assertFalse($constraint->isClosure());
@@ -37,7 +37,7 @@ public function testIsClosure(): void
$this->assertTrue($constraint->isClosure());
}
- public function testGetClosure(): void
+ public function testGetClosure()
{
$closure = static function () {
return 'FOO';
@@ -47,31 +47,31 @@ public function testGetClosure(): void
$this->assertSame($closure, $constraint->getClosure());
}
- public function testGetTargets(): void
+ public function testGetTargets()
{
$constraint = new InlineConstraint(['service' => 'foo', 'method' => 'bar']);
$this->assertSame(InlineConstraint::CLASS_CONSTRAINT, $constraint->getTargets());
}
- public function testGetRequiredOptions(): void
+ public function testGetRequiredOptions()
{
$constraint = new InlineConstraint(['service' => 'foo', 'method' => 'bar']);
$this->assertSame(['service', 'method'], $constraint->getRequiredOptions());
}
- public function testGetMethod(): void
+ public function testGetMethod()
{
$constraint = new InlineConstraint(['service' => 'foo', 'method' => 'bar']);
$this->assertSame('bar', $constraint->getMethod());
}
- public function testGetService(): void
+ public function testGetService()
{
$constraint = new InlineConstraint(['service' => 'foo', 'method' => 'bar']);
$this->assertSame('foo', $constraint->getService());
}
- public function testClosureSerialization(): void
+ public function testClosureSerialization()
{
$constraint = new InlineConstraint(['service' => 'foo', 'method' => static function (): void {
}, 'serializingWarning' => true]);
@@ -87,7 +87,7 @@ public function testClosureSerialization(): void
$this->assertTrue($constraint->getSerializingWarning());
}
- public function testStandardSerialization(): void
+ public function testStandardSerialization()
{
$constraint = new InlineConstraint(['service' => 'foo', 'method' => 'bar']);
@@ -100,7 +100,7 @@ public function testStandardSerialization(): void
$this->assertNull($constraint->getSerializingWarning());
}
- public function testSerializingWarningIsFalseWithServiceIsNotString(): void
+ public function testSerializingWarningIsFalseWithServiceIsNotString()
{
$this->expectException(
'RuntimeException'
@@ -114,7 +114,7 @@ public function testSerializingWarningIsFalseWithServiceIsNotString(): void
new InlineConstraint(['service' => 1, 'method' => 'foo', 'serializingWarning' => false]);
}
- public function testSerializingWarningIsFalseWithMethodIsNotString(): void
+ public function testSerializingWarningIsFalseWithMethodIsNotString()
{
$this->expectException(
'RuntimeException'
diff --git a/tests/Validator/ErrorElementTest.php b/tests/Validator/ErrorElementTest.php
index b94484ee..1c849278 100755
--- a/tests/Validator/ErrorElementTest.php
+++ b/tests/Validator/ErrorElementTest.php
@@ -45,25 +45,25 @@ protected function setUp(): void
if ($this->context instanceof ExecutionContextInterface) {
$builder = $this->createMock(ConstraintViolationBuilderInterface::class);
- $builder
+ $builder->expects($this->any())
->method($this->anything())
->willReturnSelf();
- $this->context
+ $this->context->expects($this->any())
->method('buildViolation')
->willReturn($builder);
$validator = $this->createMock(ValidatorInterface::class);
$this->contextualValidator = $this->createMock(ContextualValidatorInterface::class);
- $this->contextualValidator
+ $this->contextualValidator->expects($this->any())
->method($this->anything())
->willReturnSelf();
- $validator
+ $validator->expects($this->any())
->method('inContext')
->willReturn($this->contextualValidator);
- $this->context
+ $this->context->expects($this->any())
->method('getValidator')
->willReturn($validator);
}
@@ -73,12 +73,12 @@ protected function setUp(): void
$this->errorElement = new ErrorElement($this->subject, $constraintValidatorFactory, $this->context, 'foo_core');
}
- public function testGetSubject(): void
+ public function testGetSubject()
{
$this->assertSame($this->subject, $this->errorElement->getSubject());
}
- public function testGetErrorsEmpty(): void
+ public function testGetErrorsEmpty()
{
$this->assertSame([], $this->errorElement->getErrors());
}
@@ -86,7 +86,7 @@ public function testGetErrorsEmpty(): void
/**
* @group legacy
*/
- public function testGetErrors(): void
+ public function testGetErrors()
{
$this->errorElement->addViolation('Foo error message', ['bar_param' => 'bar_param_lvalue'], 'BAR');
$this->assertSame([['Foo error message', ['bar_param' => 'bar_param_lvalue'], 'BAR']], $this->errorElement->getErrors());
@@ -95,7 +95,7 @@ public function testGetErrors(): void
/**
* @group legacy
*/
- public function testAddViolation(): void
+ public function testAddViolation()
{
$this->errorElement->addViolation(['Foo error message', ['bar_param' => 'bar_param_lvalue'], 'BAR']);
$this->assertSame([['Foo error message', ['bar_param' => 'bar_param_lvalue'], 'BAR']], $this->errorElement->getErrors());
@@ -104,7 +104,7 @@ public function testAddViolation(): void
/**
* @group legacy
*/
- public function testAddViolationWithTranslationDomain(): void
+ public function testAddViolationWithTranslationDomain()
{
$this->errorElement->addViolation(['Foo error message', ['bar_param' => 'bar_param_lvalue'], 'BAR'], [], null, 'translation_domain');
$this->assertSame([['Foo error message', ['bar_param' => 'bar_param_lvalue'], 'BAR']], $this->errorElement->getErrors());
@@ -113,7 +113,7 @@ public function testAddViolationWithTranslationDomain(): void
/**
* @group legacy
*/
- public function testAddConstraint(): void
+ public function testAddConstraint()
{
$constraint = new NotNull();
if ($this->context instanceof LegacyExecutionContextInterface) {
@@ -136,7 +136,7 @@ public function testAddConstraint(): void
/**
* @group legacy
*/
- public function testWith(): void
+ public function testWith()
{
$constraint = new NotNull();
@@ -162,7 +162,7 @@ public function testWith(): void
/**
* @group legacy
*/
- public function testCall(): void
+ public function testCall()
{
$constraint = new NotNull();
@@ -185,7 +185,7 @@ public function testCall(): void
$this->errorElement->end();
}
- public function testCallException(): void
+ public function testCallException()
{
$this->expectException('RuntimeException');
$this->expectExceptionMessage('Unable to recognize the command');
@@ -194,7 +194,7 @@ public function testCallException(): void
$this->errorElement->baz();
}
- public function testGetFullPropertyPath(): void
+ public function testGetFullPropertyPath()
{
$this->errorElement->with('baz');
$this->assertSame('bar.baz', $this->errorElement->getFullPropertyPath());
@@ -206,20 +206,20 @@ public function testGetFullPropertyPath(): void
/**
* @group legacy
*/
- public function testFluidInterface(): void
+ public function testFluidInterface()
{
$constraint = new NotNull();
if ($this->context instanceof LegacyExecutionContextInterface) {
- $this->context
+ $this->context->expects($this->any())
->method('validateValue')
->with($this->equalTo($this->subject), $this->equalTo($constraint), $this->equalTo(''), $this->equalTo('foo_core'))
->willReturn(null);
} else {
- $this->contextualValidator
+ $this->contextualValidator->expects($this->any())
->method('atPath')
->with('');
- $this->contextualValidator
+ $this->contextualValidator->expects($this->any())
->method('validate')
->with($this->subject, $constraint, ['foo_core']);
}
@@ -230,4 +230,15 @@ public function testFluidInterface(): void
$this->assertSame($this->errorElement, $this->errorElement->addConstraint($constraint));
$this->assertSame($this->errorElement, $this->errorElement->assertNotNull());
}
+
+ public function testExceptionIsThrownWhenContextIsString()
+ {
+ $constraintValidatorFactory = $this->createMock(ConstraintValidatorFactoryInterface::class);
+
+ $this->expectException(
+ \TypeError::class
+ );
+
+ $this->errorElement = new ErrorElement($this->subject, $constraintValidatorFactory, 'foo', 'foo_core');
+ }
}