StatementDecoratorTest.php 1.9 KB

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