/**
  * @dataProvider loadClientProvider
  */
 public function testLoadClient($hardwareData, $biosData, $customFields, $packages, $items, $xmlFile)
 {
     // Only getTableName() is called which returns static data and does not
     // need to be mocked.
     $itemManager = $this->getMockBuilder('Model\\Client\\ItemManager')->disableOriginalConstructor()->setMethods(null)->getMock();
     $itemTypes = $itemManager->getItemTypes();
     $itemHydrator = $this->getMock('Zend\\Stdlib\\Hydrator\\ArraySerializable');
     $itemHydrator->method('extract')->will($this->returnCallback(function ($data) {
         return array_change_key_case($data, CASE_UPPER);
     }));
     $mapGetItems = array();
     $services = array();
     foreach ($itemTypes as $type) {
         $services[] = array('Protocol\\Hydrator\\' . $itemManager->getTableName($type), true, $itemHydrator);
         if (isset($items[$type])) {
             $mapGetItems[] = array($type, 'id', 'asc', array(), $items[$type]);
         } else {
             $mapGetItems[] = array($type, 'id', 'asc', array(), array());
         }
     }
     $client = $this->getMock('Model\\Client\\Client');
     $client->method('offsetGet')->willReturnMap(array(array('ClientId', 'client_id'), array('CustomFields', $customFields)));
     $client->method('getDownloadedPackageIds')->willReturn($packages);
     $client->expects($this->exactly(count($itemTypes)))->method('getItems')->will($this->returnValueMap($mapGetItems));
     $hardwareHydrator = $this->getMockBuilder('Protocol\\Hydrator\\ClientsHardware')->disableOriginalConstructor()->getMock();
     $hardwareHydrator->expects($this->once())->method('extract')->with($client)->willReturn($hardwareData);
     $biosHydrator = $this->getMock('Protocol\\Hydrator\\ClientsBios');
     $biosHydrator->expects($this->once())->method('extract')->with($client)->willReturn($biosData);
     $services[] = array('Model\\Client\\ItemManager', true, $itemManager);
     $services[] = array('Protocol\\Hydrator\\ClientsHardware', true, $hardwareHydrator);
     $services[] = array('Protocol\\Hydrator\\ClientsBios', true, $biosHydrator);
     $serviceLocator = $this->getMock('\\Zend\\ServiceManager\\ServiceManager');
     $serviceLocator->method('get')->willReturnMap($services);
     $document = new \Protocol\Message\InventoryRequest();
     $document->loadClient($client, $serviceLocator);
     $this->assertXmlStringEqualsXmlFile(\Protocol\Module::getPath('data/Test/Message/InventoryRequest/' . $xmlFile), $document->saveXml());
 }
 /**
  * @dataProvider filterProvider
  * @requires PHP 7.0
  */
 public function testFilter($suffix)
 {
     $output = \Zend\Filter\StaticFilter::execute(file_get_contents(\Protocol\Module::getPath("data/Test/Filter/InventoryDecode/encoded-{$suffix}")), 'Protocol\\InventoryDecode');
     $this->assertNotEmpty($output);
     $this->assertEquals(file_get_contents(\Protocol\Module::getPath("data/Test/Filter/InventoryDecode/decoded-{$suffix}")), $output);
 }
Example #3
0
 /** {@inheritdoc} */
 public function getSchemaFilename()
 {
     return \Protocol\Module::getPath('data/RelaxNG/InventoryRequest.rng');
 }