Completed
Pull Request — master (#1339)
by Maksim
14:29
created

SerializerTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the FOSElasticaBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
/**
13
 * This file is part of the FOSElasticaBundle project.
14
 *
15
 * (c) Tim Nagel <[email protected]>
16
 *
17
 * This source file is subject to the MIT license that is bundled
18
 * with this source code in the file LICENSE.
19
 */
20
21
namespace FOS\ElasticaBundle\Tests\Functional;
22
23
/**
24
 * @group functional
25
 */
26
class SerializerTest extends WebTestCase
27
{
28 View Code Duplication
    public function testMappingIteratorToArrayField()
29
    {
30
        static::bootKernel(['test_case' => 'Serializer']);
31
        $persister = static::$kernel->getContainer()->get('fos_elastica.object_persister.index.type');
32
33
        $object = new TypeObj();
34
        $object->id = 1;
35
        $object->coll = new \ArrayIterator(['foo', 'bar']);
36
        $persister->insertOne($object);
37
38
        $object->coll = new \ArrayIterator(['foo', 'bar', 'bazz']);
39
        $object->coll->offsetUnset(1);
40
41
        $persister->replaceOne($object);
42
    }
43
44
    /**
45
     * Tests that the serialize_null configuration attribute works.
46
     */
47
    public function testWithNullValues()
48
    {
49
        static::bootKernel(['test_case' => 'Serializer']);
50
        $container = static::$kernel->getContainer();
51
52
        $disabledNullPersister = $container->get('fos_elastica.object_persister.index.type_serialize_null_disabled');
53
        $enabledNullPersister = $container->get('fos_elastica.object_persister.index.type_serialize_null_enabled');
54
55
        $object = new TypeObj();
56
        $object->id = 1;
57
        $object->field1 = null;
58
        $disabledNullPersister->insertOne($object);
59
        $enabledNullPersister->insertOne($object);
60
61
        // Tests that attributes with null values are not persisted into an Elasticsearch type without the serialize_null option
62
        $disabledNullType = $container->get('fos_elastica.index.index.type_serialize_null_disabled');
63
        $documentData = $disabledNullType->getDocument(1)->getData();
64
        $this->assertArrayNotHasKey('field1', $documentData);
65
66
        // Tests that attributes with null values are persisted into an Elasticsearch type with the serialize_null option
67
        $enabledNullType = $container->get('fos_elastica.index.index.type_serialize_null_enabled');
68
        $documentData = $enabledNullType->getDocument(1)->getData();
69
        $this->assertArrayHasKey('field1', $documentData);
70
        $this->assertNull($documentData['field1']);
71
    }
72
73
    public function testUnmappedType()
74
    {
75
        static::bootKernel(['test_case' => 'Serializer']);
76
        $resetter = static::$kernel->getContainer()->get('fos_elastica.resetter');
77
        $resetter->resetIndex('index');
78
    }
79
}
80