DbTest.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. use \Codeception\Lib\Driver\Db;
  3. use \Codeception\Test\Unit;
  4. use \Codeception\Util\ReflectionHelper;
  5. /**
  6. * @group appveyor
  7. * @group db
  8. */
  9. class DbTest extends Unit
  10. {
  11. /**
  12. * @dataProvider getWhereCriteria
  13. */
  14. public function testGenerateWhereClause($criteria, $expectedResult)
  15. {
  16. $db = new Db('sqlite:tests/data/sqlite.db','root','');
  17. $result = ReflectionHelper::invokePrivateMethod($db, 'generateWhereClause', [&$criteria]);
  18. $this->assertEquals($expectedResult, $result);
  19. }
  20. public function getWhereCriteria()
  21. {
  22. return [
  23. 'like' => [['email like' => 'mail.ua'], 'WHERE "email" LIKE ? '],
  24. '<=' => [['id <=' => '5'], 'WHERE "id" <= ? '],
  25. '<' => [['id <' => '5'], 'WHERE "id" < ? '],
  26. '>=' => [['id >=' => '5'], 'WHERE "id" >= ? '],
  27. '>' => [['id >' => '5'], 'WHERE "id" > ? '],
  28. '!=' => [['id !=' => '5'], 'WHERE "id" != ? '],
  29. ];
  30. }
  31. }