Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.

Commit bd55939

Browse files
moved runtime exception to native TypeError
1 parent 13fa0b9 commit bd55939

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/Facebook/Facebook.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,6 @@ public function __construct(array $config = [])
158158
$enableBeta = isset($config['enable_beta_mode']) && $config['enable_beta_mode'] === true;
159159
$this->client = new FacebookClient($httpClientHandler, $enableBeta);
160160

161-
if (isset($config['url_detection_handler'])) {
162-
if ($config['url_detection_handler'] instanceof UrlDetectionInterface) {
163-
$this->urlDetectionHandler = $config['url_detection_handler'];
164-
} else {
165-
throw new \InvalidArgumentException('The url_detection_handler must be an instance of Facebook\Url\UrlDetectionInterface');
166-
}
167-
}
168-
169161
if (isset($config['pseudo_random_string_generator'])) {
170162
if ($config['pseudo_random_string_generator'] instanceof PseudoRandomStringGeneratorInterface) {
171163
$this->pseudoRandomStringGenerator = $config['pseudo_random_string_generator'];
@@ -191,6 +183,7 @@ public function __construct(array $config = [])
191183
throw new \InvalidArgumentException('The persistent_data_handler must be set to "session", "memory", or be an instance of Facebook\PersistentData\PersistentDataInterface');
192184
}
193185
}
186+
$this->setUrlDetectionHandler($config['url_detection_handler'] ?: new FacebookUrlDetectionHandler());
194187

195188
if (isset($config['default_access_token'])) {
196189
$this->setDefaultAccessToken($config['default_access_token']);
@@ -257,13 +250,19 @@ public function getLastResponse()
257250
*/
258251
public function getUrlDetectionHandler()
259252
{
260-
if (!$this->urlDetectionHandler instanceof UrlDetectionInterface) {
261-
$this->urlDetectionHandler = new FacebookUrlDetectionHandler();
262-
}
263-
264253
return $this->urlDetectionHandler;
265254
}
266255

256+
/**
257+
* Changes the URL detection handler.
258+
*
259+
* @param UrlDetectionInterface $urlDetectionHandler
260+
*/
261+
private function setUrlDetectionHandler(UrlDetectionInterface $urlDetectionHandler)
262+
{
263+
$this->urlDetectionHandler = $urlDetectionHandler;
264+
}
265+
267266
/**
268267
* Returns the default AccessToken entity.
269268
*

tests/FacebookTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,14 @@ public function testPersistentDataHandlerCanBeForced()
176176
);
177177
}
178178

179-
/**
180-
* @expectedException \InvalidArgumentException
181-
*/
182179
public function testSettingAnInvalidUrlHandlerThrows()
183180
{
181+
$expectedException = (PHP_MAJOR_VERSION > 5 && class_exists('TypeError'))
182+
? 'TypeError'
183+
: 'PHPUnit_Framework_Error';
184+
185+
$this->setExpectedException($expectedException);
186+
184187
$config = array_merge($this->config, [
185188
'url_detection_handler' => 'foo_handler',
186189
]);

0 commit comments

Comments
 (0)