55
66function hudsonFixtureBase (): string
77{
8- return __DIR__ .'/../../../archive/messages/HUDSON ' ;
8+ $ path = sys_get_temp_dir ().'/laravel-ftn-hudson-tests ' ;
9+
10+ if (! is_dir ($ path )) {
11+ mkdir ($ path , recursive: true );
12+ }
13+
14+ $ body = "I want this Hudson body preserved. \r\n" ;
15+ $ recordCount = (int ) ceil (strlen ($ body ) / 128 );
16+
17+ file_put_contents ($ path .'/MSGIDX.BBS ' , pack ('vC ' , 42 , 7 ));
18+ file_put_contents ($ path .'/MSGHDR.BBS ' , hudsonHeader (
19+ msgno: 42 ,
20+ replyTo: 12 ,
21+ firstReply: 13 ,
22+ startRecord: 0 ,
23+ recordCount: $ recordCount ,
24+ board: 7 ,
25+ fromName: 'Odinn Sorensen ' ,
26+ toName: 'Gregory ThroatWobbler ' ,
27+ subject: 'Keep on the good work.. ' ,
28+ date: '01-01-24 ' ,
29+ time: '12:34 ' ,
30+ ));
31+ file_put_contents ($ path .'/MSGTXT.BBS ' , str_pad ($ body , $ recordCount * 128 , "\0" ));
32+
33+ return $ path ;
934}
1035
1136it ('reads real Hudson messages and board metadata ' , function (): void {
1237 $ messages = array_values (iterator_to_array (new HudsonReader ()->read (hudsonFixtureBase ())));
1338 $ first = firstHudsonMessage ($ messages );
1439
15- expect ($ first ->fromName )->toBe ('Dirk A. Mueller ' )
16- ->and ($ first ->toName )->not ->toBeEmpty ()
17- ->and ($ first ->subject )->not ->toBeEmpty ()
40+ expect ($ first ->msgno )->toBe (42 )
41+ ->and ($ first ->fromName )->toBe ('Odinn Sorensen ' )
42+ ->and ($ first ->toName )->toBe ('Gregory ThroatWobbler ' )
43+ ->and ($ first ->subject )->toBe ('Keep on the good work.. ' )
44+ ->and ($ first ->bodyText )->toContain ('Hudson body preserved ' )
1845 ->and ($ first ->postedAt )->not ->toBeNull ()
19- ->and ($ first ->areaCode )->toStartWith ('BOARD ' );
46+ ->and ($ first ->replyToMsgno )->toBe (12 )
47+ ->and ($ first ->reply1stMsgno )->toBe (13 )
48+ ->and ($ first ->areaCode )->toBe ('BOARD7 ' )
49+ ->and ($ first ->areaName )->toBe ('BOARD7 ' )
50+ ->and ($ first ->areaSortOrder )->toBe (7 )
51+ ->and ($ first ->areaMetaKey )->toBe ('hudson:7 ' );
2052});
2153
2254/**
@@ -30,3 +62,42 @@ function firstHudsonMessage(array $messages): ParsedMessage
3062
3163 return $ messages [0 ];
3264}
65+
66+ function hudsonHeader (
67+ int $ msgno ,
68+ int $ replyTo ,
69+ int $ firstReply ,
70+ int $ startRecord ,
71+ int $ recordCount ,
72+ int $ board ,
73+ string $ fromName ,
74+ string $ toName ,
75+ string $ subject ,
76+ string $ date ,
77+ string $ time ,
78+ ): string {
79+ return pack (
80+ 'v11C5 ' ,
81+ $ msgno ,
82+ $ replyTo ,
83+ $ firstReply ,
84+ 0 ,
85+ $ startRecord ,
86+ $ recordCount ,
87+ 0 ,
88+ 0 ,
89+ 0 ,
90+ 0 ,
91+ 0 ,
92+ 0 ,
93+ 0 ,
94+ 0 ,
95+ 0 ,
96+ $ board ,
97+ )
98+ .str_pad ("\0" .$ time , 6 , "\0" )
99+ .str_pad ("\0" .$ date , 9 , "\0" )
100+ .str_pad ("\0" .$ toName , 36 , "\0" )
101+ .str_pad ("\0" .$ fromName , 36 , "\0" )
102+ .str_pad ("\0" .$ subject , 73 , "\0" );
103+ }
0 commit comments