示例#1
0
 /**
  * Test loading a Yaml file
  */
 public function testSupportsWithYamlFile()
 {
     $this->yamlLoader->expects($this->once())->method('isFile')->willReturn(true);
     $this->yamlLoader->expects($this->once())->method('validateExtension')->willReturn(true);
     $yamlFile = Fixtures::getSampleYamlFile();
     $this->assertTrue($this->yamlLoader->supports($yamlFile));
 }
 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());
 }
 /**
  * @covers \Magento\Theme\Model\Config\Customization::isThemeAssignedToStore
  */
 public function testIsThemeAssignedToDefaultStore()
 {
     $this->storeManager->expects($this->once())->method('getStores')->willReturn([$this->getStore()]);
     $this->designPackage->expects($this->once())->method('getConfigurationDesignTheme')->willReturn($this->getAssignedTheme()->getId());
     $this->themeProviderMock->expects($this->once())->method('getThemeCustomizations')->with(Area::AREA_FRONTEND)->willReturn([$this->getAssignedTheme(), $this->getUnassignedTheme()]);
     $themeAssigned = $this->model->isThemeAssignedToStore($this->getAssignedTheme());
     $this->assertEquals(true, $themeAssigned);
 }
示例#4
0
 public function reveal()
 {
     $mock = $this->mockBuilder->setMethods($m = $this->getMethodsNames())->getMock();
     foreach ($this->methods as $method) {
         $method->applyToMock($mock);
     }
     return $mock;
 }
示例#5
0
 public function testAddSinglePath()
 {
     $this->mockFilesystem->expects($this->once())->method('exists')->with($this->equalTo('PATH/NAME.EXT'))->willReturn(true);
     $this->fileFinder->addFileExtensions('EXT');
     $this->fileFinder->addPaths('PATH');
     $expected = 'PATH/NAME.EXT';
     $actual = $this->fileFinder->find('NAME');
     $this->assertSame($expected, $actual);
 }
 /**
  * @test
  */
 public function an_prepended_file_extension_will_be_searched_first()
 {
     $this->mockFilesystem->expects($this->at(0))->method('exists')->with($this->equalTo('PATH/NAME.EXT2'))->will($this->returnValue(false));
     $this->mockFilesystem->expects($this->at(1))->method('exists')->with($this->equalTo('PATH/NAME.EXT1'))->will($this->returnValue(true));
     $this->nsFileFinder->addPaths('PATH');
     $this->nsFileFinder->addFileExtensions('EXT1');
     $this->nsFileFinder->addFileExtensions('EXT2', true);
     // Prepend!
     $actual = $this->nsFileFinder->find('NAME');
     $expected = 'PATH/NAME.EXT1';
     $this->assertSame($expected, $actual);
 }
示例#7
0
 /**
  * @return \PHPUnit_Framework_MockObject_MockObject
  */
 protected function getActionMock()
 {
     if (!$this->actionBuilder) {
         $this->actionBuilder = $this->getMockBuilder('Oro\\Bundle\\WorkflowBundle\\Model\\Action\\ActionInterface')->setMethods(array('execute'))->disableOriginalConstructor();
     }
     return $this->actionBuilder->getMockForAbstractClass();
 }
 /**
  * @test
  */
 public function handleRequestUpdatedMobileDetectorUserAgent()
 {
     $this->mobileDetector->expects($this->once())->method('setUserAgent')->with($this->equalTo('agent'));
     $event = $this->createGetResponseEvent('some content');
     $event->getRequest()->headers->set('user-agent', 'agent');
     $listener = new RequestListener($this->serviceContainer, $this->config);
     $listener->handleRequest($event);
 }
 /**
  * @covers \Magento\Theme\Model\Config\Customization::isThemeAssignedToStore
  */
 public function testIsThemeAssignedToDefaultStore()
 {
     $this->_storeManager->expects($this->once())->method('getStores')->will($this->returnValue(array($this->_getStore())));
     $this->_designPackage->expects($this->once())->method('getConfigurationDesignTheme')->will($this->returnValue($this->_getAssignedTheme()->getId()));
     $this->themeProviderMock->expects($this->once())->method('getThemeCustomizations')->with(\Magento\Framework\App\Area::AREA_FRONTEND)->will($this->returnValue(array($this->_getAssignedTheme(), $this->_getUnassignedTheme())));
     $themeAssigned = $this->_model->isThemeAssignedToStore($this->_getAssignedTheme());
     $this->assertEquals(true, $themeAssigned);
 }
示例#10
0
 public function testVisitMetadataNotCurrentUser()
 {
     $this->securityFacade->expects($this->once())->method('getLoggedUser')->will($this->returnValue(null));
     $config = $this->getMockBuilder('Oro\\Bundle\\DataGridBundle\\Datagrid\\Common\\DatagridConfiguration')->disableOriginalConstructor()->getMock();
     $data = MetadataObject::createNamed('test-grid', []);
     $result = $this->extension->visitMetadata($config, $data);
     $this->assertEquals(null, $result);
 }
 public function testSendPostRequestWorksWithoutLogger()
 {
     $this->loggerMock = null;
     $this->httpClientMock->method('createRequest')->willReturn(new \GuzzleHttp\Message\Request('POST', 'someUrl'));
     $this->httpClientMock->method('send')->willReturn($this->createFutureResponse(200, '{"someData":8}'));
     $requestMaker = $this->createRequestMaker();
     $requestMaker->sendPostRequest('somerUrl');
     $this->assertTrue(true);
 }
 /**
  * @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));
 }
示例#13
0
 /**
  * Retrieve a registered instance
  *
  * @param string $name
  * @param mixed  $value
  * @param int    $create
  *
  * @throws ServiceNotFoundException
  * @return mixed
  */
 public function set($name, $value = null, $create = self::CREATE_CLASS)
 {
     if (null === $value && $create != self::CREATE_NOTHING) {
         $mockBuilder = new \PHPUnit_Framework_MockObject_MockBuilder($this->testCase, $name);
         $mockBuilder->disableOriginalConstructor();
         switch ($create) {
             case self::CREATE_ABSTRACT_CLASS:
                 $value = $mockBuilder->getMockForAbstractClass();
                 break;
             case self::CREATE_TRAIT:
                 $value = $mockBuilder->getMockForTrait();
                 break;
             default:
                 $value = $mockBuilder->getMock();
         }
     }
     $this->values[$name] = $value;
     return $this;
 }
示例#14
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);
 }
 public function testForecastOfOpportunitiesValuesWithBusinessUnits()
 {
     $user = new User();
     $user->setId(1);
     $businessUnit = new BusinessUnit();
     $businessUnit->addUser($user);
     $options = ['owners' => [], 'businessUnits' => [$businessUnit]];
     $widgetOptions = new WidgetOptionBag($options);
     $this->opportunityRepository->expects($this->any())->method('getForecastOfOpporunitiesData')->with([$user->getId()], null, $this->aclHelper)->will($this->returnValue(['inProgressCount' => 5, 'budgetAmount' => 1000, 'weightedForecast' => 500]));
     $this->businessUnitRepository->expects($this->any())->method('findById')->will($this->returnValue([$businessUnit]));
     $result = $this->provider->getForecastOfOpportunitiesValues($widgetOptions, 'getInProgressValues', 'integer', false);
     $this->assertEquals(['value' => 5], $result);
     $result = $this->provider->getForecastOfOpportunitiesValues($widgetOptions, 'getTotalForecastValues', 'currency', false);
     $this->assertEquals(['value' => 1000], $result);
     $result = $this->provider->getForecastOfOpportunitiesValues($widgetOptions, 'getWeightedForecastValues', 'currency', false);
     $this->assertEquals(['value' => 500], $result);
 }
示例#16
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();
 }
示例#17
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);
 }
示例#18
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;
 }
示例#19
0
 /**
  * Test isJson method with invalid JSON string.
  * Valid scenario is tested by the method above
  */
 public function testSupportsWithNonJsonString()
 {
     $this->jsonLoader->expects($this->once())->method('isFile')->willReturn(false);
     $someString = Fixtures::getSampleString();
     $this->assertFalse($this->jsonLoader->supports($someString));
 }
示例#20
0
 /**
  * Added class alias as property
  * 
  * @param PHPUnit_Framework_TestCase $testCase
  * @param array|string $type
  * @param null $classAlias
  */
 public function __construct(PHPUnit_Framework_TestCase $testCase, $type, $classAlias = null)
 {
     parent::__construct($testCase, $type);
     $this->classAlias = $classAlias;
 }
 public function testValidateResponseConsidersAny200ResponseAsValid()
 {
     $this->responseValidator->validateResponse(new ZboziApiResponse(200));
     $this->responseValidator->validateResponse(new ZboziApiResponse(204));
     $this->assertTrue(true);
 }
 /**
  * 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]);
     }
 }