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; |
13
|
|
|
|
14
|
|
|
use Xabbuh\XApi\DataFixtures\StatementResultFixtures; |
15
|
|
|
use Xabbuh\XApi\Serializer\StatementResultSerializer; |
16
|
|
|
use Xabbuh\XApi\Serializer\Tests\Fixtures\StatementResultJsonFixtures; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author Christian Flothmann <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class StatementResultSerializerTest extends AbstractSerializerTest |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var StatementResultSerializer |
25
|
|
|
*/ |
26
|
|
|
private $statementResultSerializer; |
27
|
|
|
|
28
|
|
|
protected function setUp() |
29
|
|
|
{ |
30
|
|
|
parent::setUp(); |
31
|
|
|
$this->statementResultSerializer = new StatementResultSerializer($this->serializer); |
32
|
|
|
} |
33
|
|
View Code Duplication |
public function testDeserializeStatementResult() |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
/** @var \Xabbuh\XApi\Model\StatementResult $statementResult */ |
36
|
|
|
$statementResult = $this->statementResultSerializer->deserializeStatementResult( |
37
|
|
|
StatementResultJsonFixtures::getStatementResult() |
38
|
|
|
); |
39
|
|
|
$statements = $statementResult->getStatements(); |
40
|
|
|
|
41
|
|
|
$this->assertEquals(2, count($statements)); |
42
|
|
|
$this->assertEquals( |
43
|
|
|
'12345678-1234-5678-8234-567812345678', |
44
|
|
|
$statements[0]->getId() |
45
|
|
|
); |
46
|
|
|
$this->assertEquals( |
47
|
|
|
'12345678-1234-5678-8234-567812345679', |
48
|
|
|
$statements[1]->getId() |
49
|
|
|
); |
50
|
|
|
$this->assertNull($statementResult->getMoreUrlPath()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testSerializeMinimalStatement() |
54
|
|
|
{ |
55
|
|
|
$statementResult = StatementResultFixtures::getStatementResult(); |
56
|
|
|
|
57
|
|
|
$this->assertJsonEquals( |
58
|
|
|
StatementResultJsonFixtures::getStatementResult(), |
59
|
|
|
$this->statementResultSerializer->serializeStatementResult($statementResult) |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
View Code Duplication |
public function testDeserializeStatementResultWithMore() |
|
|
|
|
64
|
|
|
{ |
65
|
|
|
/** @var \Xabbuh\XApi\Model\StatementResult $statementResult */ |
66
|
|
|
$statementResult = $this->statementResultSerializer->deserializeStatementResult( |
67
|
|
|
StatementResultJsonFixtures::getStatementResultWithMore() |
68
|
|
|
); |
69
|
|
|
$statements = $statementResult->getStatements(); |
70
|
|
|
|
71
|
|
|
$this->assertEquals(2, count($statements)); |
72
|
|
|
$this->assertEquals( |
73
|
|
|
'12345678-1234-5678-8234-567812345678', |
74
|
|
|
$statements[0]->getId() |
75
|
|
|
); |
76
|
|
|
$this->assertEquals( |
77
|
|
|
'12345678-1234-5678-8234-567812345679', |
78
|
|
|
$statements[1]->getId() |
79
|
|
|
); |
80
|
|
|
$this->assertEquals( |
81
|
|
|
'/xapi/statements/more/b381d8eca64a61a42c7b9b4ecc2fabb6', |
82
|
|
|
$statementResult->getMoreUrlPath() |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function testSerializeMinimalStatementWithMore() |
87
|
|
|
{ |
88
|
|
|
$statementResult = StatementResultFixtures::getStatementResultWithMore(); |
89
|
|
|
|
90
|
|
|
$this->assertJsonEquals( |
91
|
|
|
StatementResultJsonFixtures::getStatementResultWithMore(), |
92
|
|
|
$this->statementResultSerializer->serializeStatementResult($statementResult) |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
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.