scratch – Blame information for rev

Subversion Repositories:
Rev:
Rev Author Line No. Line
115 office 1 <?php
2  
3 namespace Alchemy\Tests\BinaryDriver;
4  
5 use Symfony\Component\Process\ExecutableFinder;
6 use Alchemy\BinaryDriver\ProcessBuilderFactory;
7  
8 abstract class AbstractProcessBuilderFactoryTest extends \PHPUnit_Framework_TestCase
9 {
10 public static $phpBinary;
11  
12 private $original;
13 /**
14 * @return ProcessBuilderFactory
15 */
16 abstract protected function getProcessBuilderFactory($binary);
17  
18 public function setUp()
19 {
20 ProcessBuilderFactory::$emulateSfLTS = null;
21 if (null === static::$phpBinary) {
22 $this->markTestSkipped('Unable to detect php binary, skipping');
23 }
24 }
25  
26 public static function setUpBeforeClass()
27 {
28 $finder = new ExecutableFinder();
29 static::$phpBinary = $finder->find('php');
30 }
31  
32 public function testThatBinaryIsSetOnConstruction()
33 {
34 $factory = $this->getProcessBuilderFactory(static::$phpBinary);
35 $this->assertEquals(static::$phpBinary, $factory->getBinary());
36 }
37  
38 public function testGetSetBinary()
39 {
40 $finder = new ExecutableFinder();
41 $phpUnit = $finder->find('phpunit');
42  
43 if (null === $phpUnit) {
44 $this->markTestSkipped('Unable to detect phpunit binary, skipping');
45 }
46  
47 $factory = $this->getProcessBuilderFactory(static::$phpBinary);
48 $factory->useBinary($phpUnit);
49 $this->assertEquals($phpUnit, $factory->getBinary());
50 }
51  
52 /**
53 * @expectedException Alchemy\BinaryDriver\Exception\InvalidArgumentException
54 */
55 public function testUseNonExistantBinary()
56 {
57 $factory = $this->getProcessBuilderFactory(static::$phpBinary);
58 $factory->useBinary('itissureitdoesnotexist');
59 }
60  
61 public function testCreateShouldReturnAProcess()
62 {
63 $factory = $this->getProcessBuilderFactory(static::$phpBinary);
64 $process = $factory->create();
65  
66 $this->assertInstanceOf('Symfony\Component\Process\Process', $process);
67 $this->assertEquals("'".static::$phpBinary."'", $process->getCommandLine());
68 }
69  
70 public function testCreateWithStringArgument()
71 {
72 $factory = $this->getProcessBuilderFactory(static::$phpBinary);
73 $process = $factory->create('-v');
74  
75 $this->assertInstanceOf('Symfony\Component\Process\Process', $process);
76 $this->assertEquals("'".static::$phpBinary."' '-v'", $process->getCommandLine());
77 }
78  
79 public function testCreateWithArrayArgument()
80 {
81 $factory = $this->getProcessBuilderFactory(static::$phpBinary);
82 $process = $factory->create(array('-r', 'echo "Hello !";'));
83  
84 $this->assertInstanceOf('Symfony\Component\Process\Process', $process);
85 $this->assertEquals("'".static::$phpBinary."' '-r' 'echo \"Hello !\";'", $process->getCommandLine());
86 }
87  
88 public function testCreateWithTimeout()
89 {
90 $factory = $this->getProcessBuilderFactory(static::$phpBinary);
91 $factory->setTimeout(200);
92 $process = $factory->create(array('-i'));
93  
94 $this->assertInstanceOf('Symfony\Component\Process\Process', $process);
95 $this->assertEquals(200, $process->getTimeout());
96 }
97 }