Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
"react/event-loop": "~0.4.0|~0.3.0",
"react/child-process": "~0.4.0|~0.3.0"
},
"require-dev": {
"clue/block-react": "^1.1"
},
"autoload": {
"psr-4": { "Clue\\React\\Zenity\\": "src/" }
}
Expand Down
6 changes: 6 additions & 0 deletions src/Zen/BaseZen.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,16 @@ public function promise()

public function close()
{
// resolve with whatever is currently buffered
$this->deferred->resolve();

if ($this->process !== null && $this->process->isRunning()) {
$this->process->terminate(SIGKILL);

// explicitly close all streams immediately
$this->process->stdin->close();
$this->process->stdout->close();
$this->process->stderr->close();
}

return $this;
Expand Down
13 changes: 7 additions & 6 deletions tests/FunctionalLauncherTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

use Clue\React\Block;
use Clue\React\Zenity\Launcher;
use React\EventLoop\Factory;
use Clue\React\Zenity\Zen\BaseZen;
use React\EventLoop\Factory;

class LauncherTest extends TestCase
class FunctionalLauncherTest extends TestCase
{
private $loop;
private $dialog;
Expand All @@ -27,9 +28,9 @@ public function testEchoParameters()

$promise = $this->launcher->launch($this->dialog);

$this->loop->run();
$result = Block\await($promise, $this->loop, 1.0);

$promise->then($this->expectCallableOnceWith('--hello --world'));
$this->assertEquals('--hello --world', $result);
}

public function testDoesPassStdin()
Expand All @@ -44,9 +45,9 @@ public function testDoesPassStdin()
$zen->close();
});

$this->loop->run();
$result = Block\await($zen->promise(), $this->loop, 1.0);

$zen->promise()->then($this->expectCallableOnceWith('okay'));
$this->assertEquals('okay', $result);
}

public function testWaitForOutput()
Expand Down
1 change: 1 addition & 0 deletions tests/Zen/BaseZenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function setUp()
$this->process->stdin = $this->instream;

$this->process->stdout = $this->getMock('React\Stream\ReadableStreamInterface');
$this->process->stderr = $this->getMock('React\Stream\ReadableStreamInterface');
}

public function testClosingZenTerminatesProcess()
Expand Down
25 changes: 12 additions & 13 deletions tests/Zen/FunctionalBaseZenTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

use Clue\React\Block;
use Clue\React\Zenity\Zen\BaseZen;
use React\EventLoop\Factory;
use React\ChildProcess\Process;
use Clue\React\Zenity\Zen\BaseZen;

class FunctionalBaseZenTest extends TestCase
{
public function setUp()
Expand All @@ -18,9 +20,9 @@ public function testZenResolvesWithProcessOutput()
$zen = new BaseZen();
$zen->go($process);

$this->loop->run();
$result = Block\await($zen->promise(), $this->loop, 1.0);

$zen->promise()->then($this->expectCallableOnceWith('okay'));
$this->assertEquals('okay', $result);
}

public function testZenResolvesWithTrueWhenProcessHasNoOutput()
Expand All @@ -31,9 +33,9 @@ public function testZenResolvesWithTrueWhenProcessHasNoOutput()
$zen = new BaseZen();
$zen->go($process);

$this->loop->run();
$result = Block\await($zen->promise(), $this->loop, 1.0);

$zen->promise()->then($this->expectCallableOnceWith(true));
$this->assertTrue($result);
}

public function testZenRejectsWhenProcessReturnsError()
Expand All @@ -44,9 +46,7 @@ public function testZenRejectsWhenProcessReturnsError()
$zen = new BaseZen();
$zen->go($process);

$this->loop->run();

$zen->promise()->then(null, $this->expectCallableOnceWith(1));
Block\await($zen->promise()->then(null, $this->expectCallableOnceWith(1)), $this->loop, 1.0);
}

public function testClosingZenResolvesWithOutputSoFar()
Expand All @@ -61,9 +61,9 @@ public function testClosingZenResolvesWithOutputSoFar()
$zen->close();
});

$this->loop->run();
$result = Block\await($zen->promise(), $this->loop, 1.0);

$zen->promise()->then($this->expectCallableOnceWith('okay'));
$this->assertEquals('okay', $result);
}

public function testTerminatingProcessReturnsError()
Expand All @@ -76,10 +76,9 @@ public function testTerminatingProcessReturnsError()

$this->loop->addTimer(0.1, function() use ($process) {
$process->terminate(SIGKILL);
$process->stdin->end();
});

$this->loop->run();

$zen->promise()->then(null, $this->expectCallableOnce());
Block\await($zen->promise()->then(null, $this->expectCallableOnce()), $this->loop, 1.0);
}
}