Completed
Push — master ( 07e238...0f15f1 )
by Pavel
09:14
created

TestForm::buildForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
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) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
43
        }
44
    }
45
}
46
47
class TestForm extends AbstractType
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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