From e4a0c5d556ee8acd3abdbf7a8476e132e7ee6413 Mon Sep 17 00:00:00 2001 From: Roman Martinuk Date: Tue, 20 Jul 2021 19:36:01 +0300 Subject: [PATCH 1/2] [Console] fix table setHeaderTitle without headers --- .../Component/Console/Helper/Table.php | 14 +++++++------ .../Console/Tests/Helper/TableTest.php | 21 +++++++++++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Console/Helper/Table.php b/src/Symfony/Component/Console/Helper/Table.php index 8f9e972408..1d0a22baa3 100644 --- a/src/Symfony/Component/Console/Helper/Table.php +++ b/src/Symfony/Component/Console/Helper/Table.php @@ -374,6 +374,7 @@ class Table $isHeader = !$this->horizontal; $isFirstRow = $this->horizontal; + $hasTitle = (bool) $this->headerTitle; foreach ($rows as $row) { if ($divider === $row) { $isHeader = false; @@ -391,12 +392,13 @@ class Table } if ($isHeader || $isFirstRow) { - if ($isFirstRow) { - $this->renderRowSeparator(self::SEPARATOR_TOP_BOTTOM); - $isFirstRow = false; - } else { - $this->renderRowSeparator(self::SEPARATOR_TOP, $this->headerTitle, $this->style->getHeaderTitleFormat()); - } + $this->renderRowSeparator( + $isHeader ? self::SEPARATOR_TOP : self::SEPARATOR_TOP_BOTTOM, + $hasTitle ? $this->headerTitle : null, + $hasTitle ? $this->style->getHeaderTitleFormat() : null + ); + $isFirstRow = false; + $hasTitle = false; } if ($this->horizontal) { $this->renderRow($row, $this->style->getCellRowFormat(), $this->style->getCellHeaderFormat()); diff --git a/src/Symfony/Component/Console/Tests/Helper/TableTest.php b/src/Symfony/Component/Console/Tests/Helper/TableTest.php index d02d6ea42e..eed0b16623 100644 --- a/src/Symfony/Component/Console/Tests/Helper/TableTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/TableTest.php @@ -1115,6 +1115,27 @@ TABLE ]; } + public function testSetTitleWithoutHeaders() + { + (new Table($output = $this->getOutputStream())) + ->setHeaderTitle('Reproducer') + ->setRows([ + ['Value', '123-456'], + ['Some other value', '789-0'], + ]) + ->render(); + + $expected = <<<'TABLE' ++-------- Reproducer --------+ +| Value | 123-456 | +| Some other value | 789-0 | ++------------------+---------+ + +TABLE; + + $this->assertSame($expected, $this->getOutputContent($output)); + } + public function testColumnMaxWidths() { $table = new Table($output = $this->getOutputStream()); From 8c11c16fda50c8dfa9400fb3566e523bd515e59a Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 21 Jul 2021 13:47:49 +0200 Subject: [PATCH 2/2] Fix intersection types on tests --- .../Tests/CacheWarmer/AnnotationsCacheWarmerTest.php | 2 +- .../Tests/Command/CachePoolDeleteCommandTest.php | 2 +- .../FrameworkBundle/Tests/Command/CachePruneCommandTest.php | 4 ++-- .../Component/Cache/Tests/Adapter/TagAwareAdapterTest.php | 2 +- .../Component/Serializer/Tests/Encoder/XmlEncoderTest.php | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/AnnotationsCacheWarmerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/AnnotationsCacheWarmerTest.php index 9e353ad7bb..d834acb911 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/AnnotationsCacheWarmerTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/AnnotationsCacheWarmerTest.php @@ -167,7 +167,7 @@ class AnnotationsCacheWarmerTest extends TestCase } /** - * @return MockObject|Reader + * @return MockObject&Reader */ private function getReadOnlyReader() { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CachePoolDeleteCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CachePoolDeleteCommandTest.php index 907d5b9de3..4a32ab9961 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CachePoolDeleteCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CachePoolDeleteCommandTest.php @@ -84,7 +84,7 @@ class CachePoolDeleteCommandTest extends TestCase } /** - * @return MockObject|KernelInterface + * @return MockObject&KernelInterface */ private function getKernel() { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CachePruneCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CachePruneCommandTest.php index 3fe3a48e2f..060c657ec3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CachePruneCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/CachePruneCommandTest.php @@ -51,7 +51,7 @@ class CachePruneCommandTest extends TestCase } /** - * @return MockObject|KernelInterface + * @return MockObject&KernelInterface */ private function getKernel() { @@ -72,7 +72,7 @@ class CachePruneCommandTest extends TestCase } /** - * @return MockObject|PruneableInterface + * @return MockObject&PruneableInterface */ private function getPruneableInterfaceMock() { diff --git a/src/Symfony/Component/Cache/Tests/Adapter/TagAwareAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/TagAwareAdapterTest.php index de7b81149d..4b7c64058c 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/TagAwareAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/TagAwareAdapterTest.php @@ -217,7 +217,7 @@ class TagAwareAdapterTest extends AdapterTestCase } /** - * @return MockObject|PruneableCacheInterface + * @return MockObject&PruneableCacheInterface */ private function getPruneableMock(): AdapterInterface { diff --git a/src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php b/src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php index 8a65982f56..e3b7376d2f 100644 --- a/src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php +++ b/src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php @@ -931,7 +931,7 @@ XML; } /** - * @return MockObject|NormalizerInterface + * @return MockObject&NormalizerInterface */ private function createMockDateTimeNormalizer() {