Completed
Pull Request — master (#1146)
by Giovanni
06:29
created

testIfEventOnPostTransformEventIsCalled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 12
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of the FOSElasticaBundle project.
5
 *
6
 * (c) Tim Nagel <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace FOS\ElasticaBundle\Tests\Functional;
13
14
/**
15
 * @group functional
16
 */
17
class SerializerTest extends WebTestCase
18
{
19 View Code Duplication
    public function testMappingIteratorToArrayField()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
    {
21
        $client = $this->createClient(array('test_case' => 'Serializer'));
22
        $persister = $client->getContainer()->get('fos_elastica.object_persister.index.type');
23
24
        $object = new TypeObj();
25
        $object->id = 1;
26
        $object->coll = new \ArrayIterator(array('foo', 'bar'));
27
        $persister->insertOne($object);
28
29
        $object->coll = new \ArrayIterator(array('foo', 'bar', 'bazz'));
30
        $object->coll->offsetUnset(1);
31
32
        $persister->replaceOne($object);
33
    }
34
35
    /**
36
     * Tests that the serialize_null configuration attribute works
37
     */
38
    public function testWithNullValues()
39
    {
40
        $client = $this->createClient(array('test_case' => 'Serializer'));
41
        $container = $client->getContainer();
42
43
        $disabledNullPersister = $container->get('fos_elastica.object_persister.index.type_serialize_null_disabled');
44
        $enabledNullPersister = $container->get('fos_elastica.object_persister.index.type_serialize_null_enabled');
45
46
        $object = new TypeObj();
47
        $object->id = 1;
48
        $object->field1 = null;
49
        $disabledNullPersister->insertOne($object);
50
        $enabledNullPersister->insertOne($object);
51
52
        // Tests that attributes with null values are not persisted into an Elasticsearch type without the serialize_null option
53
        $disabledNullType = $container->get('fos_elastica.index.index.type_serialize_null_disabled');
54
        $documentData = $disabledNullType->getDocument(1)->getData();
55
        $this->assertArrayNotHasKey('field1', $documentData);
56
57
        // Tests that attributes with null values are persisted into an Elasticsearch type with the serialize_null option
58
        $enabledNullType = $container->get('fos_elastica.index.index.type_serialize_null_enabled');
59
        $documentData = $enabledNullType->getDocument(1)->getData();
60
        $this->assertArrayHasKey('field1', $documentData);
61
        $this->assertEquals($documentData['field1'], null);
62
    }
63
64
    public function testUnmappedType()
65
    {
66
        $client = $this->createClient(array('test_case' => 'Serializer'));
67
        $resetter = $client->getContainer()->get('fos_elastica.resetter');
68
        $resetter->resetIndex('index');
69
    }
70
71
    public function testIfEventOnPostTransformEventIsCalled()
72
    {
73
        $client = $this->createClient(array('test_case' => 'SerializerWithListener'));
74
        $container = $client->getContainer();
75
        $object = new TypeObj();
76
        $object->id = 2;
77
        $object->field1 = 'a listener will change me';
78
79
        $elasticaPersister = $container->get('fos_elastica.object_persister.index.type');
80
        $elasticaPersister->insertOne($object);
81
82
        $elasticaType = $container->get('fos_elastica.index.index.type');
83
84
        $documentData = $elasticaType->getDocument(2)->getData();
85
86
        $this->assertArrayHasKey('field1', $documentData);
87
        $this->assertEquals($documentData['field1'], 'post_persister');
88
    }
89
90
    protected function setUp()
91
    {
92
        parent::setUp();
93
94
        $this->deleteTmpDir('Serializer');
95
    }
96
97
    protected function tearDown()
98
    {
99
        parent::tearDown();
100
101
        $this->deleteTmpDir('Serializer');
102
    }
103
}
104