Example #1
0
 public function testAdd()
 {
     $this->varReaderWriter->expects($this->once())->method('isExist')->willReturn(false);
     $this->varReaderWriter->expects($this->once())->method('writeFile');
     $this->logger->expects($this->once())->method('log')->with(\Psr\Log\LogLevel::ERROR, 'test1');
     $this->status->add('test1', \Psr\Log\LogLevel::ERROR);
 }
 protected function setUp()
 {
     $this->logger = $this->getMock('Psr\\Log\\LoggerInterface', array('info', 'error'));
     $this->logger->expects($this->any())->method('info');
     $this->logger->expects($this->any())->method('error');
     $this->adapter = new BraintreeSubscriptionAdapter($this->logger, 'sandbox', MERCHANTID, PUBLICKEY, PRIVATEKEY, 'Kairos\\SubscriptionBundle\\Tests\\TestEntities\\TransactionEntity');
 }
Example #3
0
 public function testBeforeDispatchWithException()
 {
     $exception = new LocalizedException(new Phrase('Phrase'));
     $this->themeRegistration->expects($this->once())->method('register')->willThrowException($exception);
     $this->logger->expects($this->once())->method('critical');
     $this->plugin->beforeDispatch($this->abstractAction, $this->request);
 }
Example #4
0
 public function testBeforeExecuteWithException()
 {
     $exception = new LocalizedException(new Phrase('Phrase'));
     $this->themeRegistration->expects($this->once())->method('register')->willThrowException($exception);
     $this->logger->expects($this->once())->method('critical');
     $object = new Registration($this->themeRegistration, $this->logger, $this->appState);
     $object->beforeExecute($this->abstractAction, $this->request);
 }
 public function testUpdateDbWithException()
 {
     $this->databaseConfig->expects($this->once())->method('isAutoUpdate')->willReturn(true);
     $e = new \Exception();
     $this->updaterSelected->expects($this->once())->method('update')->willThrowException($e);
     $this->logger->expects($this->once())->method('critical')->with($e);
     $this->assertSame($this->cronUpdateDb, $this->cronUpdateDb->execute());
 }
 public function testSendEmailWhenRedirectUrlExists()
 {
     $this->paymentMock->expects($this->once())->method('getOrderPlaceRedirectUrl')->willReturn(false);
     $this->orderMock->expects($this->once())->method('getCanSendNewEmailFlag');
     $this->orderSenderMock->expects($this->never())->method('send');
     $this->loggerMock->expects($this->never())->method('critical');
     $this->model->execute($this->observerMock);
 }
 /**
  * Make sure publish is logged.
  */
 public function testCall()
 {
     $this->innerDriver->expects(self::once())->method('call')->willReturn(new Promise(function () {
         return new Response('');
     }));
     $this->logger->expects(self::exactly(2))->method('debug');
     $this->driver->call(new Identity(''), new Request(''))->resolve();
 }
 public function testServiceNotListening()
 {
     $this->logger->expects($this->once())->method('info');
     $this->logger->expects($this->once())->method('warning');
     $this->connection->expects($this->any())->method('isServiceListening')->will($this->returnValue(false));
     $listener = new PheanstalkLogListener();
     $listener->setLogger($this->logger);
     $listener->onCommand(new CommandEvent($this->pheanstalk, []), CommandEvent::PEEK_READY);
 }
Example #9
0
 public function testIndexActionException()
 {
     $this->request->expects($this->once())->method('isPost')->will($this->returnValue(true));
     $exception = new \Exception();
     $this->request->expects($this->once())->method('getPostValue')->will($this->throwException($exception));
     $this->logger->expects($this->once())->method('critical')->with($this->identicalTo($exception));
     $this->response->expects($this->once())->method('setHttpResponseCode')->with(500);
     $this->model->executeInternal();
 }
 /**
  * @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $loggerExpects
  * @param string $stateMode
  * @return void
  * @dataProvider reorderChildElementLogDataProvider
  */
 public function testReorderChildElementLog($loggerExpects, $stateMode)
 {
     $parentName = 'parent';
     $childName = 'child';
     $offsetOrSibling = '-';
     $this->stateMock->expects($this->once())->method('getMode')->willReturn($stateMode);
     $this->loggerMock->expects($loggerExpects)->method('critical')->with("Broken reference: the '{$childName}' tries to reorder itself towards '', but " . "their parents are different: '{$parentName}' and '' respectively.");
     $this->dataStructure->reorderChildElement($parentName, $childName, $offsetOrSibling);
 }
 public function testApplyThemeCustomizationException()
 {
     $file = $this->getMock('Magento\\Theme\\Model\\Theme\\File', [], [], '', false);
     $file->expects($this->any())->method('getCustomizationService')->willThrowException(new \InvalidArgumentException());
     $this->themeCustomization->expects($this->once())->method('getFiles')->will($this->returnValue([$file]));
     $this->logger->expects($this->once())->method('critical');
     $observer = new \Magento\Framework\Event\Observer();
     $this->themeObserver->execute($observer);
 }
 /**
  * @expectedException \Assertis\SimpleDatabase\SimpleDatabaseExecuteException
  */
 public function testExecuteQueryThrowsExceptionOnExecuteError()
 {
     $sql = "SQL";
     $params = ['foo' => 'bar'];
     $this->pdo->expects($this->once())->method('prepare')->with($sql)->willReturn($this->statement);
     $this->statement->expects($this->once())->method('execute')->with($params)->willReturn(false);
     $this->logger->expects($this->once())->method('error');
     $db = new SimpleDatabase($this->pdo, $this->logger);
     $db->executeQuery($sql, $params);
 }
 public function testDone()
 {
     $jobId = 12345;
     $this->pheanstalkMock->expects($this->once())->method('delete')->with($this->callback(function (Job $job) use($jobId) {
         return $job->getId() === $jobId;
     }));
     $this->pheanstalkMock->expects($this->any())->method('peek')->with($jobId)->willReturn(new Job($jobId, 'asdf'));
     $this->loggerMock->expects($this->once())->method('info')->with('Done job (12345): asdf');
     $this->sut->done($jobId);
 }
 public function testGetFilesEmpty()
 {
     $this->libraryFilesMock->expects($this->any())->method('getFiles')->will($this->returnValue([]));
     $this->baseFilesMock->expects($this->any())->method('getFiles')->will($this->returnValue([]));
     $this->overriddenBaseFilesMock->expects($this->any())->method('getFiles')->will($this->returnValue([]));
     $aggregated = new Aggregated($this->fileListFactoryMock, $this->libraryFilesMock, $this->baseFilesMock, $this->overriddenBaseFilesMock, $this->loggerMock);
     $this->themeMock->expects($this->any())->method('getInheritedThemes')->will($this->returnValue([]));
     $this->themeMock->expects($this->any())->method('getCode')->will($this->returnValue('theme_code'));
     $this->loggerMock->expects($this->once())->method('notice')->with('magento_import returns empty result by path * for theme theme_code', []);
     $aggregated->getFiles($this->themeMock, '*');
 }
Example #15
0
 public function testExecuteWithException()
 {
     $this->requestMock->expects($this->once())->method('getParam')->with('item_id', null)->willReturn('1');
     $exception = new \Exception('Error message!');
     $this->sidebarMock->expects($this->once())->method('checkQuoteItem')->with(1)->willThrowException($exception);
     $this->loggerMock->expects($this->once())->method('critical')->with($exception)->willReturn(null);
     $this->sidebarMock->expects($this->once())->method('getResponseData')->with('Error message!')->willReturn(['success' => false, 'error_message' => 'Error message!']);
     $this->jsonHelperMock->expects($this->once())->method('jsonEncode')->with(['success' => false, 'error_message' => 'Error message!'])->willReturn('json encoded');
     $this->responseMock->expects($this->once())->method('representJson')->with('json encoded')->willReturn('json represented');
     $this->assertEquals('json represented', $this->removeItem->executeInternal());
 }
 public function testThemeRegistration()
 {
     $pattern = 'some pattern';
     $eventMock = $this->getMockBuilder('Magento\\Framework\\Event')->setMethods(['getPathPattern'])->disableOriginalConstructor()->getMock();
     $eventMock->expects($this->any())->method('getPathPattern')->willReturn($pattern);
     $observerMock = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $observerMock->expects($this->any())->method('getEvent')->willReturn($eventMock);
     $this->registration->expects($this->once())->method('register')->with($pattern)->willThrowException(new \Magento\Framework\Exception\LocalizedException(__('exception')));
     $this->logger->expects($this->once())->method('critical');
     /** @var $observerMock \Magento\Framework\Event\Observer */
     $this->themeObserver->execute($observerMock);
 }
Example #17
0
 public function testRunError()
 {
     $process = $this->createProcessMock();
     $process->expects($this->once())->method('getCommandLine')->will($this->returnValue($command = 'foo.sh'));
     $this->logger->expects($this->once())->method('debug')->with($this->identicalTo(sprintf('Webhook process started: "%s".', $command)));
     $process->expects($this->once())->method('run');
     $process->expects($this->once())->method('isSuccessful')->will($this->returnValue(false));
     $process->expects($this->once())->method('getOutput')->will($this->returnValue($output = 'output'));
     $process->expects($this->once())->method('getErrorOutput')->will($this->returnValue($error = 'error'));
     $this->logger->expects($this->once())->method('error')->with($this->identicalTo(sprintf('Webhook process errored: "%s".', $command)), $this->identicalTo(['output' => $output, 'error' => $error]));
     $this->runner->run($process);
 }
 public function getViewFileUrlWithException()
 {
     $params = ['a' => 'b'];
     $paramsSecure = ['a' => 'b', '_secure' => false];
     $fileId = 'file id';
     $fileUrl = 'exception url';
     $this->requestMock->expects($this->once())->method('isSecure')->willReturn(false);
     $exception = new LocalizedException('message');
     $this->repositoryMock->expects($this->once())->method('getUrlWithParams')->with($fileId, $paramsSecure)->willThrowException($exception);
     $this->loggerMock->expects($this->once())->method('critical')->with($exception);
     $this->urlMock->expects($this->once())->method('getUrl')->with('', ['_direct' => 'core/index/notFound'])->willReturn($fileUrl);
     $this->assertEquals($fileUrl, $this->model->getViewFileUrl($fileId, $params));
 }
Example #19
0
 /**
  * Testcase Constructor.
  *
  * @return void
  */
 public function setUpError()
 {
     $this->logger = $this->getMock('Psr\\Log\\LoggerInterface');
     $this->header = $this->getMock('http\\Header');
     $response = $this->getMockBuilder('Lunr\\Network\\CurlResponse')->disableOriginalConstructor()->getMock();
     $response->expects($this->once())->method('get_network_error_number')->will($this->returnValue(-1));
     $response->expects($this->once())->method('get_network_error_message')->will($this->returnValue('Error Message'));
     $map = [['http_code', 404], ['url', 'http://localhost/']];
     $response->expects($this->exactly(2))->method('__get')->will($this->returnValueMap($map));
     $this->logger->expects($this->once())->method('warning')->with($this->equalTo('Dispatching push notification to {endpoint} failed: {error}'), $this->equalTo(['error' => 'Error Message', 'endpoint' => 'http://localhost/']));
     $this->class = new MPNSResponse($response, $this->logger, $this->header);
     $this->reflection = new ReflectionClass('Lunr\\Vortex\\MPNS\\MPNSResponse');
 }
Example #20
0
 public function testUpdate()
 {
     $statusInfo = 'some status info';
     $data = ['status' => 'success', 'message' => __('Database(s) successfully updated.'), 'status_info' => $statusInfo];
     $this->resultJson->expects($this->once())->method('setData')->with($data)->willReturnSelf();
     $this->updaterSelected->expects($this->once())->method('update')->willReturnSelf();
     $statusBlock = $this->getMockBuilder('Tobai\\GeoIp2\\Block\\Adminhtml\\System\\Config\\Status')->disableOriginalConstructor()->getMock();
     $layout = $this->getMock('Magento\\Framework\\View\\LayoutInterface');
     $this->layoutFactory->expects($this->once())->method('create')->willReturn($layout);
     $layout->expects($this->once())->method('createBlock')->with('Tobai\\GeoIp2\\Block\\Adminhtml\\System\\Config\\Status')->willReturn($statusBlock);
     $statusBlock->expects($this->once())->method('getDbStatus')->willReturn($statusInfo);
     $this->logger->expects($this->never())->method('critical');
     $this->assertSame($this->resultJson, $this->controllerUpdate->execute());
 }
 /**
  * @param string $application
  * @param array  $parameters
  * @dataProvider provideValidParameters
  */
 public function testLogActionWithValidParameters($application, $parameters)
 {
     $url = '/api/log/' . $application;
     $client = static::createClient();
     $this->mockRegistry();
     $this->registry->expects($this->once())->method('get')->with($application)->willReturn($this->logger);
     if (!isset($parameters['context'])) {
         $this->logger->expects($this->once())->method('log')->with($parameters['level'], $parameters['message']);
     } else {
         $this->logger->expects($this->once())->method('log')->with($parameters['level'], $parameters['message'], $parameters['context']);
     }
     $client->request('POST', $url, $parameters, array(), array('CONTENT_TYPE' => 'application/json'), null, 'json');
     $this->assertEquals(204, $client->getResponse()->getStatusCode());
     $this->assertEmpty($client->getResponse()->getContent());
 }
 public function testExecuteWithException()
 {
     $themeId = 23;
     $this->_request->expects($this->at(0))->method('getParam')->with('id')->willReturn($themeId);
     $this->_objectManagerMock->expects($this->at(0))->method('get')->with('Magento\\Theme\\Model\\Uploader\\Service')->WillReturn($this->serviceModel);
     $this->_objectManagerMock->expects($this->at(1))->method('get')->with('Magento\\Framework\\View\\Design\\Theme\\FlyweightFactory')->WillReturn($this->themeFactory);
     $this->_objectManagerMock->expects($this->at(2))->method('get')->with('Magento\\Framework\\View\\Design\\Theme\\Customization\\File\\Js')->WillReturn($this->customizationJs);
     $this->_objectManagerMock->expects($this->at(4))->method('get')->with('Magento\\Framework\\Json\\Helper\\Data')->WillReturn($this->jsonHelper);
     $this->themeFactory->expects($this->once())->method('create')->willThrowException(new \Exception('Message'));
     $this->_objectManagerMock->expects($this->at(3))->method('get')->with('Psr\\Log\\LoggerInterface')->willReturn($this->logger);
     $this->logger->expects($this->once())->method('critical');
     $this->jsonHelper->expects($this->once())->method('jsonEncode')->with(['error' => true, 'message' => 'We can\'t upload the JS file right now.'])->willReturn('{"error":"true","message":"We can\'t upload the JS file right now."}');
     $this->response->expects($this->once())->method('representJson')->with('{"error":"true","message":"We can\'t upload the JS file right now."}');
     $this->_model->execute();
 }
 public function testFetchViewWithNoFileName()
 {
     $output = '';
     $template = false;
     $templatePath = 'wrong_template_path.pthml';
     $moduleName = 'Acme';
     $blockName = 'acme_test_module_test_block';
     $exception = "Invalid template file: '{$templatePath}' in module: '{$moduleName}' block's name: '{$blockName}'";
     $this->block->setTemplate($templatePath);
     $this->block->setData('module_name', $moduleName);
     $this->block->setNameInLayout($blockName);
     $this->validator->expects($this->once())->method('isValid')->with($template)->willReturn(false);
     $this->loggerMock->expects($this->once())->method('critical')->with($exception)->willReturn(null);
     $this->assertEquals($output, $this->block->fetchView($template));
 }
Example #24
0
 /**
  * @param $groupOne
  * @param $groupTwo
  * @param $expectedResult
  * @dataProvider dataProviderRenderAssets
  */
 public function testRenderAssets($groupOne, $groupTwo, $expectedResult)
 {
     $assetUrl = 'url';
     $assetNoRoutUrl = 'no_route_url';
     $exception = new \Magento\Framework\Exception('my message');
     $assetMockOne = $this->getMock('Magento\\Framework\\View\\Asset\\AssetInterface');
     $assetMockOne->expects($this->exactly(2))->method('getUrl')->willReturn($assetUrl);
     $groupAssetsOne = [$assetMockOne, $assetMockOne];
     $groupMockOne = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\PropertyGroup')->disableOriginalConstructor()->getMock();
     $groupMockOne->expects($this->once())->method('getAll')->willReturn($groupAssetsOne);
     $groupMockOne->expects($this->any())->method('getProperty')->willReturnMap([[GroupedCollection::PROPERTY_CAN_MERGE, true], [GroupedCollection::PROPERTY_CONTENT_TYPE, $groupOne['type']], ['attributes', $groupOne['attributes']], ['ie_condition', $groupOne['condition']]]);
     $assetMockTwo = $this->getMock('Magento\\Framework\\View\\Asset\\AssetInterface');
     $assetMockTwo->expects($this->once())->method('getUrl')->willThrowException($exception);
     $groupAssetsTwo = [$assetMockTwo];
     $groupMockTwo = $this->getMockBuilder('Magento\\Framework\\View\\Asset\\PropertyGroup')->disableOriginalConstructor()->getMock();
     $groupMockTwo->expects($this->once())->method('getAll')->willReturn($groupAssetsTwo);
     $groupMockTwo->expects($this->any())->method('getProperty')->willReturnMap([[GroupedCollection::PROPERTY_CAN_MERGE, true], [GroupedCollection::PROPERTY_CONTENT_TYPE, $groupTwo['type']], ['attributes', $groupTwo['attributes']], ['ie_condition', $groupTwo['condition']]]);
     $this->pageConfigMock->expects($this->once())->method('getAssetCollection')->willReturn($this->assetsCollection);
     $this->assetsCollection->expects($this->once())->method('getGroups')->willReturn([$groupMockOne, $groupMockTwo]);
     $this->assetMinifyServiceMock->expects($this->exactly(2))->method('getAssets')->willReturnArgument(0);
     $this->assetMergeServiceMock->expects($this->exactly(1))->method('getMergedAssets')->willReturnArgument(0);
     $this->loggerMock->expects($this->once())->method('critical')->with($exception);
     $this->urlBuilderMock->expects($this->once())->method('getUrl')->with('', ['_direct' => 'core/index/notFound'])->willReturn($assetNoRoutUrl);
     $this->assertEquals($expectedResult, $this->renderer->renderAssets($this->renderer->getAvailableResultGroups()));
 }
 public function testFeedParserTransformsLinks()
 {
     $rss = '<rss version="2.0">
                 <channel>
                     <title>Example channel</title>
                     <item>
                         <custom-name-tag>Example name</custom-name-tag>
                         <custom-link-tag>http://link.tld/resource/</custom-link-tag>
                     </item>
                     <item>
                         <custom-name-tag>Another name</custom-name-tag>
                         <custom-link-tag>http://example.com/getme/</custom-link-tag>
                     </item>
                 </channel>
             </rss>';
     $this->aggregatorConfiguration->expects($this->atLeastOnce())->method('getNameTagName')->willReturn('custom-name-tag');
     $this->aggregatorConfiguration->expects($this->atLeastOnce())->method('getLinkTagName')->willReturn('custom-link-tag');
     $this->aggregatorConfiguration->expects($this->atLeastOnce())->method('getNameExtractPattern')->willReturn('/^(.*?) /');
     $this->aggregatorConfiguration->expects($this->atLeastOnce())->method('getLinkExtractPattern')->willReturn('/^(.*?)$/');
     $this->aggregatorConfiguration->expects($this->atLeastOnce())->method('getLinkTransformPattern')->willReturn(['/^(.*?)$/', '$1?passkey=1234']);
     $this->logger->expects($this->never())->method('error');
     $this->logger->expects($this->never())->method('warning');
     $result = $this->subjectUnderTest->parseFeedXml($rss);
     $this->assertSame(['Example' => 'http://link.tld/resource/?passkey=1234', 'Another' => 'http://example.com/getme/?passkey=1234'], $result);
 }
 /**
  * Tests deleteTemporaryAssets() when the config item for age is 0.
  *
  * @covers ::deleteTemporaryAssets
  *
  * @test
  */
 public function deleteTemporaryAssetsDeletesAssetsWhenAgeIsGreaterThanZero()
 {
     $mock_config = $this->getMockBuilder(ImmutableConfig::class)->disableOriginalConstructor()->getMock();
     $age = 123456;
     $mock_config->expects($this->once())->method('get')->with('temporary_maximum_age')->willReturn($age);
     $this->configFactory->expects($this->once())->method('get')->with('system.file')->willReturn($mock_config);
     $mock_query = $this->getMock('\\Drupal\\Core\\Entity\\Query\\QueryInterface');
     $map = [['status', FILE_STATUS_PERMANENT, '<>'], ['changed', MOCK_TIMESTAMP - $age, '<']];
     $mock_query->expects($this->exactly(2))->method('condition')->will($this->returnValueMap($map));
     $mock_query->expects($this->once())->method('range')->with(0, 50)->will($this->returnSelf());
     $mock_asset_ids = [123, 456, 789];
     $mock_asset_ids = array_combine($mock_asset_ids, $mock_asset_ids);
     $mock_query->expects($this->once())->method('execute')->willReturn($mock_asset_ids);
     $mock_entity_storage = $this->getMock(EntityStorageInterface::class);
     $mock_entity_storage->expects($this->once())->method('getQuery')->willReturn($mock_query);
     $mock_assets = [];
     $log_map = [];
     foreach ($mock_asset_ids as $id) {
         $mock_asset = $this->getMockBuilder('\\Drupal\\embridge\\EmbridgeAssetEntityInterface')->disableOriginalConstructor()->getMock();
         $mock_asset->expects($this->once())->method('delete');
         $filename = 'Mock Asset ' . $id;
         $mock_asset->expects($this->once())->method('getFilename')->willReturn($filename);
         $mock_asset->expects($this->once())->method('id')->willReturn($id);
         $log_map[] = ['Embridge Asset "%filename" [%id] garbage collected during cron.', ['%filename' => $filename, '%id' => $id]];
         $mock_assets[$id] = $mock_asset;
     }
     $this->logger->expects($this->exactly(count($mock_asset_ids)))->method('notice')->will($this->returnValueMap($log_map));
     $mock_entity_storage->expects($this->once())->method('loadMultiple')->with($mock_asset_ids)->willReturn($mock_assets);
     $this->entityTypeManager->expects($this->once())->method('getStorage')->with('embridge_asset_entity')->willReturn($mock_entity_storage);
     $this->emdbHelper->deleteTemporaryAssets();
 }
Example #27
0
 /**
  * Test if error logger is called when compile is called more than once
  *
  * @expectedException Exception
  */
 public function testLogCallOnCompileMoreThanOnceNoDebug()
 {
     $loggerDecorator = $this->getDoppoInstance(false);
     $this->container->expects($this->once())->method('compile')->will($this->throwException(new Exception()));
     $this->logger->expects($this->never())->method('error');
     $loggerDecorator->compile();
 }
 /**
  * Test logged exception is the same as the thrown one in production mode
  */
 public function testCriticalExceptionStackTrace()
 {
     $thrownException = new \Exception('', 0);
     $this->_loggerMock->expects($this->once())->method('critical')->will($this->returnCallback(function (\Exception $loggedException) use($thrownException) {
         $this->assertSame($thrownException, $loggedException->getPrevious());
     }));
     $this->_errorProcessor->maskException($thrownException);
 }
 /**
  * @covers ::submitForm
  */
 function testSubmitForm()
 {
     $this->logger->expects($this->atLeastOnce())->method('info');
     $this->payment->expects($this->once())->method('delete');
     $form = [];
     $form_state = $this->getMock(FormStateInterface::class);
     $form_state->expects($this->once())->method('setRedirect')->with('<front>');
     $this->sut->submitForm($form, $form_state);
 }
 public function testGetStoreIdWithPermanentRuleException()
 {
     $countryCode = 'UA';
     $storeId = 2;
     $ex = new \Exception('Permanent Rule Exception');
     $this->country->expects($this->once())->method('getCountryCode')->willReturn($countryCode);
     $this->rule->expects($this->once())->method('getStoreId')->with($countryCode)->willReturn($storeId);
     $this->permanentRule->expects($this->once())->method('updateStoreId')->with($storeId, $countryCode)->willThrowException($ex);
     $this->logger->expects($this->once())->method('critical')->with($ex);
     $this->assertFalse($this->switcher->isInitialized());
     $this->assertEquals($storeId, $this->switcher->getStoreId());
     $this->assertTrue($this->switcher->isInitialized());
 }