public function testPrimitiveCopyFunction()
 {
     $abstractPrimitive = $this->abstractPrimitive->setMethods(['cast'])->getMock();
     $abstractPrimitive->setInternalValue('test value');
     $this->assertNotSame($abstractPrimitive, $clone = $abstractPrimitive->copy());
     $this->assertEquals($abstractPrimitive->getInternalValue(), $clone->getInternalValue());
 }
예제 #2
0
 public function reveal()
 {
     $mock = $this->mockBuilder->setMethods($m = $this->getMethodsNames())->getMock();
     foreach ($this->methods as $method) {
         $method->applyToMock($mock);
     }
     return $mock;
 }
예제 #3
0
 /**
  * @covers Malwarebytes\ZendeskBundle\Service\ApiService::getAudit
  */
 public function testGetAudit()
 {
     $apiService = $this->apiService->setMethods(array('_get'))->getMock();
     $ticketId = 123;
     $auditId = 456;
     $mockResponse = array('foo');
     $apiService->expects($this->once())->method('_get')->with("/tickets/{$ticketId}/audits/{$auditId}")->will($this->returnValue($mockResponse));
     $this->assertEquals($mockResponse, $apiService->getAudit($ticketId, $auditId));
 }
예제 #4
0
 /**
  * @covers \Magento\Framework\View\Design\Theme\Customization\AbstractFile::delete
  * @covers \Magento\Framework\View\Design\Theme\Customization\AbstractFile::_deleteFileContent
  */
 public function testDelete()
 {
     $model = $this->_modelBuilder->setMethods(['getFullPath', 'getType', 'getContentType'])->getMock();
     $file = $this->getMock('Magento\\Theme\\Model\\Theme\\File', ['__wakeup'], [], '', false);
     $file->setData(['file_type' => 'js', 'file_name' => 'test_3.js', 'file_path' => 'js/test_3.js', 'content' => 'test content', 'sort_order' => 12]);
     $directoryMock = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\Write', ['touch', 'delete', 'getRelativePath'], [], '', false);
     $directoryMock->expects($this->once())->method('touch')->will($this->returnValue(true));
     $directoryMock->expects($this->once())->method('delete')->will($this->returnValue(true));
     $this->_filesystem->expects($this->any())->method('getDirectoryWrite')->with(DirectoryList::ROOT)->will($this->returnValue($directoryMock));
     $model->expects($this->once())->method('getFullPath')->with($file)->will($this->returnValue('test_path'));
     /** @var $model \Magento\Framework\View\Design\Theme\Customization\AbstractFile */
     /** @var $file \Magento\Theme\Model\Theme\File */
     $model->delete($file);
 }
예제 #5
0
 /**
  * @param bool $shouldCloneFields
  * @param array $prefixes
  * @param int $callNum
  * @dataProvider initGroupDataProvider
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testInitGroup($shouldCloneFields, $prefixes, $callNum)
 {
     /** @var \Magento\Config\Block\System\Config\Form | \PHPUnit_Framework_MockObject_MockObject $object */
     $object = $this->_objectBuilder->setMethods(['initFields'])->getMock();
     $this->_formFactoryMock->expects($this->any())->method('create')->will($this->returnValue($this->_formMock));
     $this->_formMock->expects($this->once())->method('setParent')->with($object);
     $this->_formMock->expects($this->once())->method('setBaseUrl')->with('base_url');
     $this->_urlModelMock->expects($this->any())->method('getBaseUrl')->will($this->returnValue('base_url'));
     $fieldsetRendererMock = $this->getMock('Magento\\Config\\Block\\System\\Config\\Form\\Fieldset', [], [], '', false, false);
     $this->_fieldsetFactoryMock->expects($this->once())->method('create')->will($this->returnValue($fieldsetRendererMock));
     $cloneModelMock = $this->getMock('Magento\\Config\\Model\\Config', ['getPrefixes'], [], '', false, false);
     $groupMock = $this->getMock('Magento\\Config\\Model\\Config\\Structure\\Element\\Group', [], [], '', false, false);
     $groupMock->expects($this->once())->method('getFrontendModel')->will($this->returnValue(false));
     $groupMock->expects($this->any())->method('getPath')->will($this->returnValue('section_id_group_id'));
     $groupMock->expects($this->once())->method('getLabel')->will($this->returnValue('label'));
     $groupMock->expects($this->once())->method('getComment')->will($this->returnValue('comment'));
     $groupMock->expects($this->once())->method('isExpanded')->will($this->returnValue(false));
     $groupMock->expects($this->once())->method('populateFieldset');
     $groupMock->expects($this->once())->method('shouldCloneFields')->will($this->returnValue($shouldCloneFields));
     $groupMock->expects($this->once())->method('getData')->will($this->returnValue('some group data'));
     $groupMock->expects($this->once())->method('getDependencies')->with('store_code')->will($this->returnValue([]));
     $sectionMock = $this->getMock('Magento\\Config\\Model\\Config\\Structure\\Element\\Section', [], [], '', false, false);
     $sectionMock->expects($this->once())->method('isVisible')->will($this->returnValue(true));
     $sectionMock->expects($this->once())->method('getChildren')->will($this->returnValue([$groupMock]));
     $this->_systemConfigMock->expects($this->once())->method('getElement')->with('section_code')->will($this->returnValue($sectionMock));
     $formFieldsetMock = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Fieldset', [], [], '', false, false);
     $params = ['legend' => 'label', 'comment' => 'comment', 'expanded' => false, 'group' => 'some group data'];
     $this->_formMock->expects($this->once())->method('addFieldset')->with('section_id_group_id', $params)->will($this->returnValue($formFieldsetMock));
     if ($shouldCloneFields) {
         $cloneModelMock->expects($this->once())->method('getPrefixes')->will($this->returnValue($prefixes));
         $groupMock->expects($this->once())->method('getCloneModel')->will($this->returnValue($cloneModelMock));
     }
     if ($shouldCloneFields && $prefixes) {
         $object->expects($this->exactly($callNum))->method('initFields')->with($formFieldsetMock, $groupMock, $sectionMock, $prefixes[0]['field'], $prefixes[0]['label']);
     } else {
         $object->expects($this->exactly($callNum))->method('initFields')->with($formFieldsetMock, $groupMock, $sectionMock);
     }
     $object->initForm();
 }
예제 #6
0
 /**
  * @covers  HubRssFeedModel::getRealDataV3
  */
 public function testGetRealDataV3()
 {
     $mockToolbox = $this->editHubModel->setMethods(['getLastPublishedTimestamp'])->getMock();
     $mockToolbox->expects($this->any())->method('getLastPublishedTimestamp', '__construct')->will($this->returnCallback('HubRssModelTest::mock_getLastPublishedTimestamp'));
     $this->mockClass('EditHubModel', $mockToolbox);
     $mock = $this->getMockBuilder('HubRssFeedModel')->disableOriginalConstructor()->setMethods(['getDataFromModulesV3'])->getMock();
     $refl = new \ReflectionObject($mock);
     $prop = $refl->getProperty('editHubModel');
     $prop->setAccessible(true);
     $prop->setValue($mock, $mockToolbox);
     $mock->expects($this->any())->method('getDataFromModulesV3')->will($this->returnCallback('HubRssModelTest::mock_getDataFromModulesV3'));
     $res = $mock->getRealDataV3(1);
     // non-zero number
     $this->assertArrayHasKey('url_1', $res);
     $this->assertEquals(HubRssFeedModel::MIN_DATE_FOUND, $res['url_1']['timestamp']);
     $this->assertArrayHasKey('url_2', $res);
     $this->assertEquals(1001, $res['url_2']['timestamp']);
     $this->assertArrayNotHasKey('url_3', $res);
     $this->assertArrayHasKey('url_4', $res);
     $this->assertEquals(991, $res['url_4']['timestamp']);
     $item1 = array_shift($res);
     $item2 = array_shift($res);
     $item3 = array_shift($res);
 }
 /**
  * Allows keeping original methods intact by overriding the set methods
  * @param MockBuilder $mock
  * @param string $name
  */
 private function setMockMethods(MockBuilder $mock, $name)
 {
     if (array_key_exists($name, $this->methods)) {
         $mock->setMethods($this->methods[$name]);
     }
 }
예제 #8
0
 /**
  * @return \PHPUnit_Framework_MockObject_MockObject
  */
 public function getUrlMock()
 {
     $mockBuilder = new MockBuilder($this->testCase, 'Zend\\Mvc\\Controller\\Plugin\\Url');
     $mockBuilder->setMethods(['fromRoute']);
     $mockBuilder->disableOriginalConstructor();
     $urlMock = $mockBuilder->getMock();
     return $urlMock;
 }