Guest User

Untitled

a guest
Nov 10th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Drupaldata_provider;
  4.  
  5. use Drupaldata_providerSecurityDataProviderCrypt;
  6. use GuzzleHttpExceptionGuzzleException;
  7. use GuzzleHttpClientInterface;
  8. use DrupalCoreCacheCacheBackendInterface;
  9.  
  10.  
  11.  
  12. /**
  13. * DataProviderServic.
  14. *
  15. * @ingroup data_provider
  16. *
  17. * @group data_provider
  18. */
  19. class DataProviderService {
  20.  
  21.  
  22. public $baseUri;
  23.  
  24.  
  25. protected $username;
  26.  
  27.  
  28. protected $password;
  29.  
  30. /**
  31. * The HTTP client to fetch the feed data with.
  32. *
  33. * @var GuzzleHttpClientInterface
  34. */
  35. protected $httpClient;
  36.  
  37. /**
  38. * The cache.default cache backend.
  39. *
  40. * @var DrupalCoreCacheCacheBackendInterface
  41. */
  42. protected $cacheBackend;
  43.  
  44. /**
  45. * Constructs a database object.
  46. *
  47. * @param GuzzleHttpClientInterface $http_client
  48. * The Guzzle HTTP client.
  49. * @param DrupalCoreCacheCacheBackendInterface $cache_backend
  50. * The cache object associated with the default bin.
  51. */
  52. public function __construct(ClientInterface $http_client, CacheBackendInterface $cache_backend) {
  53. $this->httpClient = $http_client;
  54. $this->cacheBackend = $cache_backend;
  55. $this->baseUri = Drupal::config('data_provider.settings')->get('base_uri');
  56. $this->username = Drupal::config('data_provider.settings')
  57. ->get('username');
  58. $this->password = Drupal::config('data_provider.settings')
  59. ->get('password');
  60. }
  61.  
  62.  
  63. /**
  64. * {@inheritdoc}
  65. */
  66. public static function create(ContainerInterface $container) {
  67. // Forms that require a Drupal service or a custom service should access
  68. // the service using dependency injection.
  69. // @link https://www.drupal.org/node/2203931.
  70. // Those services are passed in the $container through the static create
  71. // method.
  72. return new static(
  73. $container->get('http_client'),
  74. $container->get('cache.default')
  75. );
  76. }
  77.  
  78.  
  79. /**
  80. * Create a formatted request based on options provided
  81. *
  82. * @param $url
  83. * Requested URl.
  84. * @param array $options
  85. * Query parameter options.
  86. * @param bool $reset
  87. * Rest the cache.
  88. *
  89. * @return bool|string
  90. */
  91. public function doRequest($url, $options = array(), $reset = FALSE) {
  92. // request from api
  93. return $content;
  94. }
  95.  
  96. /**
  97. * Return the data from the API in json format.
  98. *
  99. * @return bool|mixed
  100. */
  101. public function getSubscriptions() {
  102. // do_request and from the api and return info
  103. return $subscriptions;
  104. }
  105.  
  106.  
  107.  
  108. }
  109.  
  110. <?php
  111.  
  112. namespace Drupaldata_providerTestsUnit;
  113.  
  114. use DrupalTestsUnitTestCase;
  115. use Drupaldata_providerDataProviderService;
  116.  
  117. /**
  118. * DataProviderServic unit test.
  119. *
  120. * @ingroup data_provider
  121. *
  122. * @group data_provider
  123. */
  124. class DataProviderServiceTest extends UnitTestCase {
  125.  
  126. /**
  127. * Very simple test of DataProviderService::getSubscriptions().
  128. * @todo write dataprovider tests.
  129. */
  130. public function testGetSubscriptions() {
  131. $dp = new DataProviderService();
  132. $subs = $dp->getSubscriptions();
  133. $this->assertEquals(TRUE, TRUE);
  134. }
  135.  
  136. }
  137.  
  138. PHPUnit 4.8.36 by Sebastian Bergmann and contributors.
  139.  
  140. Testing
  141. E
  142.  
  143. Time: 42.35 seconds, Memory: 610.25MB
  144.  
  145. There was 1 error:
  146.  
  147. 1) Drupaldata_providerTestsUnitDataProviderServiceTest::testGetSubscriptions
  148. Argument 1 passed to Drupaldata_providerDataProviderService::__construct() must be an instance of GuzzleHttpClientInterface, none given, called in /var/www/drupal8/docroot/modules/custom/data_provider/tests/src/Unit/DataProviderServiceTest.php on line 22 and defined
  149.  
  150. /var/www/drupal8/docroot/vendor/symfony/phpunit-bridge/DeprecationErrorHandler.php:73
  151. /var/www/drupal8/docroot/modules/custom/data_provider/src/DataProviderService.php:63
  152. /var/www/drupal8/docroot/modules/custom/data_provider/tests/src/Unit/DataProviderServiceTest.php:22
Add Comment
Please, Sign In to add comment