Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Drupaldata_provider;
- use Drupaldata_providerSecurityDataProviderCrypt;
- use GuzzleHttpExceptionGuzzleException;
- use GuzzleHttpClientInterface;
- use DrupalCoreCacheCacheBackendInterface;
- /**
- * DataProviderServic.
- *
- * @ingroup data_provider
- *
- * @group data_provider
- */
- class DataProviderService {
- public $baseUri;
- protected $username;
- protected $password;
- /**
- * The HTTP client to fetch the feed data with.
- *
- * @var GuzzleHttpClientInterface
- */
- protected $httpClient;
- /**
- * The cache.default cache backend.
- *
- * @var DrupalCoreCacheCacheBackendInterface
- */
- protected $cacheBackend;
- /**
- * Constructs a database object.
- *
- * @param GuzzleHttpClientInterface $http_client
- * The Guzzle HTTP client.
- * @param DrupalCoreCacheCacheBackendInterface $cache_backend
- * The cache object associated with the default bin.
- */
- public function __construct(ClientInterface $http_client, CacheBackendInterface $cache_backend) {
- $this->httpClient = $http_client;
- $this->cacheBackend = $cache_backend;
- $this->baseUri = Drupal::config('data_provider.settings')->get('base_uri');
- $this->username = Drupal::config('data_provider.settings')
- ->get('username');
- $this->password = Drupal::config('data_provider.settings')
- ->get('password');
- }
- /**
- * {@inheritdoc}
- */
- public static function create(ContainerInterface $container) {
- // Forms that require a Drupal service or a custom service should access
- // the service using dependency injection.
- // @link https://www.drupal.org/node/2203931.
- // Those services are passed in the $container through the static create
- // method.
- return new static(
- $container->get('http_client'),
- $container->get('cache.default')
- );
- }
- /**
- * Create a formatted request based on options provided
- *
- * @param $url
- * Requested URl.
- * @param array $options
- * Query parameter options.
- * @param bool $reset
- * Rest the cache.
- *
- * @return bool|string
- */
- public function doRequest($url, $options = array(), $reset = FALSE) {
- // request from api
- return $content;
- }
- /**
- * Return the data from the API in json format.
- *
- * @return bool|mixed
- */
- public function getSubscriptions() {
- // do_request and from the api and return info
- return $subscriptions;
- }
- }
- <?php
- namespace Drupaldata_providerTestsUnit;
- use DrupalTestsUnitTestCase;
- use Drupaldata_providerDataProviderService;
- /**
- * DataProviderServic unit test.
- *
- * @ingroup data_provider
- *
- * @group data_provider
- */
- class DataProviderServiceTest extends UnitTestCase {
- /**
- * Very simple test of DataProviderService::getSubscriptions().
- * @todo write dataprovider tests.
- */
- public function testGetSubscriptions() {
- $dp = new DataProviderService();
- $subs = $dp->getSubscriptions();
- $this->assertEquals(TRUE, TRUE);
- }
- }
- PHPUnit 4.8.36 by Sebastian Bergmann and contributors.
- Testing
- E
- Time: 42.35 seconds, Memory: 610.25MB
- There was 1 error:
- 1) Drupaldata_providerTestsUnitDataProviderServiceTest::testGetSubscriptions
- 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
- /var/www/drupal8/docroot/vendor/symfony/phpunit-bridge/DeprecationErrorHandler.php:73
- /var/www/drupal8/docroot/modules/custom/data_provider/src/DataProviderService.php:63
- /var/www/drupal8/docroot/modules/custom/data_provider/tests/src/Unit/DataProviderServiceTest.php:22
Add Comment
Please, Sign In to add comment