Completed
Push — master ( 7eed6f...d1d910 )
by amaury
03:03
created

Mapping/Reader/SearchMappingReaderTest.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace OpenOrchestra\FunctionalTests\Mapping\Reader;
4
5
use OpenOrchestra\Mapping\Annotations as ORCHESTRA;
6
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
7
use ReflectionObject;
8
9
/**
10
 * Class SearchMappingReaderTest
11
 */
12
class SearchMappingReaderTest extends KernelTestCase
13
{
14
    protected $readerSearch;
15
    protected $fakeClass;
16
17
    /**
18
     * setUp
19
     */
20
    public function setUp()
21
    {
22
        $this->fakeClass = new FakeClassAnnotation();
23
24
        static::bootKernel();
25
        $this->readerSearch = static::$kernel->getContainer()->get('open_orchestra.annotation_search_reader');
26
    }
27
28
    /**
29
     * Test ExtractMapping
30
     */
31
    public function testExtractMapping()
32
    {
33
        $mappingProperties = array(
34
            "fake_property1" =>array(
35
                "key" => "fake_property1",
36
                "field" => "fakeProperty1",
37
                "type" => "fakeType",
38
            ),
39
            "fake_property2" =>array(
40
                "key" => "fake_property2",
41
                "field" => "fakeProperty2",
42
                "type" => "string",
43
            ),
44
            "fake_property_multi" =>array(
45
                "key" => "fake_property_multi",
46
                "field" => "fakeProperty2",
47
                "type" => "string",
48
            )
49
        );
50
51
        $mapping = $this->readerSearch->extractMapping(get_class($this->fakeClass));
52
        $this->assertCount(3, $mapping);
53
        $this->assertSame($mapping, $mappingProperties);
54
    }
55
56
    /**
57
     * Clean up
58
     */
59 View Code Duplication
    protected function tearDown()
60
    {
61
        $refl = new ReflectionObject($this);
62
        foreach ($refl->getProperties() as $prop) {
63
            if (!$prop->isStatic() && 0 !== strpos($prop->getDeclaringClass()->getName(), 'PHPUnit_')) {
64
                $prop->setAccessible(true);
65
                $prop->setValue($this, null);
66
            }
67
        }
68
    }
69
}
70
71
/**
72
 * Class FakeClassAnnotation
73
 */
74
class FakeClassAnnotation
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...
75
{
76
    /**
77
     * @ORCHESTRA\Search(
78
     *      type="fakeType",
79
     *      key="fake_property1",
80
     *      field="fakeProperty1"
81
     * )
82
     */
83
    protected $fakeProperty1;
84
85
    /**
86
     * @ORCHESTRA\Search(key={"fake_property2", "fake_property_multi"})
87
     */
88
    protected $fakeProperty2;
89
}
90