8000 [Console][TableStyle] validate padding type value. · symfony/symfony@755653d · GitHub
[go: up one dir, main page]

Skip to content

Commit 755653d

Browse files
aitboudadfabpot
authored andcommitted
[Console][TableStyle] validate padding type value.
1 parent d7870a2 commit 755653d

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/Symfony/Component/Console/Helper/TableStyle.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ public function getBorderFormat()
234234
*/
235235
public function setPadType($padType)
236236
{
237+
if (!in_array($padType, array(STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH), true)) {
238+
throw new \InvalidArgumentException('Invalid padding type. Expected one of (STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH).');
239+
}
240+
237241
$this->padType = $padType;
238242

239243
return $this;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Console\Tests\Helper;
13+
14+
use Symfony\Component\Console\Helper\TableStyle;
15+
16+
class TableStyleTest extends \PHPUnit_Framework_TestCase
17+
{
18+
/**
19+
* @expectedException \InvalidArgumentException
20+
* @expectedExceptionMessage Invalid padding type. Expected one of (STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH).
21+
*/
22+
public function testSetPadTypeWithInvalidType()
23+
{
24+
$style = new TableStyle();
25+
$style->setPadType('TEST');
26+
}
27+
}

0 commit comments

Comments
 (0)
0