ContactXMLRPCTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
require_once 'Intraface/XMLRPC/Contact/Server.php';
3
4
class ContactXMLRPCTest extends PHPUnit_Framework_TestCase
5
{
6
    protected $server;
7
    protected $db;
8
9
    function setUp()
10
    {
11
        $this->server = new Intraface_XMLRPC_Contact_Server;
12
        $this->db = MDB2::singleton(DB_DSN);
13
    }
14
15
    function tearDown()
16
    {
17
        $this->db->exec('TRUNCATE contact');
18
        $this->db->exec('TRUNCATE address');
19
        unset($this->server);
20
        unset($this->db);
21
    }
22
23
    function getClient()
24
    {
25
        require_once dirname(__FILE__) . '/../../../install/Install.php';
26
27
        if (!defined('SERVER_STATUS')) {
28
            define('SERVER_STATUS', 'TEST');
29
        }
30
31
        $install = new Intraface_Install;
32
        $install->resetServer();
33
        $install->grantModuleAccess('administration', 'contact');
0 ignored issues
show
Unused Code introduced by
The call to Intraface_Install::grantModuleAccess() has too many arguments starting with 'contact'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
34
35
        require_once 'XML/RPC2/Client.php';
36
        $debug = false;
37
        $options = array('prefix' => 'contact.', 'debug' => $debug, 'encoding' => 'utf-8');
38
        $client = XML_RPC2_Client::create(XMLRPC_SERVER_URL.'contact', $options);
39
40
        return $client;
41
    }
42
43
    ////////////////////////////////////////////////
44
45
    function testConstruction()
46
    {
47
        $this->markTestIncomplete(
48
            'This test has not been implemented yet.'
49
        );
50
        $this->assertTrue(is_object($this->server));
51
    }
52
53
    function testEmptyCredentialsThrowsException()
54
    {
55
        $this->markTestIncomplete(
56
            'This test has not been implemented yet.'
57
        );
58
        $credentials = array();
59
        $data = array();
60
61
        try {
62
            $this->server->saveContact($credentials, $data);
0 ignored issues
show
Documentation introduced by
$credentials is of type array, but the function expects a object<Struct>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
63
            $this->assertFalse(true, 'Should have thrown an exception');
64
        } catch (XML_RPC2_FaultException $e) {
0 ignored issues
show
Bug introduced by
The class XML_RPC2_FaultException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
65
            $this->assertTrue(true);
66
        }
67
    }
68
69
    function testInvalidKeyThrowsException()
70
    {
71
        $this->markTestIncomplete(
72
            'This test has not been implemented yet.'
73
        );
74
        $credentials = array('private_key' => 'privatekeyshouldbereplaced', 'session_id' => 'something');
75
        $data = array();
76
        try {
77
            $this->server->saveContact($credentials, $data);
0 ignored issues
show
Documentation introduced by
$credentials is of type array<string,string,{"pr..."session_id":"string"}>, but the function expects a object<Struct>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
78
            $this->assertFalse(true, 'Should have thrown an exception');
79
        } catch (XML_RPC2_FaultException $e) {
0 ignored issues
show
Bug introduced by
The class XML_RPC2_FaultException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
80
            $this->assertTrue(true);
81
        }
82
    }
83
84
    /**
85
     * @group xmlrpc
86
     */
87
    function testGetContactWithDanishCharactersIsReturnedInUTF8FromTheClient()
88
    {
89
        $this->markTestIncomplete(
90
            'This test has not been implemented yet.'
91
        );
92
        $client = $this->getClient();
93
        $credentials = array('private_key' => 'privatekeyshouldbereplaced', 'session_id' => 'something');
94
95
        $contact = new Contact(new Stub_Kernel);
96
        $data = array('name' => 'Tester æøå');
97
        $res = $contact->save($data);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $res is correct as $contact->save($data) (which targets Contact::save()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
98
        $this->assertEquals(1, $res);
99
        $this->assertEquals('Tester æøå', $contact->get('name'));
100
101
        $retrieved = $client->getContact($credentials, $contact->getId());
102
103
        $this->assertEquals('Tester æøå', $retrieved['name']);
104
    }
105
106
    /**
107
     * @group xmlrpc
108
     */
109
    function testSaveContactWorksWithDanishCharacters()
110
    {
111
        $this->markTestIncomplete(
112
            'This test has not been implemented yet.'
113
        );
114
        $client = $this->getClient();
115
        $credentials = array('private_key' => 'privatekeyshouldbereplaced', 'session_id' => 'something');
116
117
        $contact = new Contact(new Stub_Kernel);
118
        $data = array('name' => 'Tester');
119
        $contact->save($data);
120
121
        $new_name = 'Tester æøå';
122
        $data = array('id' => $contact->getId(), 'name' => $new_name);
123
        $this->assertTrue($client->saveContact($credentials, $data));
124
125
        $saved_contact = new Contact(new Stub_Kernel, $contact->getId());
126
        $this->assertEquals($new_name, $saved_contact->get('name'));
127
    }
128
}
129