diff --git a/modules/salesforce_pull/tests/src/Unit/PullBaseTest.php b/modules/salesforce_pull/tests/src/Unit/PullBaseTest.php index 390587b1d4bf2f0bbbb26625b6bc1e24c3ee16a8..703c91301b9f1a42acf42bc826be54f8f58d7496 100644 --- a/modules/salesforce_pull/tests/src/Unit/PullBaseTest.php +++ b/modules/salesforce_pull/tests/src/Unit/PullBaseTest.php @@ -7,6 +7,7 @@ use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Logger\LoggerChannelFactoryInterface; +use Drupal\Core\StringTranslation\Translator\TranslationInterface; use Drupal\salesforce_mapping\Entity\MappedObjectInterface; use Drupal\salesforce_mapping\Entity\SalesforceMappingInterface; use Drupal\salesforce_pull\Plugin\QueueWorker\PullBase; @@ -154,13 +155,21 @@ class PullBaseTest extends UnitTestCase { * createEntity() method executes as expected - that must be in a separate test */ public function testProcessItemCreate() { + //mock StringTranslation service + $prophecy = $this->prophesize(TranslationInterface::CLASS); + $this->translation = $prophecy->reveal(); + // mock EntityNotFoundException $prophecy = $this->prophesize(EntityNotFoundException::CLASS); + $prophecy->getStringTranslation()->willReturn($this->translation); + print "pre exception reveal\n"; $my_exception = $prophecy->reveal(); + print "post exception reveal\n"; // mock mapped object EntityStorage object $prophecy = $this->prophesize(EntityStorageBase::CLASS); $prophecy->loadByProperties(Argument::any())->willThrow($my_exception); + //$prophecy->loadByProperties(Argument::any())->willThrow(new EntityNotFoundException([], 'test')); $this->entityStorage = $prophecy->reveal(); // mock EntityTypeManagerInterface diff --git a/salesforce.services.yml b/salesforce.services.yml index aa6ca8eeb15f2e1ec79473db6f9d3b2d60e7f312..58dad7f83fbf1b1209d68d8e9fa81f0b8334dcd0 100644 --- a/salesforce.services.yml +++ b/salesforce.services.yml @@ -1,4 +1,4 @@ services: salesforce.client: class: Drupal\salesforce\Rest\RestClient - arguments: ['@http_client', '@config.factory', '@url_generator', '@state', '@cache.default'] + arguments: ['@http_client', '@config.factory', '@url', '@state', '@cache.default'] diff --git a/src/Rest/RestClient.php b/src/Rest/RestClient.php index 74ec5336c6abaf3867a886224dd4049fe931d188..6f555749843fe3d1900bb18b108622d07a4678c3 100644 --- a/src/Rest/RestClient.php +++ b/src/Rest/RestClient.php @@ -5,19 +5,18 @@ namespace Drupal\salesforce\Rest; use Drupal\Component\Serialization\Json; use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\UrlHelper; +use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\Routing\UrlGeneratorInterface; use Drupal\Core\State\StateInterface; use Drupal\Core\Url; -use Drupal\salesforce\SFID; -use Drupal\salesforce\SObject; use Drupal\salesforce\SelectQuery; use Drupal\salesforce\SelectQueryResult; +use Drupal\salesforce\SFID; +use Drupal\salesforce\SObject; use GuzzleHttp\ClientInterface; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\Response; use Symfony\Component\DependencyInjection\ContainerInterface; -use Drupal\Core\Cache\CacheBackendInterface; /** * Objects, properties, and methods to communicate with the Salesforce REST API. @@ -27,7 +26,7 @@ class RestClient { public $response; protected $httpClient; protected $configFactory; - protected $urlGenerator; + protected $url; private $config; private $configEditable; private $state; @@ -43,10 +42,10 @@ class RestClient { * @param \Guzzle\Http\ClientInterface $http_client * The config factory. */ - public function __construct(ClientInterface $http_client, ConfigFactoryInterface $config_factory, UrlGeneratorInterface $url_generator, StateInterface $state, CacheBackendInterface $cache) { + public function __construct(ClientInterface $http_client, ConfigFactoryInterface $config_factory, Url $url, StateInterface $state, CacheBackendInterface $cache) { $this->configFactory = $config_factory; $this->httpClient = $http_client; - $this->urlGenerator = $url_generator; + $this->url = $url; $this->config = $this->configFactory->get('salesforce.settings'); $this->configEditable = $this->configFactory->getEditable('salesforce.settings'); $this->state = $state; @@ -73,7 +72,7 @@ class RestClient { * @param string $method * Method to initiate the call, such as GET or POST. Defaults to GET. * @param bool $returnObject - * If true, return a Drupal\salesforce\Rest\RestResponse; + * If true, return a Drupal\salesforce\Rest\RestResponse; * Otherwise, return json-decoded response body only. * Defaults to FALSE for backwards compatibility. * @@ -179,7 +178,7 @@ class RestClient { /** * Extract normalized error information from a RequestException * - * @param RequestException $e + * @param RequestException $e * @return array * Error array with keys: * * message @@ -427,7 +426,7 @@ class RestClient { * @see Drupal\salesforce\Controller\SalesforceController */ public function getAuthCallbackUrl() { - return Url::fromRoute('salesforce.oauth_callback', [], [ + return $this->url->fromRoute('salesforce.oauth_callback', [], [ 'absolute' => TRUE, 'https' => TRUE, ]); @@ -718,11 +717,11 @@ class RestClient { * Object type name, E.g., Contact, Account. * * @param int $start - * unix timestamp for older timeframe for updates. + * unix timestamp for older timeframe for updates. * Defaults to "-29 days" if empty. * * @param int $end - * unix timestamp for end of timeframe for updates. + * unix timestamp for end of timeframe for updates. * Defaults to now if empty * * @return array @@ -741,12 +740,12 @@ class RestClient { $start = strtotime('-29 days'); } $start = urlencode(gmdate(DATE_ATOM, $start)); - + if (empty($end)) { $end = time(); } $end = urlencode(gmdate(DATE_ATOM, $end)); - + return $this->apiCall("sobjects/{$name}/updated/?start=$start&end=$end"); } @@ -796,7 +795,7 @@ class RestClient { * @param string $name * Object type name, E.g., Contact, Account. * - * @param string $devname + * @param string $devname * RecordType DeveloperName, e.g. Donation, Membership, etc. * * @return SFID @@ -813,9 +812,9 @@ class RestClient { } /** - * Utility function to determine object type for given SFID + * Utility function to determine object type for given SFID * - * @param SFID $id + * @param SFID $id * @return string * @throws Exception if SFID doesn't match any object type */