StatementDecoratorTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * PHP Version 5.4
  4. *
  5. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  6. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  7. *
  8. * Licensed under The MIT License
  9. * For full copyright and license information, please see the LICENSE.txt
  10. * Redistributions of files must retain the above copyright notice.
  11. *
  12. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  13. * @link http://cakephp.org CakePHP(tm) Project
  14. * @since CakePHP(tm) v 3.0.0
  15. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  16. */
  17. namespace Cake\Test\TestCase\Database\Statement;
  18. use Cake\Database\Statement\StatementDecorator;
  19. use Cake\TestSuite\TestCase;
  20. use \PDO;
  21. /**
  22. * Tests StatementDecorator class
  23. *
  24. */
  25. class StatemetDecoratorTest extends TestCase {
  26. /**
  27. * Tests that calling lastInsertId will proxy it to
  28. * the driver's lastInsertId method
  29. *
  30. * @return void
  31. */
  32. public function testLastInsertId() {
  33. $statement = $this->getMock('\PDOStatement');
  34. $driver = $this->getMock('\Cake\Database\Driver');
  35. $statement = new StatementDecorator($statement, $driver);
  36. $driver->expects($this->once())->method('lastInsertId')
  37. ->with('users')
  38. ->will($this->returnValue(2));
  39. $this->assertEquals(2, $statement->lastInsertId('users'));
  40. }
  41. /**
  42. * Tests that calling lastInsertId will get the
  43. *
  44. * @return void
  45. */
  46. public function testLastInsertIdWithReturning() {
  47. $internal = $this->getMock('\PDOStatement');
  48. $driver = $this->getMock('\Cake\Database\Driver');
  49. $statement = new StatementDecorator($internal, $driver);
  50. $internal->expects($this->once())->method('columnCount')
  51. ->will($this->returnValue(1));
  52. $internal->expects($this->once())->method('fetch')
  53. ->with('assoc')
  54. ->will($this->returnValue(['id' => 2]));
  55. $driver->expects($this->never())->method('lastInsertId');
  56. $this->assertEquals(2, $statement->lastInsertId('users', 'id'));
  57. }
  58. }