Inheritance: use trait Webiny\Component\StdLib\StdLibTrait
 public function testGetInstance()
 {
     TwitterOAuth::setConfig(realpath(__DIR__ . '/ExampleConfig.yaml'));
     Request::getInstance()->setCurrentUrl('http://admin.w3.com/batman-is-better-than-superman/?batman=one&superman=two');
     // other tests might change the library, which can cause this test to fail
     Bridge::setLibrary('\\Webiny\\Component\\TwitterOAuth\\Bridge\\League\\TwitterOAuth');
     $instance = TwitterOAuthLoader::getInstance('MyTwitterApp');
     $this->assertInstanceOf('\\Webiny\\Component\\TwitterOAuth\\TwitterOAuth', $instance);
 }
Esempio n. 2
0
 /**
  * Returns an instance to TwitterOAuth server based on the current configuration.
  *
  * @param string $key Unique identifier for the TwitterOAuth server that you wish to get.
  *
  * @return array|TwitterOAuth
  * @throws TwitterOAuthException
  */
 public static function getInstance($key)
 {
     if (isset(self::$instances[$key])) {
         return self::$instances;
     }
     $config = TwitterOAuth::getConfig()->get($key, false);
     if (!$config) {
         throw new TwitterOAuthException('Unable to read "TwitterOAuth.' . $key . '" configuration.');
     }
     if (strpos($config->RedirectUri, 'http://') !== false || strpos($config->RedirectUri, 'https://') !== false) {
         $redirectUri = $config->RedirectUri;
     } else {
         $redirectUri = self::httpRequest()->getCurrentUrl(true)->setPath($config->RedirectUri)->setQuery('')->val();
     }
     $instance = \Webiny\Component\TwitterOAuth\Bridge\TwitterOAuth::getInstance($config->ClientId, $config->ClientSecret, $redirectUri);
     return new TwitterOAuth($instance);
 }
Esempio n. 3
0
 /**
  * @expectedException \Webiny\Component\TwitterOAuth\Bridge\TwitterOAuthException
  */
 public function testGetInstanceException()
 {
     TwitterOAuth::setLibrary('\\Webiny\\Component\\TwitterOAuth\\Tests\\Mocks\\FakeBridgeMock');
     TwitterOAuth::getInstance('client', 'secret', 'redirect');
 }