public function testCreateWithArguments()
 {
     $className = 'SomeModel';
     $data = ['param1', 'param2'];
     $classMock = $this->getMock('SomeModel');
     $this->_objectManagerMock->expects($this->once())->method('create')->with($className, $data)->will($this->returnValue($classMock));
     $this->assertEquals($classMock, $this->_factory->create($className, $data));
 }
Example #2
0
 /**
  * Run one method by given method info
  *
  * @param array $info
  * @param bool $instance
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function fireOne($info, $instance = false)
 {
     if (!$instance || isset($info['block_type']) && !$instance instanceof $info['block_type'] || !isset($info['class']) || !isset($info['method'])) {
         return $this;
     }
     $object = $this->_persistentFactory->create($info['class']);
     $method = $info['method'];
     if (method_exists($object, $method)) {
         $object->{$method}($instance);
     } elseif ($this->_appState->getMode() == \Magento\Framework\App\State::MODE_DEVELOPER) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Method "%1" is not defined in "%2"', $method, get_class($object)));
     }
     return $this;
 }