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()); }
public function testPaging() { $user = CMTest_TH::createUser(); $streamChannel = CMTest_TH::createStreamChannel(); CMTest_TH::createStreamSubscribe($user, $streamChannel); $streams = new CM_Paging_StreamSubscribe_User($user); $this->assertEquals(1, $streams->getCount()); $user->delete(); $streams = new CM_Paging_StreamSubscribe_User($user); $this->assertEquals(0, $streams->getCount()); }
public function testPaging() { $usersExpected = array(CMTest_TH::createUser(), CMTest_TH::createUser(), CMTest_TH::createUser()); $streamChannel = CMTest_TH::createStreamChannel(); foreach ($usersExpected as $user) { CMTest_TH::createStreamSubscribe($user, $streamChannel); } CMTest_TH::createStreamSubscribe(null, $streamChannel); CMTest_TH::createStreamSubscribe(null, $streamChannel); $usersActual = new CM_Paging_User_StreamChannelSubscriber($streamChannel); $this->assertEquals(3, $usersActual->getCount()); foreach ($usersExpected as $user) { $this->assertContains($user, $usersActual); } }
public function testSynchronizeMissingInPhp() { /** @var CM_Model_StreamChannel_Video $streamChannel */ $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('_stopClient', '_fetchStatus')); $json = $this->_generateWowzaData(array($streamChannel)); $wowza->expects($this->any())->method('_fetchStatus')->will($this->returnValue($json)); $wowza->expects($this->at(1))->method('_stopClient')->with($streamPublish->getKey(), $streamChannel->getPrivateHost()); $wowza->expects($this->at(2))->method('_stopClient')->with($streamSubscribe->getKey(), $streamChannel->getPrivateHost()); $wowza->expects($this->exactly(2))->method('_stopClient'); /** @var $wowza CM_Stream_Adapter_Video_Wowza */ $wowza->unpublish($streamChannel->getKey()); $wowza->unsubscribe($streamChannel->getKey(), $streamSubscribe->getKey()); $wowza->synchronize(); }
public function testGetChannel() { $streamChannel = CMTest_TH::createStreamChannel(); $streamPublish = CMTest_TH::createStreamSubscribe(CMTest_TH::createUser(), $streamChannel); $this->assertEquals($streamChannel, $streamPublish->getStreamChannel()); }
public function testSynchronizeMissingInPhp() { $streamChannel = CMTest_TH::createStreamChannel(null, CM_Janus_Service::getTypeStatic()); $streamChannelKey = $streamChannel->getKey(); $streamPublish = CMTest_TH::createStreamPublish(null, $streamChannel); $streamPublishKey = $streamPublish->getKey(); $streamSubscribe = CMTest_TH::createStreamSubscribe(null, $streamChannel); $streamSubscribeKey = $streamSubscribe->getKey(); $streamChannel2 = CMTest_TH::createStreamChannel(null, CM_Janus_Service::getTypeStatic()); $streamChannelKey2 = $streamChannel2->getKey(); CMTest_TH::createStreamPublish(null, $streamChannel2); //to make channel non empty $location = $this->mockClass('CM_Geo_Point')->newInstanceWithoutConstructor(); $server1 = $this->mockClass('CM_Janus_Server')->newInstance([1, 'key', 'http://mock', 'ws://mock', [], $location]); /** @var CM_Janus_ServerList|\Mocka\AbstractClassTrait $serverList */ $serverList = $this->mockObject('CM_Janus_ServerList'); $serverList->mockMethod('getAll')->set([$server1]); $status = [['id' => $streamPublishKey, 'channelName' => $streamChannelKey, 'isPublish' => true], ['id' => $streamSubscribeKey, 'channelName' => $streamChannelKey, 'isPublish' => false], ['id' => 'absentStreamKey', 'channelName' => 'absentChannelKey', 'isPublish' => false], ['id' => 'absentStreamKey2', 'channelName' => $streamChannelKey2, 'isPublish' => true]]; $httpApiClient = $this->mockClass('CM_Janus_HttpApiClient')->newInstanceWithoutConstructor(); $httpApiClient->mockMethod('fetchStatus')->set(function (CM_Janus_Server $passedServer) use($server1, $status) { $this->assertSame($server1, $passedServer); return $status; }); $stopStreamMethod = $httpApiClient->mockMethod('stopStream')->at(0, function ($server, $streamKey) use($streamPublishKey, $server1) { $this->assertEquals($server1, $server); $this->assertSame($streamPublishKey, $streamKey); })->at(1, function ($server, $streamKey) use($streamSubscribeKey, $server1) { $this->assertEquals($server1, $server); $this->assertSame($streamSubscribeKey, $streamKey); })->at(2, function ($server, $streamKey) use($server1) { $this->assertEquals($server1, $server); $this->assertSame('absentStreamKey', $streamKey); })->at(3, function ($server, $streamKey) use($server1) { $this->assertEquals($server1, $server); $this->assertSame('absentStreamKey2', $streamKey); }); /** @var CM_Janus_HttpApiClient $httpApiClient */ $janus = new CM_Janus_Service($serverList, $httpApiClient); $janus->getStreamRepository()->removeStream($streamPublish); $janus->getStreamRepository()->removeStream($streamSubscribe); $janus->synchronize(); $this->assertSame(4, $stopStreamMethod->getCallCount()); }