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

added support for PHP8 #1212

Open
wants to merge 3 commits into
base: 5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4
- 8.0
- nightly

sudo: false

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
}
],
"require": {
"php": "^5.4|^7.0"
"php": "^7.2|^8.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"mockery/mockery": "~0.8",
"phpunit/phpunit": "~8.0 | ~9.2",
"mockery/mockery": "~1.3",
"guzzlehttp/guzzle": "~5.0"
},
"suggest": {
Expand Down
41 changes: 19 additions & 22 deletions tests/Authentication/AccessTokenMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
namespace Facebook\Tests\Authentication;

use Facebook\Authentication\AccessTokenMetadata;
use Facebook\Exceptions\FacebookSDKException;
use Facebook\Tests\BaseTestCase;

class AccessTokenMetadataTest extends \PHPUnit_Framework_TestCase
class AccessTokenMetadataTest extends BaseTestCase
{

protected $graphResponseData = [
Expand All @@ -51,7 +53,7 @@ class AccessTokenMetadataTest extends \PHPUnit_Framework_TestCase
],
];

public function testDatesGetCastToDateTime()
public function testDatesGetCastToDateTime(): void
{
$metadata = new AccessTokenMetadata($this->graphResponseData);

Expand All @@ -62,7 +64,7 @@ public function testDatesGetCastToDateTime()
$this->assertInstanceOf('DateTime', $issuedAt);
}

public function testAllTheGettersReturnTheProperValue()
public function testAllTheGettersReturnTheProperValue(): void
{
$metadata = new AccessTokenMetadata($this->graphResponseData);

Expand All @@ -81,56 +83,51 @@ public function testAllTheGettersReturnTheProperValue()
$this->assertEquals('1337', $metadata->getUserId());
}

/**
* @expectedException \Facebook\Exceptions\FacebookSDKException
*/
public function testInvalidMetadataWillThrow()
public function testInvalidMetadataWillThrow(): void
{
$this->expectException(FacebookSDKException::class);
new AccessTokenMetadata(['foo' => 'bar']);
}

public function testAnExpectedAppIdWillNotThrow()
public function testAnExpectedAppIdWillNotThrow(): void
{
$metadata = new AccessTokenMetadata($this->graphResponseData);
$metadata->validateAppId('123');
}

/**
* @expectedException \Facebook\Exceptions\FacebookSDKException
*/
public function testAnUnexpectedAppIdWillThrow()
public function testAnUnexpectedAppIdWillThrow(): void
{
$this->expectException(FacebookSDKException::class);

$metadata = new AccessTokenMetadata($this->graphResponseData);
$metadata->validateAppId('foo');
}

public function testAnExpectedUserIdWillNotThrow()
public function testAnExpectedUserIdWillNotThrow(): void
{
$metadata = new AccessTokenMetadata($this->graphResponseData);
$metadata->validateUserId('1337');
}

/**
* @expectedException \Facebook\Exceptions\FacebookSDKException
*/
public function testAnUnexpectedUserIdWillThrow()
public function testAnUnexpectedUserIdWillThrow(): void
{
$this->expectException(FacebookSDKException::class);

$metadata = new AccessTokenMetadata($this->graphResponseData);
$metadata->validateUserId('foo');
}

public function testAnActiveAccessTokenWillNotThrow()
public function testAnActiveAccessTokenWillNotThrow(): void
{
$this->graphResponseData['data']['expires_at'] = time() + 1000;
$metadata = new AccessTokenMetadata($this->graphResponseData);
$metadata->validateExpiration();
}

/**
* @expectedException \Facebook\Exceptions\FacebookSDKException
*/
public function testAnExpiredAccessTokenWillThrow()
public function testAnExpiredAccessTokenWillThrow(): void
{
$this->expectException(\Facebook\Exceptions\FacebookSDKException::class);

$this->graphResponseData['data']['expires_at'] = time() - 1000;
$metadata = new AccessTokenMetadata($this->graphResponseData);
$metadata->validateExpiration();
Expand Down
3 changes: 2 additions & 1 deletion tests/Authentication/AccessTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
namespace Facebook\Tests\Authentication;

use Facebook\Authentication\AccessToken;
use Facebook\Tests\BaseTestCase;

class AccessTokenTest extends \PHPUnit_Framework_TestCase
class AccessTokenTest extends BaseTestCase
{

public function testAnAccessTokenCanBeReturnedAsAString()
Expand Down
25 changes: 15 additions & 10 deletions tests/Authentication/OAuth2ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
use Facebook\Facebook;
use Facebook\FacebookApp;
use Facebook\Authentication\OAuth2Client;
use Facebook\Tests\BaseTestCase;

class OAuth2ClientTest extends \PHPUnit_Framework_TestCase
class OAuth2ClientTest extends BaseTestCase
{

/**
Expand All @@ -45,14 +46,14 @@ class OAuth2ClientTest extends \PHPUnit_Framework_TestCase
*/
protected $oauth;

protected function setUp()
protected function setUp(): void
{
$app = new FacebookApp('123', 'foo_secret');
$this->client = new FooFacebookClientForOAuth2Test();
$this->oauth = new OAuth2Client($app, $this->client, static::TESTING_GRAPH_VERSION);
}

public function testCanGetMetadataFromAnAccessToken()
public function testCanGetMetadataFromAnAccessToken(): void
{
$this->client->setMetadataResponse();

Expand All @@ -74,15 +75,19 @@ public function testCanGetMetadataFromAnAccessToken()
$this->assertEquals(static::TESTING_GRAPH_VERSION, $request->getGraphVersion());
}

public function testCanBuildAuthorizationUrl()
public function testCanBuildAuthorizationUrl(): void
{
$scope = ['email', 'base_foo'];
$authUrl = $this->oauth->getAuthorizationUrl('https://foo.bar', 'foo_state', $scope, ['foo' => 'bar'], '*');

$this->assertContains('*', $authUrl);
$this->assertStringContainsString('*', $authUrl);

$expectedUrl = 'https://www.facebook.com/' . static::TESTING_GRAPH_VERSION . '/dialog/oauth?';
$this->assertTrue(strpos($authUrl, $expectedUrl) === 0, 'Unexpected base authorization URL returned from getAuthorizationUrl().');
$this->assertSame(
strpos($authUrl, $expectedUrl),
0,
'Unexpected base authorization URL returned from getAuthorizationUrl().'
);

$params = [
'client_id' => '123',
Expand All @@ -93,11 +98,11 @@ public function testCanBuildAuthorizationUrl()
'foo' => 'bar',
];
foreach ($params as $key => $value) {
$this->assertContains($key . '=' . urlencode($value), $authUrl);
$this->assertStringContainsString($key . '=' . urlencode($value), $authUrl);
}
}

public function testCanGetAccessTokenFromCode()
public function testCanGetAccessTokenFromCode(): void
{
$this->client->setAccessTokenResponse();

Expand All @@ -122,7 +127,7 @@ public function testCanGetAccessTokenFromCode()
$this->assertEquals(static::TESTING_GRAPH_VERSION, $request->getGraphVersion());
}

public function testCanGetLongLivedAccessToken()
public function testCanGetLongLivedAccessToken(): void
{
$this->client->setAccessTokenResponse();

Expand All @@ -143,7 +148,7 @@ public function testCanGetLongLivedAccessToken()
$this->assertEquals($expectedParams, $request->getParams());
}

public function testCanGetCodeFromLongLivedAccessToken()
public function testCanGetCodeFromLongLivedAccessToken(): void
{
$this->client->setCodeResponse();

Expand Down
12 changes: 12 additions & 0 deletions tests/BaseTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Facebook\Tests;

use Mockery\Adapter\Phpunit\MockeryTestCase;

class BaseTestCase extends MockeryTestCase
{

}
5 changes: 3 additions & 2 deletions tests/Exceptions/FacebookResponseExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\Exceptions\FacebookResponseException;
use Facebook\Tests\BaseTestCase;

class FacebookResponseExceptionTest extends \PHPUnit_Framework_TestCase
class FacebookResponseExceptionTest extends BaseTestCase
{

/**
* @var FacebookRequest
*/
protected $request;

protected function setUp()
protected function setUp(): void
{
$this->request = new FacebookRequest(new FacebookApp('123', 'foo'));
}
Expand Down
8 changes: 3 additions & 5 deletions tests/FacebookAppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@

use Facebook\FacebookApp;

class FacebookAppTest extends \PHPUnit_Framework_TestCase
class FacebookAppTest extends BaseTestCase
{
/**
* @var FacebookApp
*/
private $app;

protected function setUp()
protected function setUp(): void
{
$this->app = new FacebookApp('id', 'secret');
}
Expand Down Expand Up @@ -64,11 +64,9 @@ public function testSerialization()
$this->assertEquals('secret', $newApp->getSecret());
}

/**
* @expectedException \Facebook\Exceptions\FacebookSDKException
*/
public function testOverflowIntegersWillThrow()
{
$this->expectException(\Facebook\Exceptions\FacebookSDKException::class);
new FacebookApp(PHP_INT_MAX + 1, "foo");
}

Expand Down
24 changes: 7 additions & 17 deletions tests/FacebookBatchRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
use Facebook\FacebookBatchRequest;
use Facebook\FileUpload\FacebookFile;

class FacebookBatchRequestTest extends \PHPUnit_Framework_TestCase
class FacebookBatchRequestTest extends BaseTestCase
{
/**
* @var FacebookApp
*/
private $app;

protected function setUp()
protected function setUp(): void
{
$this->app = new FacebookApp('123', 'foo_secret');
}
Expand Down Expand Up @@ -80,31 +80,25 @@ public function testRequestWithAppOnlyWillFallbackToBatchDefaults()
$this->assertRequestContainsAppAndToken($request, $customApp, 'foo_token');
}

/**
* @expectedException \Facebook\Exceptions\FacebookSDKException
*/
public function testWillThrowWhenNoThereIsNoAppFallback()
{
$this->expectException(\Facebook\Exceptions\FacebookSDKException::class);
$batchRequest = new FacebookBatchRequest();

$batchRequest->addFallbackDefaults(new FacebookRequest(null, 'foo_token'));
}

/**
* @expectedException \Facebook\Exceptions\FacebookSDKException
*/
public function testWillThrowWhenNoThereIsNoAccessTokenFallback()
{
$this->expectException(\Facebook\Exceptions\FacebookSDKException::class);
$request = new FacebookBatchRequest();

$request->addFallbackDefaults(new FacebookRequest($this->app));
}

/**
* @expectedException \InvalidArgumentException
*/
public function testAnInvalidTypeGivenToAddWillThrow()
{
$this->expectException(\InvalidArgumentException::class);
$request = new FacebookBatchRequest();

$request->add('foo');
Expand Down Expand Up @@ -168,21 +162,17 @@ public function testRequestsCanBeInjectedIntoConstructor()
$this->assertRequestsMatch($requests, $formattedRequests);
}

/**
* @expectedException \Facebook\Exceptions\FacebookSDKException
*/
public function testAZeroRequestCountWithThrow()
{
$this->expectException(\Facebook\Exceptions\FacebookSDKException::class);
$batchRequest = new FacebookBatchRequest($this->app, [], 'foo_token');

$batchRequest->validateBatchRequestCount();
}

/**
* @expectedException \Facebook\Exceptions\FacebookSDKException
*/
public function testMoreThanFiftyRequestsWillThrow()
{
$this->expectException(\Facebook\Exceptions\FacebookSDKException::class);
$batchRequest = $this->createBatchRequest();

$this->createAndAppendRequestsTo($batchRequest, 51);
Expand Down
4 changes: 2 additions & 2 deletions tests/FacebookBatchResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
use Facebook\FacebookBatchRequest;
use Facebook\FacebookBatchResponse;

class FacebookBatchResponseTest extends \PHPUnit_Framework_TestCase
class FacebookBatchResponseTest extends BaseTestCase
{
/**
* @var \Facebook\FacebookApp
Expand All @@ -41,7 +41,7 @@ class FacebookBatchResponseTest extends \PHPUnit_Framework_TestCase
*/
protected $request;

protected function setUp()
protected function setUp(): void
{
$this->app = new FacebookApp('123', 'foo_secret');
$this->request = new FacebookRequest(
Expand Down
Loading