1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ScayTrase\Api\Cruds\Tests\Unit\Processor; |
4
|
|
|
|
5
|
|
|
use ScayTrase\Api\Cruds\Adaptors\Symfony\FormProcessor; |
6
|
|
|
use ScayTrase\Api\Cruds\Exception\EntityProcessingException; |
7
|
|
|
use ScayTrase\Api\Cruds\Tests\AbstractCrudsWebTest; |
8
|
|
|
use ScayTrase\Api\Cruds\Tests\Fixtures\SymfonySerializer\SymfonyTestKernel; |
9
|
|
|
use Symfony\Component\Form\AbstractType; |
10
|
|
|
use Symfony\Component\Form\Extension\Core\Type\IntegerType; |
11
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
12
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
13
|
|
|
|
14
|
|
|
class FormProcessorTest extends AbstractCrudsWebTest |
15
|
|
|
{ |
16
|
|
|
public function testProcessor() |
17
|
|
|
{ |
18
|
|
|
self::createAndBootKernel(SymfonyTestKernel::class); |
19
|
|
|
$factory = static::$kernel->getContainer()->get('form.factory'); |
20
|
|
|
|
21
|
|
|
$entity = new \stdClass(); |
22
|
|
|
$entity->b = null; |
23
|
|
|
$entity->a = null; |
24
|
|
|
|
25
|
|
|
$processor = new FormProcessor($factory, TestForm::class); |
26
|
|
|
$processor->updateEntity($entity, ['a' => 'a', 'b' => 3]); |
27
|
|
|
|
28
|
|
|
self::assertSame('a', $entity->a); |
29
|
|
|
self::assertSame(3, $entity->b); |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
$processor->updateEntity($entity, ['a' => 3, 'b' => '5']); |
33
|
|
|
|
34
|
|
|
self::assertSame('3', $entity->a); |
35
|
|
|
self::assertSame(5, $entity->b); |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
try { |
39
|
|
|
$processor->updateEntity($entity, ['b' => ['a' => [5, 42], 7], 'a' => '5']); |
40
|
|
|
|
41
|
|
|
self::fail('Should be invalid'); |
42
|
|
|
} catch (EntityProcessingException $exception) { |
|
|
|
|
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
class TestForm extends AbstractType |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options) |
50
|
|
|
{ |
51
|
|
|
$builder->add('a', TextType::class); |
52
|
|
|
$builder->add('b', IntegerType::class); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|