LimitExpressionTest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\DB\Test\Unit\Sql;
  7. class LimitExpressionTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @expectedException \Zend_Db_Adapter_Exception
  11. * @expectedExceptionMessage LIMIT argument count=0 is not valid
  12. */
  13. public function testToStringExceptionCount()
  14. {
  15. $sql = 'test sql';
  16. $count = 0;
  17. $model = new \Magento\Framework\DB\Sql\LimitExpression($sql, $count);
  18. $model->__toString();
  19. }
  20. /**
  21. * @expectedException \Zend_Db_Adapter_Exception
  22. * @expectedExceptionMessage LIMIT argument offset=-1 is not valid
  23. */
  24. public function testToStringExceptionOffset()
  25. {
  26. $sql = 'test sql';
  27. $count = 1;
  28. $offset = -1;
  29. $model = new \Magento\Framework\DB\Sql\LimitExpression($sql, $count, $offset);
  30. $model->__toString();
  31. }
  32. public function testToString()
  33. {
  34. $sql = 'select * from test_table';
  35. $count = 1;
  36. $offset = 1;
  37. $model = new \Magento\Framework\DB\Sql\LimitExpression($sql, $count, $offset);
  38. $this->assertEquals('select * from test_table LIMIT 1 OFFSET 1', $model->__toString());
  39. }
  40. }