Skip to content

Commit d4f856c

Browse files
authored
Merge branch 'master' into master
2 parents 6f08509 + 25f00da commit d4f856c

File tree

8 files changed

+158
-19
lines changed

8 files changed

+158
-19
lines changed

Diff for: .codecov.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
codecov:
2+
require_ci_to_pass: yes
3+
4+
coverage:
5+
precision: 2
6+
round: down
7+
range: "70...100"
8+
status:
9+
project:
10+
default:
11+
target: auto
12+
threshold: 0%
13+
patch:
14+
default:
15+
target: auto
16+
threshold: 0%
17+
18+
parsers:
19+
gcov:
20+
branch_detection:
21+
conditional: yes
22+
loop: yes
23+
method: no
24+
macro: no
25+
26+
comment:
27+
layout: "reach,diff,flags,tree"
28+
behavior: default
29+
require_changes: false

Diff for: .gitattributes

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
/.gitattributes export-ignore
2-
/.github/ export-ignore
3-
/.gitignore export-ignore
4-
/docs/ export-ignore
5-
/phpunit.xml export-ignore
6-
/test/ export-ignore
1+
/.codecov.yml export-ignore
2+
/.gitattributes export-ignore
3+
/.github/ export-ignore
4+
/.gitignore export-ignore
5+
/CHANGELOG.md export-ignore
6+
/CODE_OF_CONDUCT.md export-ignore
7+
/CONTRIBUTING.md export-ignore
8+
/CREDITS.md export-ignore
9+
/README.PROVIDER-GUIDE.md export-ignore
10+
/docs/ export-ignore
11+
/phpunit.xml export-ignore
12+
/test/ export-ignore

Diff for: .github/workflows/continuous-integration.yml

+2-7
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,5 @@ jobs:
7979
composer-options: "${{ matrix.composer-options }}"
8080
- name: "Run unit tests"
8181
run: "./vendor/bin/phpunit --colors=always --coverage-clover build/logs/clover.xml"
82-
- name: "Publish coverage report to Coveralls"
83-
continue-on-error: true
84-
env:
85-
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
86-
run: |
87-
composer global --ansi require php-coveralls/php-coveralls
88-
php-coveralls --ansi -vv --coverage_clover=build/logs/clover.xml
82+
- name: "Publish coverage report to Codecov"
83+
uses: "codecov/codecov-action@v1"

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
This package makes it simple to integrate your application with [OAuth 2.0](http://oauth.net/2/) service providers.
44

55
[![Gitter Chat](https://img.shields.io/badge/gitter-join_chat-brightgreen.svg?style=flat-square)](https://gitter.im/thephpleague/oauth2-client)
6-
[![Source Code](http://img.shields.io/badge/source-thephpleague/oauth2--client-blue.svg?style=flat-square)](https://github.com/thephpleague/oauth2-client)
6+
[![Source Code](https://img.shields.io/badge/source-thephpleague/oauth2--client-blue.svg?style=flat-square)](https://github.com/thephpleague/oauth2-client)
77
[![Latest Version](https://img.shields.io/github/release/thephpleague/oauth2-client.svg?style=flat-square)](https://github.com/thephpleague/oauth2-client/releases)
88
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://github.com/thephpleague/oauth2-client/blob/master/LICENSE)
99
[![Build Status](https://img.shields.io/github/workflow/status/thephpleague/oauth2-client/CI?label=CI&logo=github&style=flat-square)](https://github.com/thephpleague/oauth2-client/actions?query=workflow%3ACI)
10-
[![Coverage Status](https://img.shields.io/coveralls/thephpleague/oauth2-client/master.svg?style=flat-square)](https://coveralls.io/r/thephpleague/oauth2-client?branch=master)
10+
[![Codecov Code Coverage](https://img.shields.io/codecov/c/gh/thephpleague/oauth2-client?label=codecov&logo=codecov&style=flat-square)](https://codecov.io/gh/thephpleague/oauth2-client)
1111
[![Total Downloads](https://img.shields.io/packagist/dt/league/oauth2-client.svg?style=flat-square)](https://packagist.org/packages/league/oauth2-client)
1212

1313
---

Diff for: docs/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ League/oauth2-client
1212
[![Latest Version](https://img.shields.io/github/release/thephpleague/oauth2-client.svg?style=flat-square)](https://github.com/thephpleague/oauth2-client/releases)
1313
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://github.com/thephpleague/oauth2-client/blob/master/LICENSE)
1414
[![Build Status](https://img.shields.io/github/workflow/status/thephpleague/oauth2-client/CI?label=CI&logo=github&style=flat-square)](https://github.com/thephpleague/oauth2-client/actions?query=workflow%3ACI)
15-
[![Coverage Status](https://img.shields.io/coveralls/thephpleague/oauth2-client/master.svg?style=flat-square)](https://coveralls.io/r/thephpleague/oauth2-client?branch=master)
15+
[![Codecov Code Coverage](https://img.shields.io/codecov/c/gh/thephpleague/oauth2-client?label=codecov&logo=codecov&style=flat-square)](https://codecov.io/gh/thephpleague/oauth2-client)
1616
[![Total Downloads](https://img.shields.io/packagist/dt/league/oauth2-client.svg?style=flat-square)](https://packagist.org/packages/league/oauth2-client)
1717

1818
The OAuth2 login flow, seen commonly around the web in the form of "Connect with Facebook/Google/etc." buttons, is a very

Diff for: src/Token/AccessToken.php

+36-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,40 @@ class AccessToken implements AccessTokenInterface, ResourceOwnerAccessTokenInter
4949
*/
5050
protected $values = [];
5151

52+
/**
53+
* @var int
54+
*/
55+
private static $timeNow;
56+
57+
/**
58+
* Set the time now. This should only be used for testing purposes.
59+
*
60+
* @param int $timeNow the time in seconds since epoch
61+
* @return void
62+
*/
63+
public static function setTimeNow($timeNow)
64+
{
65+
self::$timeNow = $timeNow;
66+
}
67+
68+
/**
69+
* Reset the time now if it was set for test purposes.
70+
*
71+
* @return void
72+
*/
73+
public static function resetTimeNow()
74+
{
75+
self::$timeNow = null;
76+
}
77+
78+
/**
79+
* @return int
80+
*/
81+
public function getTimeNow()
82+
{
83+
return self::$timeNow ? self::$timeNow : time();
84+
}
85+
5286
/**
5387
* Constructs an access token.
5488
*
@@ -80,14 +114,14 @@ public function __construct(array $options = [])
80114
throw new \InvalidArgumentException('expires_in value must be an integer');
81115
}
82116

83-
$this->expires = $options['expires_in'] != 0 ? time() + $options['expires_in'] : 0;
117+
$this->expires = $options['expires_in'] != 0 ? $this->getTimeNow() + $options['expires_in'] : 0;
84118
} elseif (!empty($options['expires'])) {
85119
// Some providers supply the seconds until expiration rather than
86120
// the exact timestamp. Take a best guess at which we received.
87121
$expires = $options['expires'];
88122

89123
if (!$this->isExpirationTimestamp($expires)) {
90-
$expires += time();
124+
$expires += $this->getTimeNow();
91125
}
92126

93127
$this->expires = $expires;

Diff for: src/Token/AccessTokenInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function getToken();
3434
public function getRefreshToken();
3535

3636
/**
37-
* Returns the expiration timestamp, if defined.
37+
* Returns the expiration timestamp in seconds, if defined.
3838
*
3939
* @return integer|null
4040
*/

Diff for: test/src/Token/AccessTokenTest.php

+75
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,27 @@
1010

1111
class AccessTokenTest extends TestCase
1212
{
13+
/**
14+
* BC teardown.
15+
*
16+
* This is for backwards compatibility of older PHP versions. Ideally we would just implement a tearDown() here but
17+
* older PHP versions this library supports don't have return typehint support, so this is the workaround.
18+
*
19+
* @return void
20+
*/
21+
private static function tearDownForBackwardsCompatibility()
22+
{
23+
/* reset the test double time if it was set */
24+
AccessToken::resetTimeNow();
25+
}
26+
1327
public function testInvalidRefreshToken()
1428
{
1529
$this->expectException(InvalidArgumentException::class);
1630

1731
$token = $this->getAccessToken(['invalid_access_token' => 'none']);
32+
33+
self::tearDownForBackwardsCompatibility();
1834
}
1935

2036
protected function getAccessToken($options = [])
@@ -32,6 +48,49 @@ public function testExpiresInCorrection()
3248
$this->assertNotNull($expires);
3349
$this->assertGreaterThan(time(), $expires);
3450
$this->assertLessThan(time() + 200, $expires);
51+
52+
self::tearDownForBackwardsCompatibility();
53+
}
54+
55+
public function testExpiresInCorrectionUsingSetTimeNow()
56+
{
57+
/* set fake time at 2020-01-01 00:00:00 */
58+
AccessToken::setTimeNow(1577836800);
59+
$options = ['access_token' => 'access_token', 'expires_in' => 100];
60+
$token = $this->getAccessToken($options);
61+
62+
$expires = $token->getExpires();
63+
64+
$this->assertNotNull($expires);
65+
$this->assertEquals(1577836900, $expires);
66+
67+
self::tearDownForBackwardsCompatibility();
68+
}
69+
70+
public function testSetTimeNow()
71+
{
72+
AccessToken::setTimeNow(1577836800);
73+
$timeNow = $this->getAccessToken(['access_token' => 'asdf'])->getTimeNow();
74+
75+
$this->assertEquals(1577836800, $timeNow);
76+
77+
self::tearDownForBackwardsCompatibility();
78+
}
79+
80+
public function testResetTimeNow()
81+
{
82+
AccessToken::setTimeNow(1577836800);
83+
$token = $this->getAccessToken(['access_token' => 'asdf']);
84+
85+
$this->assertEquals(1577836800, $token->getTimeNow());
86+
AccessToken::resetTimeNow();
87+
88+
$this->assertNotEquals(1577836800, $token->getTimeNow());
89+
90+
$timeBeforeAssertion = time();
91+
$this->assertGreaterThanOrEqual($timeBeforeAssertion, $token->getTimeNow());
92+
93+
self::tearDownForBackwardsCompatibility();
3594
}
3695

3796
public function testExpiresPastTimestamp()
@@ -45,6 +104,8 @@ public function testExpiresPastTimestamp()
45104
$token = $this->getAccessToken($options);
46105

47106
$this->assertFalse($token->hasExpired());
107+
108+
self::tearDownForBackwardsCompatibility();
48109
}
49110

50111
public function testGetRefreshToken()
@@ -58,6 +119,8 @@ public function testGetRefreshToken()
58119
$refreshToken = $token->getRefreshToken();
59120

60121
$this->assertEquals($options['refresh_token'], $refreshToken);
122+
123+
self::tearDownForBackwardsCompatibility();
61124
}
62125

63126
public function testHasNotExpiredWhenPropertySetInFuture()
@@ -75,6 +138,8 @@ public function testHasNotExpiredWhenPropertySetInFuture()
75138
->andReturn($expectedExpires);
76139

77140
$this->assertFalse($token->hasExpired());
141+
142+
self::tearDownForBackwardsCompatibility();
78143
}
79144

80145
public function testHasExpiredWhenPropertySetInPast()
@@ -92,6 +157,8 @@ public function testHasExpiredWhenPropertySetInPast()
92157
->andReturn($expectedExpires);
93158

94159
$this->assertTrue($token->hasExpired());
160+
161+
self::tearDownForBackwardsCompatibility();
95162
}
96163

97164
public function testCannotReportExpiredWhenNoExpirationSet()
@@ -104,6 +171,8 @@ public function testCannotReportExpiredWhenNoExpirationSet()
104171
$this->expectException(RuntimeException::class);
105172

106173
$hasExpired = $token->hasExpired();
174+
175+
self::tearDownForBackwardsCompatibility();
107176
}
108177

109178
public function testInvalidExpiresIn()
@@ -116,6 +185,8 @@ public function testInvalidExpiresIn()
116185
$this->expectException(InvalidArgumentException::class);
117186

118187
$token = $this->getAccessToken($options);
188+
189+
self::tearDownForBackwardsCompatibility();
119190
}
120191

121192

@@ -132,6 +203,8 @@ public function testJsonSerializable()
132203
$jsonToken = json_encode($token);
133204

134205
$this->assertEquals($options, json_decode($jsonToken, true));
206+
207+
self::tearDownForBackwardsCompatibility();
135208
}
136209

137210
public function testValues()
@@ -151,5 +224,7 @@ public function testValues()
151224
$this->assertTrue(is_array($values));
152225
$this->assertArrayHasKey('custom_thing', $values);
153226
$this->assertSame($options['custom_thing'], $values['custom_thing']);
227+
228+
self::tearDownForBackwardsCompatibility();
154229
}
155230
}

0 commit comments

Comments
 (0)