本文整理汇总了PHP中CMTest_TH::timeForward方法的典型用法代码示例。如果您正苦于以下问题:PHP CMTest_TH::timeForward方法的具体用法?PHP CMTest_TH::timeForward怎么用?PHP CMTest_TH::timeForward使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CMTest_TH
的用法示例。
在下文中一共展示了CMTest_TH::timeForward方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testOnRedisMessageSubscribe
public function testOnRedisMessageSubscribe()
{
$adapter = new CM_MessageStream_Adapter_SocketRedis([]);
$message = array('type' => 'subscribe', 'data' => array('channel' => 'foo:' . CM_Model_StreamChannel_Message::getTypeStatic(), 'clientKey' => 'bar', 'data' => array()));
$adapter->onRedisMessage(json_encode($message));
$timeStarted = time();
$streamChannel = CM_Model_StreamChannel_Message::findByKeyAndAdapter('foo', $adapter->getType());
$this->assertNotNull($streamChannel);
$streamChannels = new CM_Paging_StreamChannel_AdapterType($adapter->getType());
$this->assertSame(1, $streamChannels->getCount());
$streamSubscribe = CM_Model_Stream_Subscribe::findByKeyAndChannel('bar', $streamChannel);
$this->assertNotNull($streamSubscribe);
$this->assertSame(1, $streamChannel->getStreamSubscribes()->getCount());
$this->assertSameTime($timeStarted, $streamSubscribe->getStart());
$this->assertSameTime($streamChannel->canSubscribe(null, time()), $streamSubscribe->getAllowedUntil());
$this->assertNull($streamSubscribe->getUser());
CMTest_TH::timeForward(CM_MessageStream_Adapter_SocketRedis::SYNCHRONIZE_DELAY);
$adapter->onRedisMessage(json_encode($message));
$streamChannels = new CM_Paging_StreamChannel_AdapterType($adapter->getType());
$this->assertSame(1, $streamChannels->getCount());
$this->assertSame(1, $streamChannel->getStreamSubscribes()->getCount());
CMTest_TH::reinstantiateModel($streamSubscribe);
$this->assertSameTime($timeStarted, $streamSubscribe->getStart());
$this->assertSameTime($streamChannel->canSubscribe(null, $timeStarted), $streamSubscribe->getAllowedUntil());
}
示例2: testCheckStreams
public function testCheckStreams()
{
$mockAdapter = $this->getMockForAbstractClass('CM_Stream_Adapter_Video_Abstract', array(), 'CM_Stream_Adapter_Video_Mock', true, true, true, array('_stopStream', 'getType'));
$mockAdapter->expects($this->exactly(2))->method('_stopStream')->will($this->returnValue(1));
$mockAdapter->expects($this->any())->method('getType')->will($this->returnValue(1));
CM_Config::get()->CM_Model_StreamChannel_Abstract->types[CM_Model_StreamChannel_Video_Mock::getTypeStatic()] = 'CM_Model_StreamChannel_Video_Mock';
$wowza = $wowza = $this->getMock('CM_Stream_Video', array('getAdapter'));
$wowza->expects($this->any())->method('getAdapter')->will($this->returnValue($mockAdapter));
/** @var $wowza CM_Stream_Video */
// allowedUntil will be updated, if stream has expired and its user isn't $userUnchanged, hardcoded in CM_Model_StreamChannel_Video_Mock::canSubscribe() using getOnline()
$userUnchanged = CMTest_TH::createUser();
$userUnchanged->setOnline();
$streamChannel = CM_Model_StreamChannel_Video_Mock::createStatic(array('key' => 'foo1', 'serverId' => 1, 'adapterType' => 1, 'width' => 100, 'height' => 100, 'thumbnailCount' => 0));
$streamSubscribeUnchanged1 = CM_Model_Stream_Subscribe::createStatic(array('streamChannel' => $streamChannel, 'user' => $userUnchanged, 'key' => 'foo1_2', 'start' => time()));
$streamSubscribeUnchanged2 = CM_Model_Stream_Subscribe::createStatic(array('streamChannel' => $streamChannel, 'user' => CMTest_TH::createUser(), 'key' => 'foo1_4', 'start' => time()));
$streamSubscribeChanged1 = CM_Model_Stream_Subscribe::createStatic(array('streamChannel' => $streamChannel, 'user' => CMTest_TH::createUser(), 'key' => 'foo1_3', 'start' => time()));
$streamPublishUnchanged1 = CM_Model_Stream_Publish::createStatic(array('streamChannel' => $streamChannel, 'user' => $userUnchanged, 'key' => 'foo1_2', 'start' => time()));
$streamPublishChanged1 = CM_Model_Stream_Publish::createStatic(array('streamChannel' => CM_Model_StreamChannel_Video_Mock::createStatic(array('key' => 'foo2', 'serverId' => 1, 'adapterType' => 1, 'width' => 100, 'height' => 100, 'thumbnailCount' => 0)), 'user' => CMTest_TH::createUser(), 'key' => 'foo2_1', 'start' => time()));
$this->assertSameTime($streamSubscribeUnchanged1->getAllowedUntil(), time() + 10);
$this->assertSameTime($streamSubscribeUnchanged2->getAllowedUntil(), time() + 100);
$this->assertSameTime($streamSubscribeChanged1->getAllowedUntil(), time() + 100);
$this->assertSameTime($streamPublishUnchanged1->getAllowedUntil(), time() + 10);
$this->assertSameTime($streamPublishChanged1->getAllowedUntil(), time() + 100);
CMTest_TH::timeForward(200);
$wowza->checkStreams();
$this->assertEquals($streamSubscribeUnchanged1->getAllowedUntil() + 10, $streamSubscribeUnchanged1->_change()->getAllowedUntil());
$this->assertEquals($streamSubscribeUnchanged2->getAllowedUntil() + 100, $streamSubscribeUnchanged2->_change()->getAllowedUntil());
$this->assertEquals($streamSubscribeChanged1->getAllowedUntil() + 100, $streamSubscribeChanged1->_change()->getAllowedUntil());
$this->assertEquals($streamPublishUnchanged1->getAllowedUntil() + 10, $streamPublishUnchanged1->_change()->getAllowedUntil());
$this->assertEquals($streamPublishChanged1->getAllowedUntil() + 100, $streamPublishChanged1->_change()->getAllowedUntil());
}
示例3: testClean
public function testClean()
{
$user1 = CMTest_TH::createUser();
$user2 = CMTest_TH::createUser();
$user1->getRoles()->add(self::ROLE_A, 2000);
$user1->getRoles()->add(self::ROLE_C);
$user1->getRoles()->add(self::ROLE_B, 1000);
$user2->getRoles()->add(self::ROLE_A, 2000);
$user2->getRoles()->add(self::ROLE_B, 1000);
$this->assertTrue($user1->getRoles()->contains(self::ROLE_B));
CMTest_TH::timeForward(1500);
CM_ModelAsset_User_Roles::deleteOld($user1);
$user1->_change();
$user2->_change();
$this->assertFalse($user1->getRoles()->contains(self::ROLE_B));
$this->assertRow('cm_role', array('userId' => $user2->getId(), 'role' => self::ROLE_B));
$this->assertFalse($user2->getRoles()->contains(self::ROLE_B));
$this->assertTrue($user2->getRoles()->contains(self::ROLE_A));
CM_ModelAsset_User_Roles::deleteOld();
$user1->_change();
$user2->_change();
$this->assertNotRow('cm_role', array('userId' => $user2->getId(), 'role' => self::ROLE_B));
$this->assertTrue($user2->getRoles()->contains(self::ROLE_A));
$this->assertTrue($user1->getRoles()->contains(self::ROLE_A));
$this->assertTrue($user1->getRoles()->contains(self::ROLE_C));
}
示例4: testCleanUp
public function testCleanUp()
{
$client = $this->getServiceManager()->getMongoDb();
$encoder = new CM_Log_Encoder_MongoDb();
$handler = new CM_Log_Handler_MongoDb($client, $encoder, CM_Paging_Log::COLLECTION_NAME);
$context1 = new CM_Log_Context();
$context1->setExtra(['bar' => 'quux']);
$record1 = new CM_Log_Record(CM_Log_Logger::DEBUG, 'foo', $context1);
$record2 = new CM_Log_Record(CM_Log_Logger::DEBUG, 'baz', new CM_Log_Context());
$record3 = new CM_Log_Record(CM_Log_Logger::CRITICAL, 'bar', new CM_Log_Context());
$record4 = new CM_Log_Record(CM_Log_Logger::INFO, 'bazBar', new CM_Log_Context());
$contextTyped = new CM_Log_Context();
$contextTyped->setExtra(['type' => 1]);
$typedRecord = new CM_Log_Record(CM_Log_Logger::DEBUG, 'quux', $contextTyped);
$paging = new CM_Paging_Log([CM_Log_Logger::DEBUG, CM_Log_Logger::INFO]);
$this->assertSame(0, $paging->getCount());
$handler->handleRecord($record1);
$handler->handleRecord($record2);
$handler->handleRecord($record3);
$handler->handleRecord($record4);
$handler->handleRecord($typedRecord);
$paging->_change();
$this->assertSame(4, $paging->getCount());
$age = 7 * 86400 + 1;
CMTest_TH::timeForward($age);
$paging->cleanUp();
$this->assertSame(0, $paging->getCount());
}
示例5: testDeleteOlder
public function testDeleteOlder()
{
$file = CM_File_UserContent_Temp::create('foo.txt', 'bar');
$this->assertTrue($file->exists());
CM_File_UserContent_Temp::deleteOlder(100);
$this->assertTrue($file->exists());
CMTest_TH::timeForward(1000);
CM_File_UserContent_Temp::deleteOlder(100);
$this->assertFalse($file->exists());
}
示例6: testDeleteExpired
public function testDeleteExpired()
{
CMTest_TH::timeInit();
$runtime = new CM_Cache_Storage_Runtime();
$runtime->set('foo', true);
$this->assertTrue($runtime->get('foo'));
CMTest_TH::timeForward(5);
$runtime->set('bar', true);
$this->assertFalse($runtime->get('foo'));
}
示例7: testDeleteOlder
public function testDeleteOlder()
{
$captcha = CM_Captcha::create();
$id = $captcha->getId();
CMTest_TH::timeForward(200);
CM_Captcha::deleteOlder(100);
try {
new CM_Captcha($id);
$this->fail('Can construct old captcha');
} catch (CM_Exception_Nonexistent $e) {
$this->assertTrue(true);
}
}
示例8: testPaging
public function testPaging()
{
$key = 'foo';
$streamChannel1 = CMTest_TH::createStreamChannel();
$streamChannel1->_set('key', $key);
$streamChannel2 = CMTest_TH::createStreamChannel();
$streamChannel2->_set('key', $key);
$this->assertEquals([], new CM_Paging_StreamChannelArchiveMedia_Key($key));
$streamChannelArchive1 = CMTest_TH::createStreamChannelVideoArchive($streamChannel1);
CMTest_TH::timeForward(1);
$streamChannelArchive2 = CMTest_TH::createStreamChannelVideoArchive($streamChannel2);
$this->assertEquals([$streamChannelArchive1, $streamChannelArchive2], new CM_Paging_StreamChannelArchiveMedia_Key($key));
}
示例9: testPaging
public function testPaging()
{
$user = CMTest_TH::createUser();
CMTest_TH::createStreamChannelVideoArchive(null, $user);
CMTest_TH::createStreamChannelVideoArchive(null, $user);
CMTest_TH::timeForward(1);
$streamChannel3 = CMTest_TH::createStreamChannelVideoArchive(null, $user);
CMTest_TH::createStreamChannelVideoArchive();
CMTest_TH::createStreamChannelVideoArchive();
$paging = new CM_Paging_StreamChannelArchiveVideo_User($user);
$this->assertSame(3, $paging->getCount());
$this->assertEquals($streamChannel3, $paging->getItem(0));
}
示例10: testReconnectTimeout
public function testReconnectTimeout()
{
$config = CM_Service_Manager::getInstance()->getDatabases()->getMaster()->getConfig();
$config['reconnectTimeout'] = 5;
$client = new CM_Db_Client($config);
$client->connect();
$firstTime = $client->getLastConnect();
$timeForward = 100;
CMTest_TH::timeForward($timeForward);
$client->createStatement('SELECT 1')->execute();
$this->assertSameTime($firstTime + $timeForward, $client->getLastConnect(), 5);
CMTest_TH::timeForward($timeForward);
$client->createStatement('SELECT 1')->execute();
$this->assertSameTime($firstTime + 2 * $timeForward, $client->getLastConnect(), 5);
}
示例11: testAdd
public function testAdd()
{
$user = CMTest_TH::createUser();
$useragentList = new CM_Paging_Useragent_User($user);
$time = time();
$this->assertSame([], (new CM_Paging_Useragent_User($user))->getItems());
$useragentList->add('Mozilla');
$this->assertSame([['useragent' => 'Mozilla', 'createStamp' => $time]], (new CM_Paging_Useragent_User($user))->getItems());
CMTest_TH::timeForward(1);
$useragentList->add('Internet Explorer');
$this->assertSame([['useragent' => 'Internet Explorer', 'createStamp' => $time + 1], ['useragent' => 'Mozilla', 'createStamp' => $time]], (new CM_Paging_Useragent_User($user))->getItems());
CMTest_TH::timeForward(1);
$useragentList->add('Mozilla');
$this->assertSame([['useragent' => 'Mozilla', 'createStamp' => $time + 2], ['useragent' => 'Internet Explorer', 'createStamp' => $time + 1]], (new CM_Paging_Useragent_User($user))->getItems());
}
示例12: testCleanUp
public function testCleanUp()
{
$paging = $this->getMockBuilder('CM_Paging_Log_Abstract')->disableOriginalConstructor()->setMethods(array('getType'))->getMockForAbstractClass();
$paging->expects($this->any())->method('getType')->will($this->returnValue(1));
/** @var CM_Paging_Log_Abstract $paging */
$paging->__construct();
$this->assertSame(0, $paging->getCount());
CMTest_TH::getProtectedMethod($paging, '_add')->invoke($paging, 'foo');
$paging->_change();
$this->assertSame(1, $paging->getCount());
$age = 7 * 86400;
CMTest_TH::timeForward($age);
$paging->cleanUp();
$this->assertSame(0, $paging->getCount());
}
示例13: testPaging
public function testPaging()
{
CMTest_TH::createStreamChannelVideoArchive();
$archive = CMTest_TH::createStreamChannelVideoArchive();
CMTest_TH::timeForward(30);
CMTest_TH::createStreamChannelVideoArchive();
/** @var CM_Model_StreamChannel_Video $streamChannel */
$streamChannel = CMTest_TH::createStreamChannel();
$streamChannel = $this->getMock('CM_Model_StreamChannel_Video', array('getType'), array($streamChannel->getId()));
$streamChannel->expects($this->any())->method('getType')->will($this->returnValue(3));
CMTest_TH::createStreamChannelVideoArchive($streamChannel);
$paging = new CM_Paging_StreamChannelArchiveVideo_Type(CM_Model_StreamChannel_Video::getTypeStatic());
$this->assertSame(3, $paging->getCount());
$paging = new CM_Paging_StreamChannelArchiveVideo_Type($streamChannel->getType());
$this->assertSame(1, $paging->getCount());
$paging = new CM_Paging_StreamChannelArchiveVideo_Type(CM_Model_StreamChannel_Video::getTypeStatic(), $archive->getCreated());
$this->assertSame(2, $paging->getCount());
}
示例14: testFlushVariationCache
public function testFlushVariationCache()
{
$test = CM_Model_Splittest::create('foo', ['v1', 'v2']);
$variation1 = new CM_Model_SplittestVariation(CM_Db_Db::select('cm_splittestVariation', 'id', ['name' => 'v1'])->fetchColumn());
$variation2 = new CM_Model_SplittestVariation(CM_Db_Db::select('cm_splittestVariation', 'id', ['name' => 'v2'])->fetchColumn());
$variation2->setEnabled(false);
$fixture = $this->mockClass('CM_Splittest_Fixture')->newInstanceWithoutConstructor();
$fixture->mockMethod('getId')->set(1);
$fixture->mockMethod('getFixtureType')->set(1);
CMTest_TH::timeForward(1);
$variation = CMTest_TH::callProtectedMethod($test, '_getVariationFixture', [$fixture]);
$this->assertSame('v1', $variation);
$test->flush();
$variation2->setEnabled(true);
$variation1->setEnabled(false);
$variation = CMTest_TH::callProtectedMethod($test, '_getVariationFixture', [$fixture]);
$this->assertSame('v2', $variation);
}
示例15: testSynchronizeMissingInWowza
public function testSynchronizeMissingInWowza()
{
$streamChannel = CMTest_TH::createStreamChannel();
$streamPublish = CMTest_TH::createStreamPublish(null, $streamChannel);
$streamSubscribe = CMTest_TH::createStreamSubscribe(null, $streamChannel);
$wowza = $this->getMock('CM_Stream_Adapter_Video_Wowza', array('_fetchStatus'));
$json = $this->_generateWowzaData(array());
$wowza->expects($this->any())->method('_fetchStatus')->will($this->returnValue($json));
/** @var $wowza CM_Stream_Video */
$wowza->synchronize();
$this->assertEquals($streamChannel, CM_Model_StreamChannel_Abstract::findByKeyAndAdapter($streamChannel->getKey(), $wowza->getType()));
$this->assertEquals($streamPublish, CM_Model_Stream_Publish::findByKeyAndChannel($streamPublish->getKey(), $streamChannel));
$this->assertEquals($streamSubscribe, CM_Model_Stream_Subscribe::findByKeyAndChannel($streamSubscribe->getKey(), $streamChannel));
CMTest_TH::timeForward(5);
$wowza->synchronize();
$this->assertNull(CM_Model_StreamChannel_Abstract::findByKeyAndAdapter($streamChannel->getKey(), $wowza->getType()));
$this->assertNull(CM_Model_Stream_Publish::findByKeyAndChannel($streamPublish->getKey(), $streamChannel));
$this->assertNull(CM_Model_Stream_Subscribe::findByKeyAndChannel($streamSubscribe->getKey(), $streamChannel));
}