5 include __DIR__
."/../../setup.inc";
7 class TickerTest
extends \PHPUnit_Framework_TestCase
{
14 protected function setUp() {
15 $this->ticker
= new Ticker
;
18 public function testRegister() {
19 $this->ticker
->register();
20 $this->ticker
->unregister();
21 $this->ticker
->register();
22 $this->ticker
->unregister();
25 public function testTicks() {
26 $file = fopen(__FILE__
, "r");
27 stream_set_blocking($file, false);
31 $this->ticker
->register();
32 $this->ticker
->read($file, function ($file) use (&$read) {
34 $data = fread($file, 4096);
35 $read +
= strlen($data);
36 } while (strlen($data));
40 $dummy = "This test is do tiny, ";
41 $dummy.= "we don't have to do much.";
43 $this->assertEquals(filesize(__FILE__
), $read);
46 public function testBasic() {
48 $this->assertCount(0, $this->ticker
);
50 $file = fopen(__FILE__
, "r");
51 stream_set_blocking($file, false);
53 $this->ticker
->read($file, function ($file) use (&$r) {
54 fread($file, fstat($file)["size"]);
56 $this->assertCount(1, $this->ticker
);
57 $this->ticker
->write($file, function ($file) use (&$w) {
60 $this->assertCount(2, $this->ticker
);
62 $this->assertSame(2, $this->ticker
->wait());
63 $this->assertSame(0, $this->ticker
->wait());