Skip to content

Commit

Permalink
tests: added complex test for %like
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Aug 22, 2018
1 parent 4abe874 commit 0ad2dd7
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions tests/dibi/Translator.like.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

/**
* @dataProvider ../databases.ini
*/

declare(strict_types=1);

use Tester\Assert;

require __DIR__ . '/bootstrap.php';


$conn = new Dibi\Connection($config);

// starts with
Assert::falsey($conn->fetchSingle('SELECT ? LIKE %like~', 'a', 'b'));
Assert::falsey($conn->fetchSingle('SELECT ? LIKE %like~', 'baa', 'aa'));
Assert::truthy($conn->fetchSingle('SELECT ? LIKE %like~', 'aab', 'aa'));
Assert::falsey($conn->fetchSingle('SELECT ? LIKE %like~', 'bba', '%a'));
Assert::falsey($conn->fetchSingle('SELECT ? LIKE %like~', '%ba', '%a'));
Assert::truthy($conn->fetchSingle('SELECT ? LIKE %like~', '%ab', '%a'));
Assert::falsey($conn->fetchSingle('SELECT ? LIKE %like~', 'aa', '_a'));
Assert::falsey($conn->fetchSingle('SELECT ? LIKE %like~', '_b', '_a'));
Assert::truthy($conn->fetchSingle('SELECT ? LIKE %like~', '_ab', '_a'));

Assert::truthy($conn->fetchSingle('SELECT ? LIKE %like~', 'a"a', 'a"'));
Assert::falsey($conn->fetchSingle('SELECT ? LIKE %like~', 'b"', '%"'));
Assert::truthy($conn->fetchSingle('SELECT ? LIKE %like~', '%"', '%"'));

Assert::truthy($conn->fetchSingle('SELECT ? LIKE %like~', "a'a", "a'"));
Assert::falsey($conn->fetchSingle('SELECT ? LIKE %like~', "b'", "%'"));
Assert::truthy($conn->fetchSingle('SELECT ? LIKE %like~', "%'", "%'"));

Assert::truthy($conn->fetchSingle('SELECT ? LIKE %like~', 'a\\a', 'a\\'));
Assert::falsey($conn->fetchSingle('SELECT ? LIKE %like~', 'b\\', '%\\'));
Assert::truthy($conn->fetchSingle('SELECT ? LIKE %like~', '%\\', '%\\'));

Assert::truthy($conn->fetchSingle('SELECT ? LIKE %like~', 'a[a', 'a['));
Assert::falsey($conn->fetchSingle('SELECT ? LIKE %like~', 'b[', '%['));
Assert::truthy($conn->fetchSingle('SELECT ? LIKE %like~', '%[', '%['));


// ends with
Assert::falsey($conn->fetchSingle('SELECT ? LIKE %~like', 'a', 'b'));
Assert::truthy($conn->fetchSingle('SELECT ? LIKE %~like', 'baa', 'aa'));
Assert::falsey($conn->fetchSingle('SELECT ? LIKE %~like', 'aab', 'aa'));
Assert::falsey($conn->fetchSingle('SELECT ? LIKE %~like', 'bba', '%a'));
Assert::falsey($conn->fetchSingle('SELECT ? LIKE %~like', 'a%b', '%a'));
Assert::truthy($conn->fetchSingle('SELECT ? LIKE %~like', 'b%a', '%a'));
Assert::falsey($conn->fetchSingle('SELECT ? LIKE %~like', 'aa', '_a'));
Assert::falsey($conn->fetchSingle('SELECT ? LIKE %~like', '_b', '_a'));
Assert::truthy($conn->fetchSingle('SELECT ? LIKE %~like', 'b_a', '_a'));

Assert::truthy($conn->fetchSingle('SELECT ? LIKE %~like', 'a"a', '"a'));
Assert::falsey($conn->fetchSingle('SELECT ? LIKE %~like', '"b', '"%'));
Assert::truthy($conn->fetchSingle('SELECT ? LIKE %~like', '"%', '"%'));

Assert::truthy($conn->fetchSingle('SELECT ? LIKE %~like', "a'a", "'a"));
Assert::falsey($conn->fetchSingle('SELECT ? LIKE %~like', "'b", "'%"));
Assert::truthy($conn->fetchSingle('SELECT ? LIKE %~like', "'%", "'%"));

Assert::truthy($conn->fetchSingle('SELECT ? LIKE %~like', 'a\\a', '\\a'));
Assert::falsey($conn->fetchSingle('SELECT ? LIKE %~like', '\\b', '\\%'));
Assert::truthy($conn->fetchSingle('SELECT ? LIKE %~like', '\\%', '\\%'));


// contains
Assert::falsey($conn->fetchSingle('SELECT ? LIKE %~like~', 'a', 'b'));
Assert::truthy($conn->fetchSingle('SELECT ? LIKE %~like~', 'baa', 'aa'));
Assert::truthy($conn->fetchSingle('SELECT ? LIKE %~like~', 'aab', 'aa'));
Assert::falsey($conn->fetchSingle('SELECT ? LIKE %~like~', 'bba', '%a'));
Assert::truthy($conn->fetchSingle('SELECT ? LIKE %~like~', 'b%a', '%a'));

0 comments on commit 0ad2dd7

Please sign in to comment.