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

ClientIdProviderTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
c 1
b 0
f 1
lcom 1
cbo 3
dl 0
loc 25
rs 10
1
<?php
2
3
namespace Happyr\GoogleAnalyticsBundle\Tests\Unit\Service;
4
5
use Happyr\GoogleAnalyticsBundle\Service\ClientIdProvider;
6
use Symfony\Component\HttpFoundation\RequestStack;
7
8
/**
9
 * Class ClientIdProviderTest.
10
 *
11
 * @author Tobias Nyholm
12
 */
13
class ClientIdProviderTest extends \PHPUnit_Framework_TestCase
14
{
15
    public function testGetClientId()
16
    {
17
        $provider = $this->getMockBuilder('Happyr\GoogleAnalyticsBundle\Service\ClientIdProvider')
18
            ->setMethods(['getClientIdFormCookie'])
19
            ->disableOriginalConstructor()
20
            ->getMock();
21
        $provider->expects($this->once())
22
            ->method('getClientIdFormCookie')
23
            ->willReturn(false);
24
25
        $result = $provider->getClientId();
26
27
        $this->assertRegExp('|[0-9]{9}+|', $result, 'Not big and random enough');
28
    }
29
30
    public function testExtractCookie()
31
    {
32
        $provider = new ProviderDummy();
33
34
        $this->assertEquals('1110480476.1405690517', $provider->extractCookie('GA1.2.1110480476.1405690517'));
35
        $this->assertEquals('286403989.1366364567', $provider->extractCookie('1.2.286403989.1366364567'));
36
    }
37
}
38
class ProviderDummy extends ClientIdProvider
39
{
40
    public function __construct()
41
    {
42
        $this->requestStack = new RequestStack();
43
    }
44
45
    public function extractCookie($cookieValue)
46
    {
47
        return parent::extractCookie($cookieValue);
48
    }
49
}
50