SerializerFactoryTest   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 10
c 0
b 0
f 0
lcom 0
cbo 4
dl 0
loc 73
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A testNotProvidedMimeType() 0 3 1
A testMimeTypes() 0 6 1
A testEmptyMimeType() 0 5 1
A testUnsupportedMimeType() 0 5 1
A testCreateFromRequestWithAcceptHeader() 0 14 1
A testCreateFromRequestWithUnsupportedAcceptHeader() 0 5 1
A testCreateFromRequestWithGetVar() 0 8 1
A testCreateFromRequestWithWrongGetVar() 0 4 1
A testGetVarBeforeHeader() 0 5 1
A testGetVarAndHeaderEmpty() 0 6 1
1
<?php
2
3
namespace Ntb\RestAPI;
4
5
use SapphireTest;
6
use SS_HTTPRequest;
7
8
/**
9
 * Tests for the serializer factory.
10
 * @author Christian Blank <[email protected]>
11
 */
12
class SerializerFactoryTest extends SapphireTest {
13
14
    public function testNotProvidedMimeType() {
15
        $this->assertTrue(SerializerFactory::create() instanceof JsonSerializer);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<Ntb\RestAPI\SerializerFactoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
16
    }
17
18
    public function testMimeTypes() {
19
        $this->assertTrue(SerializerFactory::create('application/json') instanceof JsonSerializer);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<Ntb\RestAPI\SerializerFactoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
20
        $this->assertTrue(SerializerFactory::create('application/xml') instanceof XmlSerializer);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<Ntb\RestAPI\SerializerFactoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
21
        $this->assertTrue(SerializerFactory::create('application/yaml') instanceof YamlSerializer);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<Ntb\RestAPI\SerializerFactoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
22
        $this->assertTrue(SerializerFactory::create('text/html') instanceof HtmlSerializer);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<Ntb\RestAPI\SerializerFactoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
23
    }
24
25
    public function testEmptyMimeType() {
26
        TestHelper::assertException(function() {
27
            SerializerFactory::create("");
28
        }, 'Ntb\RestAPI\RestUserException');
29
    }
30
31
    public function testUnsupportedMimeType() {
32
        TestHelper::assertException(function() {
33
            SerializerFactory::create("foo/bar");
34
        }, 'Ntb\RestAPI\RestUserException');
35
    }
36
37
    public function testCreateFromRequestWithAcceptHeader() {
38
        $request = new SS_HTTPRequest("GET", "");
39
        $request->addHeader('Accept', 'text/html,multipart/mixed,*/*');
40
        $this->assertTrue(SerializerFactory::create_from_request($request) instanceof HtmlSerializer);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<Ntb\RestAPI\SerializerFactoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
41
        $request1 = new SS_HTTPRequest("GET", "");
42
        $request1->addHeader('Accept', 'application/json,text/html,multipart/mixed,*/*');
43
        $this->assertTrue(SerializerFactory::create_from_request($request1) instanceof JsonSerializer);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<Ntb\RestAPI\SerializerFactoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
44
        $request2 = new SS_HTTPRequest("GET", "");
45
        $request2->addHeader('Accept', 'foo/bar,application/yaml,text/html,multipart/mixed,*/*');
46
        $this->assertTrue(SerializerFactory::create_from_request($request2) instanceof YamlSerializer);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<Ntb\RestAPI\SerializerFactoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
47
        $request3 = new SS_HTTPRequest("GET", "");
48
        $request3->addHeader('Accept', 'foo/bar,application/xml,text/html,multipart/mixed,*/*');
49
        $this->assertTrue(SerializerFactory::create_from_request($request3) instanceof XmlSerializer);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<Ntb\RestAPI\SerializerFactoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
50
    }
51
52
    public function testCreateFromRequestWithUnsupportedAcceptHeader() {
53
        $request = new SS_HTTPRequest("GET", "");
54
        $request->addHeader('Accept', 'foo/bar, multipart/mixed, */*');
55
        $this->assertTrue(SerializerFactory::create_from_request($request) instanceof JsonSerializer);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<Ntb\RestAPI\SerializerFactoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
56
    }
57
58
    public function testCreateFromRequestWithGetVar() {
59
        $request = new SS_HTTPRequest("GET", "", ['accept' => 'json']);
60
        $this->assertTrue(SerializerFactory::create_from_request($request) instanceof JsonSerializer);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<Ntb\RestAPI\SerializerFactoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
61
        $request1 = new SS_HTTPRequest("GET", "", ['accept' => 'yaml']);
62
        $this->assertTrue(SerializerFactory::create_from_request($request1) instanceof YamlSerializer);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<Ntb\RestAPI\SerializerFactoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
63
        $request2 = new SS_HTTPRequest("GET", "", ['accept' => 'xml']);
64
        $this->assertTrue(SerializerFactory::create_from_request($request2) instanceof XmlSerializer);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<Ntb\RestAPI\SerializerFactoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
65
    }
66
67
    public function testCreateFromRequestWithWrongGetVar() {
68
        $request = new SS_HTTPRequest("GET", "", ['accept' => 'foo']);
69
        $this->assertTrue(SerializerFactory::create_from_request($request) instanceof JsonSerializer);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<Ntb\RestAPI\SerializerFactoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
70
    }
71
72
    public function testGetVarBeforeHeader() {
73
        $request = new SS_HTTPRequest("GET", "", ['accept' => 'yaml']);
74
        $request->addHeader('Accept', 'text/html,multipart/mixed,*/*');
75
        $this->assertTrue(SerializerFactory::create_from_request($request) instanceof YamlSerializer);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<Ntb\RestAPI\SerializerFactoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
76
    }
77
78
    public function testGetVarAndHeaderEmpty() {
79
        $request = new SS_HTTPRequest("GET", "");
80
        $request->addHeader('Accept', '');
81
        $this->assertTrue(SerializerFactory::create_from_request($request) instanceof JsonSerializer);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<Ntb\RestAPI\SerializerFactoryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
82
83
    }
84
}
85