ConsumerTest.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Integration\Test\Unit\Model\ResourceModel\Oauth;
  7. /**
  8. * Unit test for \Magento\Integration\Model\ResourceModel\Oauth\Consumer
  9. */
  10. class ConsumerTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var \Magento\Framework\DB\Adapter\AdapterInterface|\PHPUnit_Framework_MockObject_MockObject
  14. */
  15. protected $connectionMock;
  16. /**
  17. * @var \Magento\Framework\App\ResourceConnection|\PHPUnit_Framework_MockObject_MockObject
  18. */
  19. protected $resourceMock;
  20. /**
  21. * @var \Magento\Integration\Model\Oauth\Consumer
  22. */
  23. protected $consumerMock;
  24. /**
  25. * @var \Magento\Integration\Model\ResourceModel\Oauth\Consumer
  26. */
  27. protected $consumerResource;
  28. protected function setUp()
  29. {
  30. $this->consumerMock = $this->createPartialMock(
  31. \Magento\Integration\Model\Oauth\Consumer::class,
  32. ['setUpdatedAt', 'getId']
  33. );
  34. $this->connectionMock = $this->createMock(\Magento\Framework\DB\Adapter\Pdo\Mysql::class);
  35. $this->resourceMock = $this->createMock(\Magento\Framework\App\ResourceConnection::class);
  36. $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->connectionMock);
  37. $contextMock = $this->createMock(\Magento\Framework\Model\ResourceModel\Db\Context::class);
  38. $contextMock->expects($this->once())->method('getResources')->willReturn($this->resourceMock);
  39. $this->consumerResource = new \Magento\Integration\Model\ResourceModel\Oauth\Consumer(
  40. $contextMock,
  41. new \Magento\Framework\Stdlib\DateTime()
  42. );
  43. }
  44. public function testAfterDelete()
  45. {
  46. $this->connectionMock->expects($this->exactly(2))->method('delete');
  47. $this->assertInstanceOf(
  48. \Magento\Integration\Model\ResourceModel\Oauth\Consumer::class,
  49. $this->consumerResource->_afterDelete($this->consumerMock)
  50. );
  51. }
  52. public function testGetTimeInSecondsSinceCreation()
  53. {
  54. $selectMock = $this->createMock(\Magento\Framework\DB\Select::class);
  55. $selectMock->expects($this->any())->method('from')->will($this->returnValue($selectMock));
  56. $selectMock->expects($this->any())->method('reset')->will($this->returnValue($selectMock));
  57. $selectMock->expects($this->any())->method('columns')->will($this->returnValue($selectMock));
  58. $selectMock->expects($this->any())->method('where')->will($this->returnValue($selectMock));
  59. $this->connectionMock->expects($this->any())->method('select')->willReturn($selectMock);
  60. $this->connectionMock->expects($this->once())->method('fetchOne');
  61. $this->consumerResource->getTimeInSecondsSinceCreation(1);
  62. }
  63. }