ProcessBuilderTest.php 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /*
  3. * This file is part of the Assetic package, an OpenSky project.
  4. *
  5. * (c) 2010-2011 OpenSky Project Inc
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Assetic\Test\Util;
  11. use Assetic\Util\ProcessBuilder;
  12. class ProcessBuilderTest extends \PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * @test
  16. */
  17. public function shouldInheritEnvironmentVars()
  18. {
  19. $snapshot = $_ENV;
  20. $_ENV = $expected = array('foo' => 'bar');
  21. $pb = new ProcessBuilder();
  22. $pb->add('foo')->inheritEnvironmentVariables();
  23. $proc = $pb->getProcess();
  24. $this->assertEquals($expected, $proc->getEnv(), '->inheritEnvironmentVariables() copies $_ENV');
  25. $_ENV = $snapshot;
  26. }
  27. /**
  28. * @test
  29. */
  30. public function shouldNotReplaceExplicitlySetVars()
  31. {
  32. $snapshot = $_ENV;
  33. $_ENV = array('foo' => 'bar');
  34. $expected = array('foo' => 'baz');
  35. $pb = new ProcessBuilder();
  36. $pb
  37. ->setEnv('foo', 'baz')
  38. ->inheritEnvironmentVariables()
  39. ->add('foo')
  40. ;
  41. $proc = $pb->getProcess();
  42. $this->assertEquals($expected, $proc->getEnv(), '->inheritEnvironmentVariables() copies $_ENV');
  43. $_ENV = $snapshot;
  44. }
  45. }