123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <?php
- namespace League\CLImate\Tests;
- class TableTest extends TestBase
- {
- /** @test */
- public function it_can_output_a_basic_table()
- {
- $this->shouldWrite("\e[m-------------------------------------\e[0m");
- $this->shouldWrite("\e[m| Cell 1 | Cell 2 | Cell 3 | Cell 4 |\e[0m");
- $this->shouldWrite("\e[m-------------------------------------\e[0m");
- $this->shouldHavePersisted();
- $this->cli->table([
- [
- 'Cell 1',
- 'Cell 2',
- 'Cell 3',
- 'Cell 4',
- ],
- ]);
- }
- /** @test */
- public function it_can_output_an_array_of_objects_table()
- {
- $this->shouldWrite("\e[m-------------------------------------\e[0m");
- $this->shouldWrite("\e[m| cell1 | cell2 | cell3 | cell4 |\e[0m");
- $this->shouldWrite("\e[m=====================================\e[0m");
- $this->shouldWrite("\e[m| Cell 1 | Cell 2 | Cell 3 | Cell 4 |\e[0m");
- $this->shouldWrite("\e[m-------------------------------------\e[0m");
- $this->shouldHavePersisted();
- $this->cli->table([
- (object) [
- 'cell1' => 'Cell 1',
- 'cell2' => 'Cell 2',
- 'cell3' => 'Cell 3',
- 'cell4' => 'Cell 4',
- ],
- ]);
- }
- /** @test */
- public function it_can_output_an_array_of_associative_arrays_table()
- {
- $this->shouldWrite("\e[m-------------------------------------\e[0m");
- $this->shouldWrite("\e[m| cell1 | cell2 | cell3 | cell4 |\e[0m");
- $this->shouldWrite("\e[m=====================================\e[0m");
- $this->shouldWrite("\e[m| Cell 1 | Cell 2 | Cell 3 | Cell 4 |\e[0m");
- $this->shouldWrite("\e[m-------------------------------------\e[0m");
- $this->shouldHavePersisted();
- $this->cli->table([
- [
- 'cell1' => 'Cell 1',
- 'cell2' => 'Cell 2',
- 'cell3' => 'Cell 3',
- 'cell4' => 'Cell 4',
- ],
- ]);
- }
- /** @test */
- public function it_can_persist_a_style_on_the_table()
- {
- $this->shouldWrite("\e[31m-------------------------------------\e[0m");
- $this->shouldWrite("\e[31m| cell1 | cell2 | cell3 | cell4 |\e[0m");
- $this->shouldWrite("\e[31m=====================================\e[0m");
- $this->shouldWrite("\e[31m| Cell 1 | Cell 2 | Cell 3 | Cell 4 |\e[0m");
- $this->shouldWrite("\e[31m-------------------------------------\e[0m");
- $this->shouldHavePersisted();
- $this->cli->redTable([
- [
- 'cell1' => 'Cell 1',
- 'cell2' => 'Cell 2',
- 'cell3' => 'Cell 3',
- 'cell4' => 'Cell 4',
- ],
- ]);
- }
- /** @test */
- public function it_can_handle_tags_within_the_data()
- {
- $this->shouldWrite("\e[m-------------------------------------\e[0m");
- $this->shouldWrite("\e[m| cell1 | cell2 | cell3 | cell4 |\e[0m");
- $this->shouldWrite("\e[m=====================================\e[0m");
- $this->shouldWrite("\e[m| Cell \e[31m1\e[0m | Cell 2 | Cell 3 | Cell 4 |\e[0m");
- $this->shouldWrite("\e[m-------------------------------------\e[0m");
- $this->shouldHavePersisted();
- $this->cli->table([
- [
- 'cell1' => 'Cell <red>1</red>',
- 'cell2' => 'Cell 2',
- 'cell3' => 'Cell 3',
- 'cell4' => 'Cell 4',
- ],
- ]);
- }
- /** @test */
- public function it_can_handle_multi_byte_characters()
- {
- $this->shouldWrite("\e[m-------------------------------------\e[0m");
- $this->shouldWrite("\e[m| cell1 | cell2 | cell3 | cell4 |\e[0m");
- $this->shouldWrite("\e[m=====================================\e[0m");
- $this->shouldWrite("\e[m| Cell Ω | Cell 2 | Cell 3 | Cell 4 |\e[0m");
- $this->shouldWrite("\e[m-------------------------------------\e[0m");
- $this->shouldHavePersisted();
- $this->cli->table([
- [
- 'cell1' => 'Cell Ω',
- 'cell2' => 'Cell 2',
- 'cell3' => 'Cell 3',
- 'cell4' => 'Cell 4',
- ],
- ]);
- }
- /** @test */
- public function it_can_handle_the_same_value_more_than_once()
- {
- $this->shouldWrite("\e[m-------------------------------------\e[0m");
- $this->shouldWrite("\e[m| cell1 | cell2 | cell3 | cell4 |\e[0m");
- $this->shouldWrite("\e[m=====================================\e[0m");
- $this->shouldWrite("\e[m| Cell 1 | Cell 2 | Cell 3 | Cell 3 |\e[0m");
- $this->shouldWrite("\e[m-------------------------------------\e[0m");
- $this->shouldHavePersisted();
- $this->cli->table([
- [
- 'cell1' => 'Cell 1',
- 'cell2' => 'Cell 2',
- 'cell3' => 'Cell 3',
- 'cell4' => 'Cell 3',
- ],
- ]);
- }
- public function testTableWithPrefix1()
- {
- $this->shouldWrite("\e[m\t-----------\e[0m");
- $this->shouldWrite("\e[m\t| Field 1 |\e[0m");
- $this->shouldWrite("\e[m\t===========\e[0m");
- $this->shouldWrite("\e[m\t| Value 1 |\e[0m");
- $this->shouldWrite("\e[m\t-----------\e[0m");
- $this->shouldHavePersisted();
- $this->cli->table([
- ["Field 1" => "Value 1"],
- ], "\t");
- }
- }
|