public function testGetDate() { $server = new Zend_TimeSync($this->timeservers); $result = $server->getDate(); $this->assertTrue($result instanceof Zend_Date); $sntpServer = $server->get(5); $result = $sntpServer->getDate(); $this->assertTrue($result instanceof Zend_Date); $timeservers = array('foo-bar.be', 'foo-bar.be'); $server = new Zend_TimeSync($timeservers); try { $result = $server->getDate(); $this->fail('Exception expected because of invalid timeservers'); } catch (Zend_TimeSync_Exception $e) { // success } }
public function testTimesync() { try { $server = new Zend_TimeSync('ntp://pool.ntp.org', 'alias'); $date1 = $server->getDate(); // need to use the proxy class to simulate time() returning wrong value $date2 = new Zend_Date_TestHelper(time()); $info = $server->getInfo(); if ($info['offset'] >= 0.5 || $info['offset'] <= -0.52) { $this->assertFalse($date1->getTimestamp() == $date2->getTimestamp()); } else { $this->assertEquals($date1->getTimestamp(), $date2->getTimestamp()); } } catch (Zend_TimeSync_Exception $e) { $this->markTestIncomplete('NTP timeserver not available.'); } }
/** * Test getting info returned from the server * * @return void */ public function testGetInfo() { $server = new Zend_TimeSync('time.windows.com'); try { $date = $server->getDate(); $result = $server->getInfo(); $this->assertTrue(count($result) > 0); } catch (Zend_TimeSync_Exception $e) { // nothing } }
public function testTimesync() { // @todo: when the Zend_TimeSync adapter moves out of the incubator, // the following hack to allow it to be loaded should be removed. // see also ZF-954 $incubator = dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'incubator' . DIRECTORY_SEPARATOR . 'library'; $include_path = get_include_path(); set_include_path($include_path . PATH_SEPARATOR . $incubator); try { Zend_Loader::loadClass('Zend_TimeSync'); Zend_Loader::loadClass('Zend_TimeSync_Ntp'); } catch (Zend_Exception $e) { $this->markTestIncomplete($e->getMessage()); } set_include_path($include_path); // @todo: end of hack try { $server = new Zend_TimeSync('ntp://pool.ntp.org', 'alias'); $date1 = $server->getDate(); // need to use the proxy class to simulate time() returning wrong value $date2 = new Zend_Date_TestHelper(time()); $info = $server->getInfo(); if ($info['offset'] != 0) { $this->assertFalse($date1->getTimestamp() == $date2->getTimestamp()); } else { $this->assertSame($date1->getTimestamp(), $date2->getTimestamp()); } } catch (Zend_TimeSync_Exception $e) { $this->markTestIncomplete('NTP timeserver not available.'); } }