public function test_methods() { $this->assertTrue(Network::is_port_open('localhost', 4440)); $pid = Phantomjs::start('echo.js', 4440); $this->assertTrue(Attempt::make(function () { return !Network::is_port_open('localhost', 4440); }), 'Should be running after some attempts'); try { Phantomjs::start('echo.js', 4440); $this->fail('Should rise an exception'); } catch (Exception $e) { // Pass } Phantomjs::kill($pid); $this->assertTrue(Attempt::make(function () { return Network::is_port_open('localhost', 4440); }), 'Should not be running after some attempts'); }
public function test_start_and_stop() { $this->assertFalse($this->connection->is_running()); file_put_contents(TESTVIEWS . 'test.pid', Phantomjs::start('echo.js', 4441)); Attempt::make(function () { return !Network::is_port_open('localhost', 4441); }); $start_result = $this->connection->port(6000)->start(TESTVIEWS . 'test.pid'); $this->assertTrue(Attempt::make(function () { return Network::is_port_open('localhost', 4441); }), 'Should remove old running phantomjs from the pid file'); $this->assertFileExists(TESTVIEWS . 'test.pid'); $this->assertEquals(TESTVIEWS . 'test.pid', $this->connection->pid_file()); $this->assertEquals($this->connection->pid(), file_get_contents($this->connection->pid_file())); $this->assertTrue($start_result); $this->assertTrue($this->connection->is_running()); $stop_result = $this->connection->stop(); $this->assertTrue($stop_result); $this->assertFileNotExists(TESTVIEWS . 'test.pid'); $this->assertFalse($this->connection->is_running()); }