SkautisDataCollectorTest::testSerialize()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 28
rs 8.8571
cc 1
eloc 20
nc 1
nop 0
1
<?php
2
3
namespace Test\SkautisBundle;
4
5
use Skautis\Skautis;
6
use Skautis\Config;
7
use Skautis\User;
8
use Skautis\SessionAdapter\FakeAdapter;
9
use Skautis\Wsdl\WsdlManager;
10
use Skautis\Wsdl\WebServiceFactory;
11
use SkautisBundle\Profiler\SkautisDataCollector;
12
use Symfony\Component\HttpFoundation\Request;
13
use Symfony\Component\HttpFoundation\Response;
14
15
class SkautisDataCollectorTest extends \PHPUnit_Framework_TestCase
16
{
17
18
    protected function makeSkautis()
19
    {
20
        $config = new Config('id123');
21
        $sessionAdapter = new FakeAdapter();
22
        $factory = new WebServiceFactory();
23
        $wsdlManager = new WsdlManager($factory, $config);
24
        $user = new user($wsdlManager, $sessionAdapter);
25
26
        return new Skautis($wsdlManager, $user);
27
    }
28
29
30
    public function testCollect()
31
    {
32
        $data = [
33
            'skautIS_Token' => 'tok_en',
34
            'skautIS_IDUnit' => 456,
35
            'skautIS_IDRole' => 789,
36
            'skautIS_DateLogout' => '2. 12. 2014 23:56:02'
37
        ];
38
39
        $skautis = $this->makeSkautis();
40
        $skautis->setLoginData($data);
41
42
        $dataCollector = new SkautisDataCollector($skautis);
43
        $request = new Request();
44
        $response = new Response();
45
        $dataCollector->collect($request, $response);
46
47
        $this->assertEquals("id123", $dataCollector->app_id());
0 ignored issues
show
Documentation Bug introduced by
The method app_id does not exist on object<SkautisBundle\Pro...r\SkautisDataCollector>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
48
        $this->assertEquals("tok_en", $dataCollector->token());
0 ignored issues
show
Documentation Bug introduced by
The method token does not exist on object<SkautisBundle\Pro...r\SkautisDataCollector>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
49
        $this->assertEquals(false, $dataCollector->test_mode());
0 ignored issues
show
Documentation Bug introduced by
The method test_mode does not exist on object<SkautisBundle\Pro...r\SkautisDataCollector>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
50
        $this->assertEquals(789, $dataCollector->role_id());
0 ignored issues
show
Documentation Bug introduced by
The method role_id does not exist on object<SkautisBundle\Pro...r\SkautisDataCollector>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
51
    }
52
53
54
    public function testSerialize()
55
    {
56
        $data = [
57
            'skautIS_Token' => 'tok_en',
58
            'skautIS_IDUnit' => 456,
59
            'skautIS_IDRole' => 789,
60
            'skautIS_DateLogout' => '2. 12. 2014 23:56:02'
61
        ];
62
63
        $skautis = $this->makeSkautis();
64
        $skautis->setLoginData($data);
65
66
        $dataCollector = new SkautisDataCollector($skautis);
67
        $request = new Request();
68
        $response = new Response();
69
        $dataCollector->collect($request, $response);
70
71
        // Symfony uklada data do souboru -> vyzaduje serialize
72
        $serialized = serialize($dataCollector);
73
        unset($dataCollector);
74
        unset($skautis);
75
76
        $unserializedCollector = unserialize($serialized);
77
        $this->assertEquals("id123", $unserializedCollector->app_id());
78
        $this->assertEquals("tok_en", $unserializedCollector->token());
79
        $this->assertEquals(false, $unserializedCollector->test_mode());
80
        $this->assertEquals(789, $unserializedCollector->role_id());
81
    }
82
}
83