QueryInetTest::testInetList()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 13

Duplication

Lines 18
Ratio 100 %

Importance

Changes 0
Metric Value
dl 18
loc 18
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 13
nc 1
nop 0
1
<?php
2
3
namespace evseevnn\Cassandra\Tests;
4
5
use evseevnn\Cassandra;
6
7 View Code Duplication
class QueryInetTest extends Setup\QueryTestCase
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
8
{
9
10
		public function testInetColumn()
11
		{
12
				self::$connection->query('CREATE TABLE InetTest (foo inet PRIMARY KEY, bar inet)');
13
				self::$connection->query(
14
						'INSERT INTO InetTest (foo, bar) VALUES (:foo, :bar)',
15
						['foo' => '192.168.1.2', 'bar' => '192.168.2.5']
16
				);
17
				$result = self::$connection->query('SELECT * FROM InetTest WHERE foo = :foo', ['foo' => '192.168.1.2']);
18
				$this->assertEquals('192.168.2.5', $result[0]['bar']);
19
				$this->assertEquals('192.168.1.2', $result[0]['foo']);
20
		}
21
22
		public function testInetMap()
23
		{
24
				self::$connection->query('CREATE TABLE InetMapTest (foo inet PRIMARY KEY, bar map<inet,inet>)');
25
				self::$connection->query(
26
						'INSERT INTO InetMapTest (foo, bar) VALUES (:foo, :bar)',
27
						['foo' => '192.168.1.2', 'bar' => ['192.168.2.5' => '192.68.2.16']]
28
				);
29
				$result = self::$connection->query('SELECT * FROM InetMapTest WHERE foo = :foo', ['foo' => '192.168.1.2']);
30
				$this->assertEquals(['192.168.2.5' => '192.68.2.16'], $result[0]['bar']);
31
				$this->assertEquals('192.168.1.2', $result[0]['foo']);
32
		}
33
34
		public function testInetSet()
35
		{
36
				self::$connection->query('CREATE TABLE InetSetTest (foo inet PRIMARY KEY, bar set<inet>)');
37
				self::$connection->query(
38
						'INSERT INTO InetSetTest (foo, bar) VALUES (:foo, :bar)',
39
						['foo' => '192.168.1.2', 'bar' => ['192.168.2.5', '2001:470:5284:201:d1c6:6f4a:b7c9:2f9e']]
40
				);
41
				$result = self::$connection->query('SELECT * FROM InetSetTest WHERE foo = :foo', ['foo' => '192.168.1.2']);
42
				$this->assertEquals(['2001:470:5284:201:d1c6:6f4a:b7c9:2f9e', '192.168.2.5'], $result[0]['bar']);
43
				$this->assertEquals('192.168.1.2', $result[0]['foo']);
44
				//according to Spec, this should always be returned alphabetically.
45
				self::$connection->query(
46
						'INSERT INTO InetSetTest (foo, bar) VALUES (:foo, :bar)',
47
						['foo' => '254.220.120.254', 'bar' => ['2001:470:5284:201:d1c6:6f4a:b7c9:2f9e', '192.168.2.5']]
48
				);
49
				$result = self::$connection->query('SELECT * FROM InetSetTest WHERE foo = :foo', ['foo' => '254.220.120.254']);
50
				$this->assertEquals(['2001:470:5284:201:d1c6:6f4a:b7c9:2f9e', '192.168.2.5'], $result[0]['bar']);
51
		}
52
53
		public function testInetList()
54
		{
55
				self::$connection->query('CREATE TABLE InetListTest (foo inet PRIMARY KEY, bar list<inet>)');
56
				self::$connection->query(
57
						'INSERT INTO InetListTest (foo, bar) VALUES (:foo, :bar)',
58
						['foo' => '192.168.1.2', 'bar' => ['192.168.2.5', '2001:470:5284:201:d1c6:6f4a:b7c9:2f9e']]
59
				);
60
				$result = self::$connection->query('SELECT * FROM InetListTest WHERE foo = :foo', ['foo' => '192.168.1.2']);
61
				$this->assertEquals(['192.168.2.5', '2001:470:5284:201:d1c6:6f4a:b7c9:2f9e'], $result[0]['bar']);
62
				$this->assertEquals('192.168.1.2', $result[0]['foo']);
63
				//according to Spec, this should be returned in index order
64
				self::$connection->query(
65
						'INSERT INTO InetListTest (foo, bar) VALUES (:foo, :bar)',
66
						['foo' => '254.220.120.254', 'bar' => ['2001:470:5284:201:d1c6:6f4a:b7c9:2f9e', '192.168.2.5']]
67
				);
68
				$result = self::$connection->query('SELECT * FROM InetListTest WHERE foo = :foo', ['foo' => '254.220.120.254']);
69
				$this->assertEquals(['2001:470:5284:201:d1c6:6f4a:b7c9:2f9e', '192.168.2.5'], $result[0]['bar']);
70
		}
71
72
}