Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
NonceTest.php
Go to the documentation of this file.
1 <?php
7 
11 class NonceTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $connectionMock;
17 
21  protected $resourceMock;
22 
26  protected $nonceResource;
27 
28  protected function setUp()
29  {
30  $this->connectionMock = $this->createMock(\Magento\Framework\DB\Adapter\Pdo\Mysql::class);
31 
32  $this->resourceMock = $this->createMock(\Magento\Framework\App\ResourceConnection::class);
33  $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->connectionMock);
34 
35  $contextMock = $this->createMock(\Magento\Framework\Model\ResourceModel\Db\Context::class);
36  $contextMock->expects($this->once())->method('getResources')->willReturn($this->resourceMock);
37 
38  $this->nonceResource = new \Magento\Integration\Model\ResourceModel\Oauth\Nonce($contextMock);
39  }
40 
41  public function testDeleteOldEntries()
42  {
43  $this->connectionMock->expects($this->once())->method('delete');
44  $this->connectionMock->expects($this->once())->method('quoteInto');
45  $this->nonceResource->deleteOldEntries(5);
46  }
47 
48  public function testSelectByCompositeKey()
49  {
50  $selectMock = $this->createMock(\Magento\Framework\DB\Select::class);
51  $selectMock->expects($this->once())->method('from')->will($this->returnValue($selectMock));
52  $selectMock->expects($this->exactly(2))->method('where')->will($this->returnValue($selectMock));
53  $this->connectionMock->expects($this->once())->method('select')->willReturn($selectMock);
54  $this->connectionMock->expects($this->once())->method('fetchRow');
55  $this->nonceResource->selectByCompositeKey('nonce', 5);
56  }
57 }