Skip to content

Commit

Permalink
fixes like
Browse files Browse the repository at this point in the history
  • Loading branch information
midorikocak committed Feb 29, 2020
1 parent 522bfcb commit 719094b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 22 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Security
- Nothing

## [1.4.2] - 2020-02-28

### Added
- Nothing

### Deprecated
- Nothing

### Fixed
- LIKE operator

### Removed
- Nothing

### Security
- Nothing
12 changes: 6 additions & 6 deletions src/QueryMaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public function where($key, $value, string $operator = '='): QueryInterface
{
$this->checkOperator($operator);

$this->statement .= ' WHERE ' . $key . $operator . ':' . $key;
$this->query .= ' WHERE ' . $key . $operator . '\'' . $value . '\'';
$this->statement .= ' WHERE ' . $key . ' ' . $operator . ' :' . $key;
$this->query .= ' WHERE ' . $key . ' ' . $operator . ' \'' . $value . '\'';
$this->params[$key] = $value;
return $this;
}
Expand Down Expand Up @@ -162,14 +162,14 @@ private function prepareParams(array $values, string $glue, string $operator = '

foreach ($values as $key => $value) {
if (!isset($this->params[$key])) {
$queryValues[] = $key . $operator . '\'' . $value . '\'';
$params [] = $key . $operator . ':' . $key;
$queryValues[] = $key . ' ' . $operator . ' \'' . $value . '\'';
$params [] = $key . ' ' . $operator . ' :' . $key;

$this->params[$key] = $value;
} else {
$uniqid = uniqid('', true);
$queryValues[] = $key . $operator . '\'' . $value . '\'';
$params [] = $key . $operator . ':' . $key . $uniqid;
$queryValues[] = $key . ' ' . $operator . ' \'' . $value . '\'';
$params [] = $key . ' ' . $operator . ' :' . $key . $uniqid;

$this->params[$key . $uniqid] = $value;
}
Expand Down
32 changes: 16 additions & 16 deletions tests/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,18 @@ public function testSelectFields()
$this->assertEquals('SELECT id, email FROM users', $this->queryMaker->getStatement());
}

public function testSelectFieldsWhere()
public function testSelectFieldsWhereOperator()
{
$this->queryMaker->select('users', ['id', 'email'])->where('id', 3);
$this->assertEquals('SELECT id, email FROM users WHERE id=\'3\'', $this->queryMaker->getQuery());
$this->assertEquals('SELECT id, email FROM users WHERE id=:id', $this->queryMaker->getStatement());
$this->queryMaker->select('users', ['id', 'email'])->where('id', '3', '>=');
$this->assertEquals('SELECT id, email FROM users WHERE id >= \'3\'', $this->queryMaker->getQuery());
$this->assertEquals('SELECT id, email FROM users WHERE id >= :id', $this->queryMaker->getStatement());
}

public function testSelectFieldsWhereOperator()
public function testSelectFieldsLIKE()
{
$this->queryMaker->select('users', ['id', 'email'])->where('id', '3', '>=');
$this->assertEquals('SELECT id, email FROM users WHERE id>=\'3\'', $this->queryMaker->getQuery());
$this->assertEquals('SELECT id, email FROM users WHERE id>=:id', $this->queryMaker->getStatement());
$this->queryMaker->select('users', ['id', 'email'])->where('email', '%gmail%', 'LIKE');
$this->assertEquals('SELECT id, email FROM users WHERE email LIKE \'%gmail%\'', $this->queryMaker->getQuery());
$this->assertEquals('SELECT id, email FROM users WHERE email LIKE :email', $this->queryMaker->getStatement());
}

public function testUpdate()
Expand All @@ -88,11 +88,11 @@ public function testUpdate()
3
);
$this->assertEquals(
"UPDATE users SET email='[email protected]', username='midorikocak' WHERE id='3'",
"UPDATE users SET email = '[email protected]', username = 'midorikocak' WHERE id = '3'",
$this->queryMaker->getQuery()
);
$this->assertEquals(
"UPDATE users SET email=:email, username=:username WHERE id=:id",
"UPDATE users SET email = :email, username = :username WHERE id = :id",
$this->queryMaker->getStatement()
);
}
Expand All @@ -115,11 +115,11 @@ public function testWhereAnd()
{
$this->queryMaker->select('users', ['id', 'email'])->where('id', 3)->and('username', 'midori');
$this->assertEquals(
"SELECT id, email FROM users WHERE id='3' AND username='midori'",
"SELECT id, email FROM users WHERE id = '3' AND username = 'midori'",
$this->queryMaker->getQuery()
);
$this->assertEquals(
"SELECT id, email FROM users WHERE id=:id AND username=:username",
"SELECT id, email FROM users WHERE id = :id AND username = :username",
$this->queryMaker->getStatement()
);
}
Expand All @@ -128,11 +128,11 @@ public function testWhereOr()
{
$this->queryMaker->select('users', ['id', 'email'])->where('id', 3)->or('username', 'midori');
$this->assertEquals(
"SELECT id, email FROM users WHERE id='3' OR username='midori'",
"SELECT id, email FROM users WHERE id = '3' OR username = 'midori'",
$this->queryMaker->getQuery()
);
$this->assertEquals(
"SELECT id, email FROM users WHERE id=:id OR username=:username",
"SELECT id, email FROM users WHERE id = :id OR username = :username",
$this->queryMaker->getStatement()
);
}
Expand All @@ -144,11 +144,11 @@ public function testWhereAndOr()
3
)->and('email', '[email protected]')->or('username', 'midori');
$this->assertEquals(
"SELECT id, email FROM users WHERE id='3' AND email='[email protected]' OR username='midori'",
"SELECT id, email FROM users WHERE id = '3' AND email = '[email protected]' OR username = 'midori'",
$this->queryMaker->getQuery()
);
$this->assertEquals(
"SELECT id, email FROM users WHERE id=:id AND email=:email OR username=:username",
"SELECT id, email FROM users WHERE id = :id AND email = :email OR username = :username",
$this->queryMaker->getStatement()
);
}
Expand Down

0 comments on commit 719094b

Please sign in to comment.