1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace evseevnn\Cassandra\Tests; |
4
|
|
|
|
5
|
|
|
use evseevnn\Cassandra; |
6
|
|
|
|
7
|
|
|
class QueryBooleanTest extends Setup\QueryTestCase |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
public function testBooleanColumn() |
11
|
|
|
{ |
12
|
|
|
self::$connection->query('CREATE TABLE BooleanTest (foo boolean PRIMARY KEY, bar boolean)'); |
13
|
|
|
self::$connection->query( |
14
|
|
|
'INSERT INTO BooleanTest (foo, bar) VALUES (:foo, :bar)', |
15
|
|
|
['foo' => true, 'bar' => false] |
16
|
|
|
); |
17
|
|
|
$result = self::$connection->query('SELECT * FROM BooleanTest WHERE foo = :foo', ['foo' => true]); |
18
|
|
|
$this->assertEquals(false, $result[0]['bar']); |
19
|
|
|
$this->assertEquals(true, $result[0]['foo']); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function testBooleanMap() |
23
|
|
|
{ |
24
|
|
|
self::$connection->query('CREATE TABLE BooleanMapTest (foo boolean PRIMARY KEY, bar map<boolean,boolean>)'); |
25
|
|
|
self::$connection->query( |
26
|
|
|
'INSERT INTO BooleanMapTest (foo, bar) VALUES (:foo, :bar)', |
27
|
|
|
['foo' => true, 'bar' => [false => true]] |
28
|
|
|
); |
29
|
|
|
$result = self::$connection->query('SELECT * FROM BooleanMapTest WHERE foo = :foo', ['foo' => true]); |
30
|
|
|
$this->assertEquals([false => true], $result[0]['bar']); |
31
|
|
|
$this->assertEquals(true, $result[0]['foo']); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
View Code Duplication |
public function testBooleanSet() |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
self::$connection->query('CREATE TABLE BooleanSetTest (foo boolean PRIMARY KEY, bar set<boolean>)'); |
37
|
|
|
self::$connection->query( |
38
|
|
|
'INSERT INTO BooleanSetTest (foo, bar) VALUES (:foo, :bar)', |
39
|
|
|
['foo' => true, 'bar' => [true, false]] |
40
|
|
|
); |
41
|
|
|
$result = self::$connection->query('SELECT * FROM BooleanSetTest WHERE foo = :foo', ['foo' => true]); |
42
|
|
|
$this->assertEquals([false, true], $result[0]['bar']); |
43
|
|
|
$this->assertEquals(true, $result[0]['foo']); |
44
|
|
|
//according to Spec, this should always be returned alphabetically. |
45
|
|
|
self::$connection->query( |
46
|
|
|
'INSERT INTO BooleanSetTest (foo, bar) VALUES (:foo, :bar)', |
47
|
|
|
['foo' => true, 'bar' => [false, true]] |
48
|
|
|
); |
49
|
|
|
$result = self::$connection->query('SELECT * FROM BooleanSetTest WHERE foo = :foo', ['foo' => true]); |
50
|
|
|
$this->assertEquals([false, true], $result[0]['bar']); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
View Code Duplication |
public function testBooleanList() |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
self::$connection->query('CREATE TABLE BooleanListTest (foo boolean PRIMARY KEY, bar list<boolean>)'); |
56
|
|
|
self::$connection->query( |
57
|
|
|
'INSERT INTO BooleanListTest (foo, bar) VALUES (:foo, :bar)', |
58
|
|
|
['foo' => true, 'bar' => [false, true]] |
59
|
|
|
); |
60
|
|
|
$result = self::$connection->query('SELECT * FROM BooleanListTest WHERE foo = :foo', ['foo' => true]); |
61
|
|
|
$this->assertEquals([false, true], $result[0]['bar']); |
62
|
|
|
$this->assertEquals(true, $result[0]['foo']); |
63
|
|
|
//according to Spec, this should be returned in index order - seems for booleans it just doesn't care |
64
|
|
|
self::$connection->query( |
65
|
|
|
'INSERT INTO BooleanListTest (foo, bar) VALUES (:foo, :bar)', |
66
|
|
|
['foo' => false, 'bar' => [true, false]] |
67
|
|
|
); |
68
|
|
|
$result = self::$connection->query('SELECT * FROM BooleanListTest WHERE foo = :foo', ['foo' => false]); |
69
|
|
|
$this->assertEquals([false, true], $result[0]['bar']); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.