Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Query/Expression/BinaryOperatorExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public function __construct(
*/
public function negate()
{
$this->negated = true;
$this->negatedInt = 1;
$this->negated = !$this->negated;
$this->negatedInt = $this->negated ? 1 : 0;
}

/**
Expand Down
36 changes: 36 additions & 0 deletions tests/EndToEndTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,42 @@ public function testNegateOperationWithOr()
$this->assertSame([['count' => 9]], $query->fetchAll(\PDO::FETCH_ASSOC));
}

public function testNullEvaluation()
{
$pdo = self::getConnectionToFullDB(false);

// case 1, where console value is null
$query = $pdo->prepare("SELECT COUNT(*) as 'count' FROM `video_game_characters` WHERE (:console IS NULL AND `console` = 'gameboy') OR NOT (:console IS NULL)");
$query->bindValue(':console', NULL);
$query->execute();
$this->assertSame([['count' => 1]], $query->fetchAll(\PDO::FETCH_ASSOC));

// case 2, where console value is not null
$query = $pdo->prepare("SELECT COUNT(*) as 'count' FROM `video_game_characters` WHERE (:console IS NULL AND `console` = 'gameboy') OR NOT (:console IS NULL)");
$query->bindValue(':console', 'all');
$query->execute();
$this->assertSame([['count' => 16]], $query->fetchAll(\PDO::FETCH_ASSOC));
}

public function testNullWithDoubleNegativeEvaluation()
{
$pdo = self::getConnectionToFullDB(false);

//case 1, where console value is not null
$query = $pdo->prepare("SELECT COUNT(*) as 'count' FROM `video_game_characters` WHERE (:console IS NOT NULL AND `console` = :console) OR NOT (:console IS NOT NULL)");
$query->bindValue(':console', 'gameboy');
$query->execute();

$this->assertSame([['count' => 1]], $query->fetchAll(\PDO::FETCH_ASSOC));

//case 1, where console value is null
$query = $pdo->prepare("SELECT COUNT(*) as 'count' FROM `video_game_characters` WHERE (:console IS NOT NULL AND `console` = :console) OR NOT (:console IS NOT NULL)");
$query->bindValue(':console', NULL);
$query->execute();

$this->assertSame([['count' => 16]], $query->fetchAll(\PDO::FETCH_ASSOC));
}

private static function getPdo(string $connection_string, bool $strict_mode = false) : \PDO
{
$options = $strict_mode ? [\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET sql_mode="STRICT_ALL_TABLES"'] : [];
Expand Down
Loading