Skip to content

Commit

Permalink
update required php versions. Update PHPUnit. Use Mockery and update …
Browse files Browse the repository at this point in the history
…tests
  • Loading branch information
Joel Butcher committed Jul 24, 2021
1 parent 6de3555 commit 8052aba
Show file tree
Hide file tree
Showing 30 changed files with 194 additions and 202 deletions.
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
{
"name": "facebook/graph-sdk",
"name": "joelbutcher/facebook-graph-sdk",
"description": "Facebook SDK for PHP",
"keywords": ["facebook", "sdk"],
"keywords": ["facebook", "sdk", "php"],
"type": "library",
"homepage": "https://github.com/facebook/php-graph-sdk",
"homepage": "https://github.com/joelbutcher/facebook-graph-sdk",
"license": "Facebook Platform",
"authors": [
{
"name": "Facebook",
"homepage": "https://github.com/facebook/php-graph-sdk/contributors"
"name": "Joel Butcher",
"homepage": "https://github.com/joelbutcher/facebook-graph-sdk/contributors"
}
],
"config": {
"sort-packages": true
},
"require": {
"php": "^7.1",
"php": "^7.3 || ^8.0",
"psr/http-message": "^1.0",
"php-http/client-implementation": "^1.0",
"php-http/httplug": "^1.0",
"php-http/discovery": "^1.0",

"php-http/message": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^6.2",
"mockery/mockery": "^1.0",
"phpunit/phpunit": "^9.3",
"php-http/guzzle6-adapter": "^1.0"
},
"autoload": {
Expand Down
7 changes: 3 additions & 4 deletions tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ApplicationTest extends TestCase
*/
private $app;

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

/**
* @expectedException \Facebook\Exception\SDKException
*/
public function testOverflowIntegersWillThrow()
{
$this->expectException(\Facebook\Exception\SDKException::class);

new Application(PHP_INT_MAX + 1, "foo");
}

Expand Down
16 changes: 4 additions & 12 deletions tests/Authentication/AccessTokenMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,9 @@ public function testAllTheGettersReturnTheProperValue()
$this->assertEquals('1337', $metadata->getUserId());
}

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

Expand All @@ -96,11 +94,9 @@ public function testAnExpectedAppIdWillNotThrow()
$this->assertTrue(true);
}

/**
* @expectedException \Facebook\Exception\SDKException
*/
public function testAnUnexpectedAppIdWillThrow()
{
$this->expectException(\Facebook\Exception\SDKException::class);
$metadata = new AccessTokenMetadata($this->graphResponseData);
$metadata->validateAppId('foo');

Expand All @@ -115,11 +111,9 @@ public function testAnExpectedUserIdWillNotThrow()
$this->assertTrue(true);
}

/**
* @expectedException \Facebook\Exception\SDKException
*/
public function testAnUnexpectedUserIdWillThrow()
{
$this->expectException(\Facebook\Exception\SDKException::class);
$metadata = new AccessTokenMetadata($this->graphResponseData);
$metadata->validateUserId('foo');
}
Expand All @@ -133,11 +127,9 @@ public function testAnActiveAccessTokenWillNotThrow()
$this->assertTrue(true);
}

/**
* @expectedException \Facebook\Exception\SDKException
*/
public function testAnExpiredAccessTokenWillThrow()
{
$this->expectException(\Facebook\Exception\SDKException::class);
$this->graphResponseData['data']['expires_at'] = time() - 1000;
$metadata = new AccessTokenMetadata($this->graphResponseData);
$metadata->validateExpiration();
Expand Down
6 changes: 3 additions & 3 deletions tests/Authentication/OAuth2ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class OAuth2ClientTest extends TestCase
*/
protected $oauth;

protected function setUp()
protected function setUp(): void
{
$app = new Application('123', 'foo_secret');
$this->client = new FooClientForOAuth2Test();
Expand Down Expand Up @@ -81,7 +81,7 @@ public function testCanBuildAuthorizationUrl()
$scope = ['email', 'base_foo'];
$authUrl = $this->oauth->getAuthorizationUrl('https://foo.bar', 'foo_state', $scope, ['foo' => 'bar'], '*');

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

$expectedUrl = 'https://www.facebook.com/' . static::TESTING_GRAPH_VERSION . '/dialog/oauth?';
$this->assertStringStartsWith($expectedUrl, $authUrl, 'Unexpected base authorization URL returned from getAuthorizationUrl().');
Expand All @@ -95,7 +95,7 @@ public function testCanBuildAuthorizationUrl()
'foo' => 'bar',
];
foreach ($params as $key => $value) {
$this->assertContains($key . '=' . urlencode($value), $authUrl);
$this->assertStringContainsStringIgnoringCase($key . '=' . urlencode($value), $authUrl);
}
}

Expand Down
27 changes: 11 additions & 16 deletions tests/BatchRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class BatchRequestTest extends TestCase
*/
private $app;

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

/**
* @expectedException \Facebook\Exception\SDKException
*/
public function testWillThrowWhenNoThereIsNoAppFallback()
{
$this->expectException(\Facebook\Exception\SDKException::class);

$batchRequest = new BatchRequest();

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

/**
* @expectedException \Facebook\Exception\SDKException
*/
public function testWillThrowWhenNoThereIsNoAccessTokenFallback()
{
$this->expectException(\Facebook\Exception\SDKException::class);

$request = new BatchRequest();

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

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

$request = new BatchRequest();

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

/**
* @expectedException \Facebook\Exception\SDKException
*/
public function testAZeroRequestCountWithThrow()
{
$this->expectException(\Facebook\Exception\SDKException::class);

$batchRequest = new BatchRequest($this->app, [], 'foo_token');

$batchRequest->validateBatchRequestCount();
}

/**
* @expectedException \Facebook\Exception\SDKException
*/
public function testMoreThanFiftyRequestsWillThrow()
{
$this->expectException(\Facebook\Exception\SDKException::class);

$batchRequest = $this->createBatchRequest();

$this->createAndAppendRequestsTo($batchRequest, 51);
Expand Down
2 changes: 1 addition & 1 deletion tests/BatchResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class BatchResponseTest extends TestCase
*/
protected $request;

protected function setUp()
protected function setUp(): void
{
$this->app = new Application('123', 'foo_secret');
$this->request = new Request(
Expand Down
21 changes: 10 additions & 11 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ClientTest extends TestCase
*/
public static $testClient;

protected function setUp()
protected function setUp(): void
{
$this->fbApp = new Application('id', 'shhhh!');
$this->fbClient = new Client(new MyFooHttpClient());
Expand Down Expand Up @@ -163,12 +163,12 @@ public function testABatchRequestWillProperlyBatchFiles()

$this->assertEquals(Client::BASE_GRAPH_VIDEO_URL, $url);
$this->assertEquals('POST', $method);
$this->assertContains('multipart/form-data; boundary=', $headers['Content-Type']);
$this->assertContains('Content-Disposition: form-data; name="batch"', $body);
$this->assertContains('Content-Disposition: form-data; name="include_headers"', $body);
$this->assertContains('"name":0,"attached_files":', $body);
$this->assertContains('"name":1,"attached_files":', $body);
$this->assertContains('"; filename="foo.txt"', $body);
$this->assertStringContainsStringIgnoringCase('multipart/form-data; boundary=', $headers['Content-Type']);
$this->assertStringContainsStringIgnoringCase('Content-Disposition: form-data; name="batch"', $body);
$this->assertStringContainsStringIgnoringCase('Content-Disposition: form-data; name="include_headers"', $body);
$this->assertStringContainsStringIgnoringCase('"name":0,"attached_files":', $body);
$this->assertStringContainsStringIgnoringCase('"name":1,"attached_files":', $body);
$this->assertStringContainsStringIgnoringCase('"; filename="foo.txt"', $body);
}

public function testARequestOfParamsWillBeUrlEncoded()
Expand All @@ -189,14 +189,13 @@ public function testARequestWithFilesWillBeMultipart()

$headersSent = $response->getRequest()->getHeaders();

$this->assertContains('multipart/form-data; boundary=', $headersSent['Content-Type']);
$this->assertStringContainsStringIgnoringCase('multipart/form-data; boundary=', $headersSent['Content-Type']);
}

/**
* @expectedException \Facebook\Exception\SDKException
*/
public function testARequestValidatesTheAccessTokenWhenOneIsNotProvided()
{
$this->expectException(\Facebook\Exception\SDKException::class);

$fbRequest = new Request($this->fbApp, null, 'GET', '/foo');
$this->fbClient->sendRequest($fbRequest);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Exception/ResponseExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ResponseExceptionTest extends TestCase
*/
protected $request;

protected function setUp()
protected function setUp(): void
{
$this->request = new Request(new Application('123', 'foo'));
}
Expand Down
Loading

0 comments on commit 8052aba

Please sign in to comment.