コード例 #1
0
ファイル: UserTest.php プロジェクト: cargomedia/cm
 public function testOnSubscribe()
 {
     $user = CMTest_TH::createUser();
     /** @var CM_Model_StreamChannel_Message_User $channel */
     $channel = CM_Model_StreamChannel_Message_User::createStatic(['key' => CM_Model_StreamChannel_Message_User::getKeyByUser($user), 'adapterType' => CM_MessageStream_Adapter_SocketRedis::getTypeStatic()]);
     $this->assertSame(false, $user->getOnline());
     $subscribe = CMTest_TH::createStreamSubscribe($user, $channel);
     CMTest_TH::reinstantiateModel($user);
     $this->assertSame(true, $user->getOnline());
 }
コード例 #2
0
ファイル: OfflineJobTest.php プロジェクト: cargomedia/cm
 public function testExecute()
 {
     $user = CMTest_TH::createUser();
     $user->setOnline();
     $userChannel = CM_Model_StreamChannel_Message_User::createStatic(['key' => CM_Model_StreamChannel_Message_User::getKeyByUser($user), 'adapterType' => CM_MessageStream_Adapter_SocketRedis::getTypeStatic()]);
     $job = new CM_User_OfflineJob();
     $this->assertSame(true, $user->getOnline());
     $job->run(['user' => $user]);
     CMTest_TH::reinstantiateModel($user);
     $this->assertSame(true, $user->getOnline());
     $userChannel->delete();
     $job->run(['user' => $user]);
     CMTest_TH::reinstantiateModel($user);
     $this->assertSame(false, $user->getOnline());
 }
コード例 #3
0
ファイル: SocketRedisTest.php プロジェクト: cargomedia/cm
 public function testOnRedisMessageUnsubscribe()
 {
     $adapter = new CM_MessageStream_Adapter_SocketRedis([]);
     $streamChannel = CM_Model_StreamChannel_Message::createStatic(array('key' => 'foo', 'adapterType' => $adapter->getType()));
     CM_Model_Stream_Subscribe::createStatic(array('key' => 'foo', 'streamChannel' => $streamChannel, 'start' => time()));
     CM_Model_Stream_Subscribe::createStatic(array('key' => 'bar', 'streamChannel' => $streamChannel, 'start' => time()));
     $message = array('type' => 'unsubscribe', 'data' => array('channel' => 'foo:' . CM_Model_StreamChannel_Message::getTypeStatic(), 'clientKey' => 'foo'));
     $adapter->onRedisMessage(json_encode($message));
     $streamChannel = CM_Model_StreamChannel_Message::findByKeyAndAdapter('foo', $adapter->getType());
     $this->assertNotNull($streamChannel);
     $streamSubscribe = CM_Model_Stream_Subscribe::findByKeyAndChannel('foo', $streamChannel);
     $this->assertNull($streamSubscribe);
     $message = array('type' => 'unsubscribe', 'data' => array('channel' => 'foo:' . CM_Model_StreamChannel_Message::getTypeStatic(), 'clientKey' => 'bar'));
     $adapter->onRedisMessage(json_encode($message));
     $streamChannel = CM_Model_StreamChannel_Message::findByKeyAndAdapter('foo', $adapter->getType());
     $this->assertNull($streamChannel);
 }
コード例 #4
0
ファイル: AbstractTest.php プロジェクト: NicolasSchmutz/cm
 public function testIsSubscriberOrPublisher()
 {
     /** @var CM_Model_StreamChannel_Mock $streamChannel */
     $streamChannel = CM_Model_StreamChannel_Mock::createStatic(array('key' => 'foo', 'adapterType' => CM_MessageStream_Adapter_SocketRedis::getTypeStatic()));
     $user1 = CMTest_TH::createUser();
     $publish1 = CM_Model_Stream_Publish::createStatic(array('streamChannel' => $streamChannel, 'user' => $user1, 'start' => 123123, 'key' => '1'));
     $subscribe1 = CM_Model_Stream_Subscribe::createStatic(array('streamChannel' => $streamChannel, 'user' => $user1, 'start' => 123123, 'key' => '2'));
     $this->assertTrue($streamChannel->isSubscriberOrPublisher($user1));
     $this->assertTrue($streamChannel->isSubscriberOrPublisher($user1, $publish1));
     $subscribe1->delete();
     $this->assertTrue($streamChannel->isSubscriberOrPublisher($user1));
     $this->assertFalse($streamChannel->isSubscriberOrPublisher($user1, $publish1));
     $publish1->delete();
     $this->assertFalse($streamChannel->isSubscriberOrPublisher($user1));
 }