@@ -58,6 +58,121 @@ public function testTable($headers, $rows)
5858║ testcontent21 │ testcontent22 │ testcontent23 ║
5959╚═══════════════╧═══════════════╧═══════════════╝
6060
61+ EXPECTED;
62+
63+ $ tableContent = $ table
64+ ->setHeaders ($ headers )
65+ ->setRows ($ rows )
66+ ->setScreenWidth (200 )
67+ ->run ();
68+ $ this ->assertEqualsWithoutLE ($ expected , $ tableContent );
69+ }
70+
71+ public function getMultiLineTableData ()
72+ {
73+ return [
74+ [
75+ ['test1 ' , 'test2 ' , 'test3 ' . PHP_EOL . 'multiline ' ],
76+ [
77+ ['test ' . PHP_EOL . 'content1 ' , 'testcontent2 ' , 'test ' . PHP_EOL . 'content3 ' ],
78+ [
79+ 'testcontent21 ' ,
80+ 'testcontent22 ' . PHP_EOL
81+ . 'loooooooooooooooooooooooooooooooooooong ' . PHP_EOL
82+ . 'content ' ,
83+ 'testcontent23 ' . PHP_EOL
84+ . 'loooooooooooooooooooooooooooooooooooong content '
85+ ],
86+ ]
87+ ],
88+ [
89+ ['key1 ' => 'test1 ' , 'key2 ' => 'test2 ' , 'key3 ' => 'test3 ' . PHP_EOL . 'multiline ' ],
90+ [
91+ [
92+ 'key1 ' => 'test ' . PHP_EOL . 'content1 ' ,
93+ 'key2 ' => 'testcontent2 ' ,
94+ 'key3 ' => 'test ' . PHP_EOL . 'content3 '
95+ ],
96+ [
97+ 'key1 ' => 'testcontent21 ' ,
98+ 'key2 ' => 'testcontent22 ' . PHP_EOL
99+ . 'loooooooooooooooooooooooooooooooooooong ' . PHP_EOL
100+ . 'content ' ,
101+ 'key3 ' => 'testcontent23 ' . PHP_EOL
102+ . 'loooooooooooooooooooooooooooooooooooong content '
103+ ],
104+ ]
105+ ]
106+ ];
107+ }
108+
109+ /**
110+ * @dataProvider getMultiLineTableData
111+ */
112+ public function testMultiLineTable ($ headers , $ rows )
113+ {
114+ $ table = new Table ();
115+
116+ $ expected = <<<'EXPECTED'
117+ ╔═════════════╤═════════════════════════════════════╤═════════════════════════════════════════════╗
118+ ║ test1 │ test2 │ test3 ║
119+ ║ │ │ multiline ║
120+ ╟─────────────┼─────────────────────────────────────┼─────────────────────────────────────────────╢
121+ ║ test │ testcontent2 │ test ║
122+ ║ content1 │ │ content3 ║
123+ ╟─────────────┼─────────────────────────────────────┼─────────────────────────────────────────────╢
124+ ║ testcontent │ testcontent22 │ testcontent23 ║
125+ ║ 21 │ loooooooooooooooooooooooooooooooooo │ loooooooooooooooooooooooooooooooooooong con ║
126+ ║ │ oong │ tent ║
127+ ║ │ content │ ║
128+ ╚═════════════╧═════════════════════════════════════╧═════════════════════════════════════════════╝
129+
130+ EXPECTED;
131+
132+ $ tableContent = $ table
133+ ->setHeaders ($ headers )
134+ ->setRows ($ rows )
135+ ->setScreenWidth (100 )
136+ ->run ();
137+ $ this ->assertEqualsWithoutLE ($ expected , $ tableContent );
138+ }
139+
140+ public function getNumericTableData ()
141+ {
142+ return [
143+ [
144+ [1 , 2 , 3 ],
145+ [
146+ [1 , 1.2 , -1.3 ],
147+ [-2 , 2.2 , 2.3 ],
148+ ]
149+ ],
150+ [
151+ ['key1 ' => 1 , 'key2 ' => 2 , 'key3 ' => 3 ],
152+ [
153+ ['key1 ' => 1 , 'key2 ' => 1.2 , 'key3 ' => -1.3 ],
154+ ['key1 ' => -2 , 'key2 ' => 2.2 , 'key3 ' => 2.3 ],
155+ ]
156+ ]
157+ ];
158+ }
159+
160+ /**
161+ * @dataProvider getNumericTableData
162+ */
163+ public function testNumericTable ($ headers , $ rows )
164+ {
165+ $ table = new Table ();
166+
167+ $ expected = <<<'EXPECTED'
168+ ╔════╤═════╤══════╗
169+ ║ 1 │ 2 │ 3 ║
170+ ╟────┼─────┼──────╢
171+ ║ 1 │ 1.2 │ -1.3 ║
172+ ╟────┼─────┼──────╢
173+ ║ -2 │ 2.2 │ 2.3 ║
174+ ╚════╧═════╧══════╝
175+
61176EXPECTED;
62177
63178 $ tableContent = $ table
@@ -141,6 +256,35 @@ public function testListPrefix()
141256 );
142257 }
143258
259+ public function testLongerListPrefix ()
260+ {
261+ $ table = new Table ();
262+
263+ $ expected = <<<'EXPECTED'
264+ ╔═════════════════════════════════╤═════════════════════════════════╤═════════════════════════════╗
265+ ║ test1 │ test2 │ test3 ║
266+ ╟─────────────────────────────────┼─────────────────────────────────┼─────────────────────────────╢
267+ ║ testcontent1 │ testcontent2 │ testcontent3 ║
268+ ╟─────────────────────────────────┼─────────────────────────────────┼─────────────────────────────╢
269+ ║ testcontent21 with looooooooooo │ testcontent22 with looooooooooo │ -- col1 with looooooooooooo ║
270+ ║ ooooooooooooong content │ ooooooooooooong content │ ooooooooooong content ║
271+ ║ │ │ -- col2 with long content ║
272+ ╚═════════════════════════════════╧═════════════════════════════════╧═════════════════════════════╝
273+
274+ EXPECTED;
275+
276+ $ this ->assertEqualsWithoutLE ($ expected , $ table ->setHeaders (['test1 ' , 'test2 ' , 'test3 ' ])
277+ ->setRows ([
278+ ['testcontent1 ' , 'testcontent2 ' , 'testcontent3 ' ],
279+ [
280+ 'testcontent21 with loooooooooooooooooooooooong content ' ,
281+ 'testcontent22 with loooooooooooooooooooooooong content ' ,
282+ ['col1 with loooooooooooooooooooooooong content ' , 'col2 with long content ' ]
283+ ],
284+ ])->setScreenWidth (100 )->setListPrefix ('-- ' )->run ()
285+ );
286+ }
287+
144288 public function testCustomChars ()
145289 {
146290 $ table = new Table ();
0 commit comments