GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#246)
by Asmir
04:23
created

XmlSerializerTest::testGh236()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 8

Duplication

Lines 24
Ratio 88.89 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 24
loc 27
rs 8.8571
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace Hateoas\Tests\Serializer;
4
5
use Hateoas\HateoasBuilder;
6
use Hateoas\Model\Embedded;
7
use Hateoas\Model\Link;
8
use Hateoas\Representation\CollectionRepresentation;
9
use Hateoas\Serializer\XmlSerializer;
10
use Hateoas\Tests\Fixtures\AdrienBrault;
11
use Hateoas\Tests\Fixtures\Gh236Foo;
12
use Hateoas\Tests\TestCase;
13
use JMS\Serializer\SerializationContext;
14
use JMS\Serializer\XmlSerializationVisitor;
15
16
class XmlSerializerTest extends TestCase
17
{
18 View Code Duplication
    public function testSerializeLinks()
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...
19
    {
20
        $contextProphecy = $this->prophesize('JMS\Serializer\SerializationContext');
21
22
        $xmlSerializer = new XmlSerializer();
23
        $xmlSerializationVisitor = $this->createXmlSerializationVisitor();
24
25
        $links = array(
26
            new Link('self', '/users/42'),
27
            new Link('foo', '/bar', array('type' => 'magic')),
28
        );
29
30
        $xmlSerializer->serializeLinks(
31
            $links,
32
            $xmlSerializationVisitor,
33
            $contextProphecy->reveal()
34
        );
35
36
        $this->assertSame(
37
            <<<XML
38
<?xml version="1.0" encoding="UTF-8"?>
39
<root>
40
  <link rel="self" href="/users/42"/>
41
  <link rel="foo" href="/bar" type="magic"/>
42
</root>
43
44
XML
45
            ,
46
            $xmlSerializationVisitor->getResult()
47
        );
48
    }
49
50 View Code Duplication
    public function testSerializeEmbeddeds()
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...
51
    {
52
        $contextProphecy = $this->prophesize('JMS\Serializer\SerializationContext');
53
54
        $embeddeds = array(
55
            new Embedded('friend', array('name' => 'John'), 'person'),
56
        );
57
58
        $xmlSerializationVisitor = $this->createXmlSerializationVisitor();
59
60
        $xmlSerializer = new XmlSerializer();
61
        $xmlSerializer->serializeEmbeddeds(
62
            $embeddeds,
63
            $xmlSerializationVisitor,
64
            $contextProphecy->reveal()
65
        );
66
67
        $this->assertSame(
68
            <<<XML
69
<?xml version="1.0" encoding="UTF-8"?>
70
<root>
71
  <person rel="friend">
72
    <entry/>
73
  </person>
74
</root>
75
76
XML
77
            ,
78
            $xmlSerializationVisitor->getResult()
79
        );
80
    }
81
82
    public function testSerializeAdrienBrault()
83
    {
84
        $hateoas      = HateoasBuilder::buildHateoas();
85
        $adrienBrault = new AdrienBrault();
86
87
        $this->assertSame(
88
            <<<XML
89
<?xml version="1.0" encoding="UTF-8"?>
90
<result>
91
  <first_name><![CDATA[Adrien]]></first_name>
92
  <last_name><![CDATA[Brault]]></last_name>
93
  <link rel="self" href="http://adrienbrault.fr"/>
94
  <link rel="computer" href="http://www.apple.com/macbook-pro/"/>
95
  <link rel="dynamic-relation" href="awesome!!!"/>
96
  <computer rel="computer">
97
    <name><![CDATA[MacBook Pro]]></name>
98
  </computer>
99
  <computer rel="broken-computer">
100
    <name><![CDATA[Windows Computer]]></name>
101
  </computer>
102
  <smartphone rel="smartphone">
103
    <name><![CDATA[iPhone 6]]></name>
104
  </smartphone>
105
  <smartphone rel="smartphone">
106
    <name><![CDATA[Nexus 5]]></name>
107
  </smartphone>
108
  <entry rel="dynamic-relation">
109
    <entry><![CDATA[wowowow]]></entry>
110
  </entry>
111
</result>
112
113
XML
114
            ,
115
            $hateoas->serialize($adrienBrault, 'xml')
116
        );
117
    }
118
119 View Code Duplication
    public function testGh236()
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...
120
    {
121
        $data = new CollectionRepresentation([new Gh236Foo()]);
122
123
        $hateoas = HateoasBuilder::buildHateoas();
124
125
        $this->assertSame(
126
            <<<XML
127
<?xml version="1.0" encoding="UTF-8"?>
128
<collection>
129
  <entry rel="items">
130
    <entry>
131
      <a>
132
        <xxx><![CDATA[yyy]]></xxx>
133
      </a>
134
      <entry rel="b_embed">
135
        <xxx><![CDATA[zzz]]></xxx>
136
      </entry>
137
    </entry>
138
  </entry>
139
</collection>
140
141
XML
142
            ,
143
            $hateoas->serialize($data, 'xml', SerializationContext::create()->enableMaxDepthChecks())
144
        );
145
    }
146
147
    private function createXmlSerializationVisitor()
148
    {
149
        $xmlSerializationVisitor = new XmlSerializationVisitor(
150
            $this->prophesize('JMS\Serializer\Naming\PropertyNamingStrategyInterface')->reveal()
151
        );
152
        $xmlSerializationVisitorClass = new \ReflectionClass('JMS\Serializer\XmlSerializationVisitor');
153
        $stackProperty = $xmlSerializationVisitorClass->getProperty('stack');
154
        $stackProperty->setAccessible('true');
155
        $stackProperty->setValue($xmlSerializationVisitor, new \SplStack());
156
157
        $xmlSerializationVisitor->document = $xmlSerializationVisitor->createDocument(null, null, false);
158
        $xmlRootNode = $xmlSerializationVisitor->document->createElement('root');
159
        $xmlSerializationVisitor->document->appendChild($xmlRootNode);
160
        $xmlSerializationVisitor->setCurrentNode($xmlRootNode);
161
162
        return $xmlSerializationVisitor;
163
    }
164
}
165