Skip to content

Commit e65e9dd

Browse files
authored
Merge pull request #41 from edipoReboucas/fix-phpunit-php8.1
Fix test issues with phpunit 9 and php 8 and 8.1
2 parents 0e40359 + edf6747 commit e65e9dd

20 files changed

+86
-37
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ vendor/
33
.php-cs.cache
44
guzzle_environments/*/vendor/
55
guzzle_environments/*/composer.lock
6+
guzzle_environments/*/.phpunit.result.cache
67
composer.lock
78
internal_examples/
9+
.idea

.travis.yml

+10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ php:
1111
- 7.2
1212
- 7.3
1313
- 7.4
14+
- 8.0
15+
- 8.1
1416

1517
install:
1618
- cd guzzle_environments/${GUZZLE_VERSION}
@@ -62,3 +64,11 @@ matrix:
6264
env: GUZZLE_VERSION=4
6365
- php: 7.4
6466
env: GUZZLE_VERSION=5
67+
- php: 8.0
68+
env: GUZZLE_VERSION=4
69+
- php: 8.0
70+
env: GUZZLE_VERSION=5
71+
- php: 8.1
72+
env: GUZZLE_VERSION=4
73+
- php: 8.1
74+
env: GUZZLE_VERSION=5

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Guzzle OAuth 2.0 Subscriber
22

3-
> Tested with Guzzle 4, 5, 6, 7 and PHP 5.4, 5.5, 5.6, 7.0, 7.1, 7.2, 7.3 and 7.4.
3+
> Tested with Guzzle 4, 5, 6, 7 and PHP 5.4, 5.5, 5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0 and 8.1.
44
55
This is an OAuth 2.0 client for Guzzle which aims to be 100% compatible with Guzzle 4, 5, 6, 7 and all future versions within a single package.
66
Although I love Guzzle, its interfaces keep changing, causing massive breaking changes every 12 months or so, so I have created this package

guzzle_environments/4/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"require-dev": {
1010
"guzzlehttp/guzzle": "~4",
11-
"phpunit/phpunit": ">=4 <8",
11+
"phpunit/phpunit": ">=4 <10",
1212
"doctrine/cache": "~1.5"
1313
},
1414
"autoload": {

guzzle_environments/5/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"require-dev": {
1010
"guzzlehttp/guzzle": "~5",
11-
"phpunit/phpunit": ">=4 <8",
11+
"phpunit/phpunit": ">=4 <10",
1212
"doctrine/cache": "~1.5"
1313
},
1414
"autoload": {

guzzle_environments/6/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"require-dev": {
1010
"guzzlehttp/guzzle": "~6",
11-
"phpunit/phpunit": ">=4 <8",
11+
"phpunit/phpunit": ">=4 <10",
1212
"doctrine/cache": "~1.5",
1313
"psr/simple-cache": "^1.0",
1414
"symfony/cache": "^3.4",

guzzle_environments/7/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"require-dev": {
1010
"guzzlehttp/guzzle": "~7",
11-
"phpunit/phpunit": ">=4 <8",
11+
"phpunit/phpunit": ">=4 <10",
1212
"doctrine/cache": "~1.5",
1313
"psr/simple-cache": "^1.0",
1414
"symfony/cache": "^3.4",

guzzle_environments/run_tests_docker.sh

+10-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@
33
DIR=$(dirname $(readlink -f $0))
44

55
TESTS=${1:-all}
6-
#IMAGE="composer:php5-alpine"
7-
IMAGE="composer:latest"
6+
#IMAGE="phplegacy/php:5.4-composer" #PHP 5.4.45
7+
# not found a working php 5.5 image
8+
#IMAGE="prooph/composer:5.6"
9+
#IMAGE="prooph/composer:7.0"
10+
#IMAGE="prooph/composer:7.1"
11+
#IMAGE="prooph/composer:7.2"
12+
#IMAGE="prooph/composer:7.3"
13+
#IMAGE="prooph/composer:7.4"
14+
#IMAGE="prooph/composer:8.0"
15+
IMAGE="composer:latest" #PHP latest version
816

917
function run_tests()
1018
{

tests/BaseTestCase.php

+41
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,47 @@
1313

1414
class BaseTestCase extends \PHPUnit\Framework\TestCase
1515
{
16+
/**
17+
* @before
18+
*/
19+
public function _callCompatibleSetup()
20+
{
21+
if (method_exists($this, '_setUp')) {
22+
$this->_setUp();
23+
}
24+
}
25+
26+
/**
27+
* @after
28+
*/
29+
public function _callCompatibleTearDown()
30+
{
31+
if (method_exists($this, '_tearDown')) {
32+
$this->_tearDown();
33+
}
34+
}
35+
36+
public function _expectException($exception)
37+
{
38+
if (method_exists($this, 'expectException')) {
39+
$this->expectException($exception);
40+
} else {
41+
$this->setExpectedException($exception);
42+
}
43+
}
44+
45+
public function _expectExceptionMessage($message)
46+
{
47+
if (method_exists($this,'expectExceptionMessage')) {
48+
$this->expectExceptionMessage($message);
49+
} else {
50+
$this->setExpectedException(
51+
$this->getExpectedException() ? $this->getExpectedException() : 'Exception',
52+
$message
53+
);
54+
}
55+
}
56+
1657
protected function createRequest($method, $uri, $options=[])
1758
{
1859
return Helper::guzzleIs('>=', 6)?

tests/GrantType/AuthorizationCodeTest.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@ public function testConstruct()
2525
]);
2626
}
2727

28-
/**
29-
* @expectedException InvalidArgumentException
30-
* @expectedExceptionMessage Config is missing the following keys
31-
*/
3228
public function testConstructThrowsForMissing()
3329
{
30+
$this->_expectException('InvalidArgumentException');
31+
$this->_expectExceptionMessage('Config is missing the following keys');
3432
$grant = new AuthorizationCode(new Client(), []);
3533
}
3634

tests/GrantType/ClientCredentialsTest.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ public function testConstruct()
2424
]);
2525
}
2626

27-
/**
28-
* @expectedException InvalidArgumentException
29-
* @expectedExceptionMessage Config is missing the following keys
30-
*/
3127
public function testConstructThrowsForMissing()
3228
{
29+
$this->_expectException('InvalidArgumentException');
30+
$this->_expectExceptionMessage('Config is missing the following keys');
3331
$grant = new ClientCredentials(new Client(), []);
3432
}
3533

tests/GrantType/PasswordCredentialsTest.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@ public function testConstruct()
2626
]);
2727
}
2828

29-
/**
30-
* @expectedException InvalidArgumentException
31-
* @expectedExceptionMessage Config is missing the following keys
32-
*/
3329
public function testConstructThrowsForMissing()
3430
{
31+
$this->_expectException('InvalidArgumentException');
32+
$this->_expectExceptionMessage('Config is missing the following keys');
3533
$grant = new PasswordCredentials(new Client(), []);
3634
}
3735

tests/GrantType/RefreshTokenTest.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@ public function testConstruct()
2626
]);
2727
}
2828

29-
/**
30-
* @expectedException InvalidArgumentException
31-
* @expectedExceptionMessage Config is missing the following keys
32-
*/
3329
public function testConstructThrowsForMissing()
3430
{
31+
$this->_expectException('InvalidArgumentException');
32+
$this->_expectExceptionMessage('Config is missing the following keys');
3533
$grant = new RefreshToken(new Client(), []);
3634
}
3735

tests/GrantType/Specific/GithubApplicationTest.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@ public function testConstruct()
2929
]);
3030
}
3131

32-
/**
33-
* @expectedException InvalidArgumentException
34-
* @expectedExceptionMessage Config is missing the following keys
35-
*/
3632
public function testConstructThrowsForMissing()
3733
{
34+
$this->_expectException('InvalidArgumentException');
35+
$this->_expectExceptionMessage('Config is missing the following keys');
3836
$grant = new GithubApplication(new Client(), []);
3937
}
4038

tests/OAuth2MiddlewareTest.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
class OAuth2MiddlewareTest extends BaseTestCase
1717
{
18-
public function setUp()
18+
public function _setUp()
1919
{
2020
if (Helper::guzzleIs('<', 6)) {
2121
$this->markTestSkipped("Guzzle 6+ is required for this test");
@@ -162,11 +162,9 @@ public function testTriggersSignerAndGrantDataProcessor()
162162
$this->assertSame($expected_auth_value, $this->getHeader($container[0]['request'], 'Authorization'));
163163
}
164164

165-
/**
166-
* @expectedException GuzzleHttp\Exception\ClientException
167-
*/
168165
public function testOnErrorDoesNotTriggerForNonOAuthRequests()
169166
{
167+
$this->_expectException('GuzzleHttp\Exception\ClientException');
170168

171169
// A random access token helps avoid false pasitives due to caching
172170
$mock_access_token = md5(microtime(true).mt_rand(100000, 999999));

tests/Persistence/ClosureTokenPersistenceTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ClosureTokenPersistenceTest extends TokenPersistenceTestBase
1313

1414
private $cache = [];
1515

16-
public function setUp()
16+
public function _setUp()
1717
{
1818
$this->cache = [];
1919
}

tests/Persistence/DoctrineCacheTokenPersistenceTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function getInstance()
1616
return new DoctrineCacheTokenPersistence($this->cache);
1717
}
1818

19-
public function setUp()
19+
public function _setUp()
2020
{
2121
$this->cache = new ArrayCache();
2222
}

tests/Persistence/FileTokenPersistenceTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ public function getInstance()
1313
return new FileTokenPersistence($this->testFile);
1414
}
1515

16-
public function setUp()
16+
public function _setUp()
1717
{
1818
$this->testFile = tempnam(sys_get_temp_dir(), "guzzle_phpunit_test_");
1919
if (file_exists($this->testFile)) {
2020
unlink($this->testFile);
2121
}
2222
}
2323

24-
public function tearDown()
24+
public function _tearDown()
2525
{
2626
if (file_exists($this->testFile)) {
2727
unlink($this->testFile);

tests/Persistence/Laravel5CacheTokenPersistenceTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function getInstance()
1717
return new Laravel5CacheTokenPersistence($this->cache);
1818
}
1919

20-
public function setUp()
20+
public function _setUp()
2121
{
2222
$this->cache = new Repository(new ArrayStore());
2323
}

tests/Persistence/SimpleCacheTokenPersistenceTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function getInstance()
1616
return new SimpleCacheTokenPersistence($this->cache);
1717
}
1818

19-
public function setUp()
19+
public function _setUp()
2020
{
2121
$this->cache = new ArrayCache();
2222
}

0 commit comments

Comments
 (0)