Completed
Push — master ( 8f233e...cb7239 )
by Tobias
45:50 queued 28:37
created

TrackerDummy   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 7
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 1
c 1
b 0
f 1
lcom 0
cbo 1
dl 0
loc 7
rs 10
1
<?php
2
3
namespace Happyr\GoogleAnalyticsBundle\Tests\Unit\Service;
4
5
use Happyr\GoogleAnalyticsBundle\Service\Tracker;
6
7
/**
8
 * Class TrackerTest.
9
 *
10
 * @author Tobias Nyholm
11
 */
12
class TrackerTest extends \PHPUnit_Framework_TestCase
13
{
14
    public function testSend()
15
    {
16
        $trackerId = 'foo';
17
        $version = 1;
18
        $clientId = 'clientId';
19
20
        $data = [
21
            'v'   => $version,
22
            'tid' => $trackerId,
23
            'cid' => $clientId,
24
            't'   => 'pageview',
25
            'baz' => 'bar',
26
        ];
27
28
        $httpClient = $this->getMockBuilder('Happyr\GoogleAnalyticsBundle\Http\HttpClientInterface')
29
            ->setMethods(['send'])
30
            ->disableOriginalConstructor()
31
            ->getMock();
32
33
        $httpClient->expects($this->once())
34
            ->method('send')
35
            ->with($data)
36
            ->willReturn(true);
37
38
        $clientIdProvider = $this->getMockBuilder('Happyr\GoogleAnalyticsBundle\Service\ClientIdProvider')
39
            ->disableOriginalConstructor()
40
            ->getMock();
41
42
        $tracker = $this->getMockBuilder('Happyr\GoogleAnalyticsBundle\Service\Tracker')
43
            ->setMethods(['getClientId'])
44
            ->enableOriginalConstructor()
45
            ->setConstructorArgs([$httpClient, $clientIdProvider, $trackerId, $version])
46
            ->getMock();
47
48
        $tracker->expects($this->once())
49
            ->method('getClientId')
50
            ->willReturn($clientId);
51
52
        $tracker->send(['baz' => 'bar'], 'pageview');
53
    }
54
55
    public function testGetClientId()
56
    {
57
        $clientId = 'foobar';
58
        $provider = $this->getMockBuilder('Happyr\GoogleAnalyticsBundle\Service\ClientIdProvider')
59
            ->setMethods(['getClientId'])
60
            ->disableOriginalConstructor()
61
            ->getMock();
62
        $provider->expects($this->once())
63
            ->method('getClientId')
64
            ->willReturn($clientId);
65
66
        $tracker = new TrackerDummy(
67
            $this->getMockBuilder('Happyr\GoogleAnalyticsBundle\Http\HttpClientInterface')->getMock(),
68
            $provider,
69
            'foo',
70
            'bar'
71
        );
72
73
        $firstResult = $tracker->getClientId();
74
        $secondResult = $tracker->getClientId();
75
76
        $this->assertEquals($firstResult, $secondResult, 'getClientId must return the same ID at every call');
77
    }
78
}
79
class TrackerDummy extends Tracker
80
{
81
    public function getClientId()
82
    {
83
        return parent::getClientId();
84
    }
85
}
86