FakeSubscriberContact::getId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
require_once 'Intraface/modules/newsletter/NewsletterSubscriber.php';
3
require_once 'NewsletterStubs.php';
4
5
class FakeObserver
6
{
7
    function update()
8
    {
9
    }
10
}
11
12
class FakeSubscriberContact
13
{
14
    function getId()
15
    {
16
        return 1000;
17
    }
18
}
19
20
class NewsletterSubscriberTest extends PHPUnit_Framework_TestCase
21
{
22 View Code Duplication
    function setUp()
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...
23
    {
24
        $db = MDB2::singleton(DB_DSN);
25
        $db->exec('TRUNCATE newsletter_subscriber');
26
        $db->exec('TRUNCATE newsletter_archieve');
27
        $db->exec('TRUNCATE contact');
28
        $db->exec('TRUNCATE address');
29
    }
30
31
    function createSubscriber()
32
    {
33
        $list = new FakeNewsletterList();
34
        $list->kernel = new Stub_Kernel;
35
        $list->kernel->setting->set('intranet', 'contact.login_url', 'http://localhost/');
36
        return new NewsletterSubscriber($list);
37
    }
38
39
    function testConstructionSubscriber()
40
    {
41
        $subscriber = $this->createSubscriber();
42
        $this->assertTrue(is_object($subscriber));
43
    }
44
45
    function testSubscribe()
46
    {
47
        $subscriber = $this->createSubscriber();
48
        $data = array('email' => '[email protected]', 'ip' => 'ip');
49
        $this->assertTrue($subscriber->subscribe($data));
0 ignored issues
show
Documentation introduced by
$data is of type array<string,string,{"em...string","ip":"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...
50
    }
51
52
    function testUnSubscribe()
53
    {
54
        $subscriber = $this->createSubscriber();
55
        $this->assertTrue($subscriber->unsubscribe('[email protected]'));
56
    }
57
58
    function testOptin()
59
    {
60
        $subscriber = $this->createSubscriber();
61
        $data = array('email' => '[email protected]', 'ip' => 'ip');
62
        $this->assertTrue($subscriber->subscribe($data));
0 ignored issues
show
Documentation introduced by
$data is of type array<string,string,{"em...string","ip":"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...
63
        $code = 'wrongcode';
64
        $ip = 'ip';
65
66
        $this->assertFalse($subscriber->optIn($code, $ip));
67
        $code = $subscriber->get('code');
68
        $this->assertTrue($subscriber->optIn($code, $ip));
69
        $this->assertTrue($subscriber->optedIn());
70
    }
71
72
    function testAddObserver()
73
    {
74
        $subscriber = new NewsletterSubscriber(new FakeNewsletterList);
75
        $subscriber->addObserver(new FakeObserver);
76
        $this->assertEquals(1, count($subscriber->getObservers()));
77
    }
78
79
    function testAddContactReturnsInteger()
80
    {
81
        $subscriber = new NewsletterSubscriber(new FakeNewsletterList);
82
        $this->assertTrue($subscriber->addContact(new FakeSubscriberContact) > 0);
83
    }
84
85
    function testGetContactReturnsContactObject()
86
    {
87
        $subscriber = new NewsletterSubscriber(new FakeNewsletterList);
88
        $contact = new FakeSubscriberContact;
89
        $subscriber->addContact($contact);
90
        $this->assertTrue(is_object($subscriber->getContact($contact->getId())));
91
    }
92
93
    function testDeleteSubscriber()
94
    {
95
        $subscriber = new NewsletterSubscriber(new FakeNewsletterList);
96
        $this->assertTrue($subscriber->delete());
97
    }
98
99
    function testGetListReturnsArray()
100
    {
101
        $subscriber = new NewsletterSubscriber(new FakeNewsletterList);
102
        $this->assertTrue(is_array($subscriber->getList()));
103
    }
104
105
    function testGetListReturnsActiveOptedInSubscribers()
106
    {
107
        $subscriber = $this->createSubscriber();
108
        $subscriber->subscribe(array('name' => 'test1', 'email' => '[email protected]', 'ip' => '0.0.0.0'));
0 ignored issues
show
Documentation introduced by
array('name' => 'test1',...dk', 'ip' => '0.0.0.0') is of type array<string,string,{"na...string","ip":"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...
109
110
        $subscriber = $this->createSubscriber();
111
        $subscriber->subscribe(array('name' => 'test2', 'email' => '[email protected]', 'ip' => '0.0.0.0'));
0 ignored issues
show
Documentation introduced by
array('name' => 'test2',...dk', 'ip' => '0.0.0.0') is of type array<string,string,{"na...string","ip":"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...
112
        $subscriber->optin($subscriber->get('code'), '0.0.0.0');
113
114
        $subscriber = $this->createSubscriber();
115
        $subscriber->subscribe(array('name' => 'test3', 'email' => '[email protected]', 'ip' => '0.0.0.0'));
0 ignored issues
show
Documentation introduced by
array('name' => 'test3',...dk', 'ip' => '0.0.0.0') is of type array<string,string,{"na...string","ip":"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...
116
        $subscriber->optin($subscriber->get('code'), '0.0.0.0');
117
        $subscriber->delete();
118
119
        $list = $subscriber->getList();
120
121
        $this->assertEquals(1, count($list));
122
        $this->assertEquals('[email protected]', $list[0]['contact_email']);
123
    }
124
}
125