Example #1
0
 /**
  * @param ServiceLocatorInterface $serviceLocator
  *
  * @return DashboardController
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     if ($serviceLocator instanceof ControllerManager) {
         $serviceLocator = $serviceLocator->getServiceLocator();
     }
     /** @var KpiDataProvider $kpiDataProvider */
     $kpiDataProvider = $serviceLocator->get('DmMailer\\View\\DataProvider\\Kpi');
     /** @var StatsDataProvider $statsDataProvider */
     $statsDataProvider = $serviceLocator->get('DmMailer\\View\\DataProvider\\Stats');
     $controller = new DashboardController();
     $controller->addViewDataProvider($kpiDataProvider);
     $controller->addViewDataProvider($statsDataProvider);
     return $controller;
 }
 /**
  * @covers DmMailerAdmin\Controller\DashboardController
  */
 public function testIndexActionAddsViewDataFromProviders()
 {
     $data1 = ['foo1' => 'foo-data-1', 'foo2' => 'foo-data-2'];
     $data2 = ['bar' => 'bar-data'];
     $providerMock = $this->getMockBuilder('DmMailer\\View\\DataProvider\\DataProviderInterface')->setMethods(['getViewData'])->disableOriginalConstructor()->getMock();
     $providerMock->expects($this->at(0))->method('getViewData')->will($this->returnValue($data1));
     $providerMock->expects($this->at(1))->method('getViewData')->will($this->returnValue($data2));
     $this->sut->addViewDataProvider($providerMock);
     $this->sut->addViewDataProvider($providerMock);
     $actualResult = $this->sut->indexAction();
     $this->assertInstanceOf('Zend\\View\\Model\\ViewModel', $actualResult);
     $this->assertEquals($data1['foo1'], $actualResult->foo1);
     $this->assertEquals($data1['foo2'], $actualResult->foo2);
     $this->assertEquals($data2['bar'], $actualResult->bar);
 }