コード例 #1
0
ファイル: TubeTest.php プロジェクト: zwilias/beanie
 public function testTransformTubeStatusTo_respectsMode()
 {
     $tubeStatus = new TubeStatus();
     $tubeStatus->setCurrentTube(self::TEST_TUBE);
     $tube = new Tube(Beanie::DEFAULT_TUBE, $this->getServerMock());
     $tube->transformTubeStatusTo($tubeStatus, TubeStatus::TRANSFORM_WATCHED);
     $this->assertEquals(Beanie::DEFAULT_TUBE, $tube->getTubeStatus()->getCurrentTube());
     $this->assertEquals([Beanie::DEFAULT_TUBE], $tube->getTubeStatus()->getWatchedTubes());
     $this->assertNotSame($tubeStatus, $tube->getTubeStatus());
 }
コード例 #2
0
ファイル: ProducerTest.php プロジェクト: zwilias/beanie
 public function testTransformTubeStatusTo_updatesTubeStatus()
 {
     $testTube = new TubeStatus();
     $testTube->setCurrentTube('TEST');
     $testTube->addWatchedTube('TEST');
     /** @var \PHPUnit_Framework_MockObject_MockObject|Pool $poolMock */
     $poolMock = $this->getMockBuilder(Pool::class)->disableOriginalConstructor()->setMethods(['dispatchCommand'])->getMock();
     $poolMock->expects($this->never())->method('dispatchCommand');
     $producer = new Producer($poolMock);
     $producer->transformTubeStatusTo($testTube, TubeStatus::TRANSFORM_BOTH);
     $this->assertEquals($testTube->getCurrentTube(), $producer->getTubeStatus()->getCurrentTube());
     $this->assertEquals($testTube->getWatchedTubes(), $producer->getTubeStatus()->getWatchedTubes());
 }
コード例 #3
0
ファイル: Server.php プロジェクト: zwilias/beanie
 /**
  * @param TubeStatus $goal
  * @param int $mode
  * @return $this
  */
 public function transformTubeStatusTo(TubeStatus $goal, $mode = TubeStatus::TRANSFORM_BOTH)
 {
     foreach ($this->tubeStatus->transformTo($goal, $mode) as $transformCommand) {
         $this->dispatchCommand($transformCommand)->invoke();
     }
     return $this;
 }
コード例 #4
0
ファイル: TubeStatusTest.php プロジェクト: zwilias/beanie
 public function testRemoveWatchTube_fromMultiple()
 {
     $tubeStatus = new TubeStatus();
     $tubeStatus->addWatchedTube('tube-1');
     $tubeStatus->addWatchedTube('tube-2');
     $tubeStatus->addWatchedTube('tube-3');
     $tubeStatus->removeWatchedTube('tube-2');
     $this->assertEquals([Beanie::DEFAULT_TUBE, 'tube-1', 'tube-3'], $tubeStatus->getWatchedTubes());
 }
コード例 #5
0
ファイル: Tube.php プロジェクト: zwilias/beanie
 /**
  * @return string
  */
 public function getName()
 {
     return $this->tubeStatus->getCurrentTube();
 }
コード例 #6
0
ファイル: ServerTest.php プロジェクト: zwilias/beanie
 public function testTransformTubeStatusTo_willDispatchCommand()
 {
     $tubeStatus = new TubeStatus();
     $tubeStatus->setCurrentTube('test')->addWatchedTube('test');
     /** @var \PHPUnit_Framework_MockObject_MockObject|Server $serverStub */
     $serverStub = $this->getMockBuilder(Server::class)->setMethods(['dispatchCommand'])->getMock();
     $serverStub->expects($this->exactly(2))->method('dispatchCommand')->willReturn($this->getMockBuilder(ResponseOath::class)->disableOriginalConstructor()->setMethods(['invoke'])->getMock());
     $serverStub->transformTubeStatusTo($tubeStatus);
 }
コード例 #7
0
ファイル: TubeStatus.php プロジェクト: zwilias/beanie
 /**
  * @param TubeStatus $goal
  * @param int $mode
  * @return \Beanie\Command\CommandInterface[]
  */
 public function calculateTransformationTo(TubeStatus $goal, $mode = self::TRANSFORM_BOTH)
 {
     $commands = [];
     if ($mode & self::TRANSFORM_WATCHED) {
         $commands = $this->calculateTransformWatched($goal->getWatchedTubes());
     }
     if ($mode & self::TRANSFORM_USE && $goal->getCurrentTube() !== $this->currentTube) {
         $commands[] = $this->commandFactory->create(CommandInterface::COMMAND_USE, [$goal->getCurrentTube()]);
     }
     return $commands;
 }