|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the xAPI package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Christian Flothmann <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Xabbuh\XApi\Serializer\Tests\Event; |
|
13
|
|
|
|
|
14
|
|
|
use JMS\Serializer\DeserializationContext; |
|
15
|
|
|
use JMS\Serializer\EventDispatcher\PreDeserializeEvent; |
|
16
|
|
|
use Xabbuh\XApi\Serializer\Event\AddDataSubscriber; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @author Christian Flothmann <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
abstract class AddDataSubscriberTest extends \PHPUnit_Framework_TestCase |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var AddDataSubscriber |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $eventSubscriber; |
|
27
|
|
|
|
|
28
|
|
|
public function testGetSubscribedEvents() |
|
29
|
|
|
{ |
|
30
|
|
|
$this->assertEquals( |
|
31
|
|
|
array( |
|
32
|
|
|
array( |
|
33
|
|
|
'event' => 'serializer.pre_deserialize', |
|
34
|
|
|
'method' => 'onPreDeserialize', |
|
35
|
|
|
), |
|
36
|
|
|
), |
|
37
|
|
|
$this->eventSubscriber->getSubscribedEvents() |
|
38
|
|
|
); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @dataProvider getEventData |
|
43
|
|
|
*/ |
|
44
|
|
|
public function testOnPreDeserialize($type, $rawData, $expectedData) |
|
45
|
|
|
{ |
|
46
|
|
|
$event = new PreDeserializeEvent( |
|
47
|
|
|
$this->createDeserelizationContext(), |
|
48
|
|
|
$rawData, |
|
49
|
|
|
$type |
|
50
|
|
|
); |
|
51
|
|
|
$this->eventSubscriber->onPreDeserialize($event); |
|
52
|
|
|
|
|
53
|
|
|
$this->assertEquals($expectedData, $event->getData()); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
abstract public function getEventData(); |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @return DeserializationContext |
|
60
|
|
|
*/ |
|
61
|
|
|
private function createDeserelizationContext() |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->getMock('\JMS\Serializer\DeserializationContext'); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|