Skip to content

Commit 7786322

Browse files
Cari Spruiellisitnikov
authored andcommitted
MAGETWO-51292: [GITHUB] OAuth Token Exchange Expiration Period Is Not Calculated Correctly #3449
- fix test
1 parent 7bf426b commit 7786322

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

app/code/Magento/Integration/Test/Unit/Model/Oauth/ConsumerTest.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function setUp()
110110

111111
$this->resourceMock = $this->getMock(
112112
'Magento\Integration\Model\ResourceModel\Oauth\Consumer',
113-
['getTimeInSecondsSinceTokenExchangeStarted', 'getIdFieldName', 'selectByCompositeKey', 'deleteOldEntries'],
113+
['getIdFieldName', 'selectByCompositeKey', 'deleteOldEntries'],
114114
[],
115115
'',
116116
false,
@@ -215,19 +215,31 @@ public function testValidateInvalidConsumerSecret()
215215

216216
public function testGetConsumerExpirationPeriodValid()
217217
{
218-
$this->resourceMock->expects($this->once())
219-
->method('getTimeInSecondsSinceTokenExchangeStarted')
220-
->will($this->returnValue(30));
218+
$dateHelperMock = $this->getMockBuilder('Magento\Framework\Stdlib\DateTime\DateTime')
219+
->disableOriginalConstructor()
220+
->getMock();
221+
$dateHelperMock->expects($this->at(0))->method('gmtTimestamp')->willReturn(time());
222+
$dateHelperMock->expects($this->at(1))->method('gmtTimestamp')->willReturn(time() - 100);
223+
224+
$dateHelper = new \ReflectionProperty('Magento\Integration\Model\Oauth\Consumer', '_dateHelper');
225+
$dateHelper->setAccessible(true);
226+
$dateHelper->setValue($this->consumerModel, $dateHelperMock);
221227

222228
$this->consumerModel->setUpdatedAt(time());
223229
$this->assertTrue($this->consumerModel->isValidForTokenExchange());
224230
}
225231

226232
public function testGetConsumerExpirationPeriodExpired()
227233
{
228-
$this->resourceMock->expects($this->once())
229-
->method('getTimeInSecondsSinceTokenExchangeStarted')
230-
->will($this->returnValue(400));
234+
$dateHelperMock = $this->getMockBuilder('Magento\Framework\Stdlib\DateTime\DateTime')
235+
->disableOriginalConstructor()
236+
->getMock();
237+
$dateHelperMock->expects($this->at(0))->method('gmtTimestamp')->willReturn(time());
238+
$dateHelperMock->expects($this->at(1))->method('gmtTimestamp')->willReturn(time() - 1000);
239+
240+
$dateHelper = new \ReflectionProperty('Magento\Integration\Model\Oauth\Consumer', '_dateHelper');
241+
$dateHelper->setAccessible(true);
242+
$dateHelper->setValue($this->consumerModel, $dateHelperMock);
231243

232244
$this->consumerModel->setUpdatedAt(time());
233245
$this->assertFalse($this->consumerModel->isValidForTokenExchange());

0 commit comments

Comments
 (0)