@@ -39,37 +39,24 @@ The simplest ``TypeTestCase`` implementation looks like the following::
39
39
// src/AppBundle/Tests/Form/Type/TestedTypeTest.php
40
40
namespace AppBundle\Tests\Form\Type;
41
41
42
- use AppBundle\Form\Type\TestedType;
43
- use AppBundle\Model\TestObject;
42
+ use Symfony\Component\Form\Extension\Validator\ValidatorExtension;
44
43
use Symfony\Component\Form\Test\TypeTestCase;
44
+ use Symfony\Component\Validator\ConstraintViolationList;
45
+ use Symfony\Component\Validator\Validator\ValidatorInterface;
45
46
46
47
class TestedTypeTest extends TypeTestCase
47
48
{
48
- public function testSubmitValidData ()
49
+ protected function getExtensions ()
49
50
{
50
- $formData = array(
51
- 'test' => 'test',
52
- 'test2' => 'test2',
53
- );
54
-
55
- $type = new TestedType();
56
- $form = $this->factory->create($type);
57
-
58
- $object = TestObject::fromArray($formData);
59
-
60
- // submit the data to the form directly
61
- $form->submit($formData);
62
-
63
- $this->assertTrue($form->isSynchronized());
64
- $this->assertEquals($object, $form->getData());
65
-
66
- $view = $form->createView();
67
- $children = $view->children;
51
+ $validator = $this->getMock('ValidatorInterface::class');
52
+ $validator->method('validate')->will($this->returnValue(new ConstraintViolationList()));
68
53
69
- foreach (array_keys($formData) as $key) {
70
- $this->assertArrayHasKey($key, $children);
71
- }
54
+ return array(
55
+ new ValidatorExtension($validator),
56
+ );
72
57
}
58
+
59
+ // ... your tests
73
60
}
74
61
75
62
So, what does it test? Here comes a detailed explanation.
0 commit comments