Skip to content

Commit 00883fc

Browse files
committed
Make tests independent from each other
Environment variables set in a test need to be restored to their previous values or unset if we want to be able to run tests independently.
1 parent c82e2df commit 00883fc

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ class ApplicationTest extends TestCase
4141
{
4242
protected static $fixturesPath;
4343

44+
private $colSize;
45+
46+
protected function setUp()
47+
{
48+
$this->colSize = getenv('COLUMNS');
49+
}
50+
4451
public static function setUpBeforeClass()
4552
{
4653
self::$fixturesPath = realpath(__DIR__.'/Fixtures/');
@@ -383,6 +390,7 @@ public function testFindWithCommandLoader()
383390
*/
384391
public function testFindWithAmbiguousAbbreviations($abbreviation, $expectedExceptionMessage)
385392
{
393+
putenv('COLUMNS=120');
386394
if (method_exists($this, 'expectException')) {
387395
$this->expectException('Symfony\Component\Console\Exception\CommandNotFoundException');
388396
$this->expectExceptionMessage($expectedExceptionMessage);
@@ -468,6 +476,7 @@ public function provideInvalidCommandNamesSingle()
468476

469477
public function testFindAlternativeExceptionMessageMultiple()
470478
{
479+
putenv('COLUMNS=120');
471480
$application = new Application();
472481
$application->add(new \FooCommand());
473482
$application->add(new \Foo1Command());
@@ -1692,6 +1701,7 @@ public function testErrorIsRethrownIfNotHandledByConsoleErrorEventWithCatchingEn
16921701

16931702
protected function tearDown()
16941703
{
1704+
putenv($this->colSize ? 'COLUMNS' : 'COLUMNS='.$this->colSize);
16951705
putenv('SHELL_VERBOSITY');
16961706
unset($_ENV['SHELL_VERBOSITY']);
16971707
unset($_SERVER['SHELL_VERBOSITY']);

src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@
2121
*/
2222
class ProgressBarTest extends TestCase
2323
{
24+
private $colSize;
25+
26+
protected function setUp()
27+
{
28+
$this->colSize = getenv('COLUMNS');
29+
putenv('COLUMNS=120');
30+
}
31+
32+
protected function tearDown()
33+
{
34+
putenv($this->colSize ? 'COLUMNS' : 'COLUMNS='.$this->colSize);
35+
}
36+
2437
public function testMultipleStart()
2538
{
2639
$bar = new ProgressBar($output = $this->getOutputStream());

src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,19 @@ class SymfonyStyleTest extends TestCase
2626
protected $command;
2727
/** @var CommandTester */
2828
protected $tester;
29+
private $colSize;
2930

3031
protected function setUp()
3132
{
33+
$this->colSize = getenv('COLUMNS');
3234
putenv('COLUMNS=121');
3335
$this->command = new Command('sfstyle');
3436
$this->tester = new CommandTester($this->command);
3537
}
3638

3739
protected function tearDown()
3840
{
39-
putenv('COLUMNS');
41+
putenv($this->colSize ? 'COLUMNS' : 'COLUMNS='.$this->colSize);
4042
$this->command = null;
4143
$this->tester = null;
4244
}

src/Symfony/Component/Console/Tests/TerminalTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@
1616

1717
class TerminalTest extends TestCase
1818
{
19+
private $colSize;
20+
private $lineSize;
21+
22+
protected function setUp()
23+
{
24+
$this->colSize = getenv('COLUMNS');
25+
$this->lineSize = getenv('LINES');
26+
}
27+
1928
public function test()
2029
{
2130
putenv('COLUMNS=100');
@@ -31,6 +40,12 @@ public function test()
3140
$this->assertSame(60, $terminal->getHeight());
3241
}
3342

43+
protected function tearDown()
44+
{
45+
putenv($this->colSize ? 'COLUMNS' : 'COLUMNS='.$this->colSize);
46+
putenv($this->lineSize ? 'LINES' : 'LINES='.$this->lineSize);
47+
}
48+
3449
public function test_zero_values()
3550
{
3651
putenv('COLUMNS=0');

0 commit comments

Comments
 (0)