1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SPSS\Tests; |
4
|
|
|
|
5
|
|
|
use SPSS\Sav\Reader; |
6
|
|
|
use SPSS\Sav\Variable; |
7
|
|
|
use SPSS\Sav\Writer; |
8
|
|
|
|
9
|
|
|
class LongStringTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
public function testLongString() |
13
|
|
|
{ |
14
|
|
|
$firstLong = str_repeat('1234567890', 300); |
15
|
|
|
$secondLong = str_repeat('abcdefghij', 300); |
16
|
|
|
$data = [ |
17
|
|
|
'header' => [ |
18
|
|
|
'prodName' => '@(#) IBM SPSS STATISTICS', |
19
|
|
|
'layoutCode' => 2, |
20
|
|
|
'creationDate' => '08 May 19', |
21
|
|
|
'creationTime' => '12:22:16', |
22
|
|
|
], |
23
|
|
|
'variables' => [ |
24
|
|
|
[ |
25
|
|
|
'name' => 'LONGER1', |
26
|
|
|
'label' => 'long label1', |
27
|
|
|
'width' => 3000, |
28
|
|
|
'format' => Variable::FORMAT_TYPE_A, |
29
|
|
|
'attributes' => [ |
30
|
|
|
'$@Role' => Variable::ROLE_INPUT, |
31
|
|
|
], |
32
|
|
|
'data' => [ |
33
|
|
|
$firstLong, |
34
|
|
|
$secondLong |
35
|
|
|
] |
36
|
|
|
], |
37
|
|
|
[ |
38
|
|
|
'name' => 'LONGER2', |
39
|
|
|
'label' => 'long label2', |
40
|
|
|
'width' => 3000, |
41
|
|
|
'format' => Variable::FORMAT_TYPE_A, |
42
|
|
|
'attributes' => [ |
43
|
|
|
'$@Role' => Variable::ROLE_INPUT, |
44
|
|
|
], |
45
|
|
|
'data' => [ |
46
|
|
|
$firstLong, |
47
|
|
|
$secondLong |
48
|
|
|
] |
49
|
|
|
], |
50
|
|
|
[ |
51
|
|
|
'name' => 'short', |
52
|
|
|
'label' => 'short label', |
53
|
|
|
'format' => Variable::FORMAT_TYPE_A, |
54
|
|
|
'width' => 8, |
55
|
|
|
'attributes' => [ |
56
|
|
|
'$@Role' => Variable::ROLE_INPUT, |
57
|
|
|
], |
58
|
|
|
'data' => [ |
59
|
|
|
'12345678', |
60
|
|
|
'abcdefgh' |
61
|
|
|
], |
62
|
|
|
], |
63
|
|
|
], |
64
|
|
|
]; |
65
|
|
|
$writer = new Writer($data); |
66
|
|
|
|
67
|
|
|
// Uncomment if you want to really save and check the resulting file in SPSS |
68
|
|
|
//$writer->save('longString.sav'); |
69
|
|
|
|
70
|
|
|
$buffer = $writer->getBuffer(); |
71
|
|
|
$buffer->rewind(); |
72
|
|
|
|
73
|
|
|
$reader = Reader::fromString($buffer->getStream())->read(); |
|
|
|
|
74
|
|
|
|
75
|
|
|
$expected[0][0] = $data['variables'][0]['data'][0]; |
|
|
|
|
76
|
|
|
$expected[0][1] = $data['variables'][1]['data'][0]; |
77
|
|
|
$expected[0][2] = $data['variables'][2]['data'][0]; |
78
|
|
|
$expected[1][0] = $data['variables'][0]['data'][1]; |
79
|
|
|
$expected[1][1] = $data['variables'][1]['data'][1]; |
80
|
|
|
$expected[1][2] = $data['variables'][2]['data'][1]; |
81
|
|
|
$this->assertEquals($expected, $reader->data); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
} |
85
|
|
|
|