QueryVarcharTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 66
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 66
loc 66
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testVarcharColumn() 11 11 1
A testVarcharMap() 11 11 1
A testVarcharSet() 18 18 1
A testVarcharList() 18 18 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace evseevnn\Cassandra\Tests;
4
5
use evseevnn\Cassandra;
6
7 View Code Duplication
class QueryVarcharTest 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 testVarcharColumn()
11
		{
12
				self::$connection->query('CREATE TABLE VarcharTest (foo varchar PRIMARY KEY, bar varchar)');
13
				self::$connection->query(
14
						'INSERT INTO VarcharTest (foo, bar) VALUES (:foo, :bar)',
15
						['foo' => 'baz', 'bar' => 'barbaz']
16
				);
17
				$result = self::$connection->query('SELECT * FROM VarcharTest WHERE foo = :foo', ['foo' => 'baz']);
18
				$this->assertEquals('barbaz', $result[0]['bar']);
19
				$this->assertEquals('baz', $result[0]['foo']);
20
		}
21
22
		public function testVarcharMap()
23
		{
24
				self::$connection->query('CREATE TABLE VarcharMapTest (foo varchar PRIMARY KEY, bar map<varchar,varchar>)');
25
				self::$connection->query(
26
						'INSERT INTO VarcharMapTest (foo, bar) VALUES (:foo, :bar)',
27
						['foo' => 'baz', 'bar' => ['barbaz' => 'bazbar']]
28
				);
29
				$result = self::$connection->query('SELECT * FROM VarcharMapTest WHERE foo = :foo', ['foo' => 'baz']);
30
				$this->assertEquals(['barbaz' => 'bazbar'], $result[0]['bar']);
31
				$this->assertEquals('baz', $result[0]['foo']);
32
		}
33
34
		public function testVarcharSet()
35
		{
36
				self::$connection->query('CREATE TABLE VarcharSetTest (foo varchar PRIMARY KEY, bar set<varchar>)');
37
				self::$connection->query(
38
						'INSERT INTO VarcharSetTest (foo, bar) VALUES (:foo, :bar)',
39
						['foo' => 'baz', 'bar' => ['barbaz', 'bazbar']]
40
				);
41
				$result = self::$connection->query('SELECT * FROM VarcharSetTest WHERE foo = :foo', ['foo' => 'baz']);
42
				$this->assertEquals(['barbaz', 'bazbar'], $result[0]['bar']);
43
				$this->assertEquals('baz', $result[0]['foo']);
44
				//according to Spec, this should always be returned alphabetically.
45
				self::$connection->query(
46
						'INSERT INTO VarcharSetTest (foo, bar) VALUES (:foo, :bar)',
47
						['foo' => 'baz2', 'bar' => ['bazbar', 'barbaz']]
48
				);
49
				$result = self::$connection->query('SELECT * FROM VarcharSetTest WHERE foo = :foo', ['foo' => 'baz2']);
50
				$this->assertEquals(['barbaz', 'bazbar'], $result[0]['bar']);
51
		}
52
53
		public function testVarcharList()
54
		{
55
				self::$connection->query('CREATE TABLE VarcharListTest (foo varchar PRIMARY KEY, bar list<varchar>)');
56
				self::$connection->query(
57
						'INSERT INTO VarcharListTest (foo, bar) VALUES (:foo, :bar)',
58
						['foo' => 'baz', 'bar' => ['barbaz', 'bazbar']]
59
				);
60
				$result = self::$connection->query('SELECT * FROM VarcharListTest WHERE foo = :foo', ['foo' => 'baz']);
61
				$this->assertEquals(['barbaz', 'bazbar'], $result[0]['bar']);
62
				$this->assertEquals('baz', $result[0]['foo']);
63
				//according to Spec, this should be returned in index order
64
				self::$connection->query(
65
						'INSERT INTO VarcharListTest (foo, bar) VALUES (:foo, :bar)',
66
						['foo' => 'baz2', 'bar' => ['bazbar', 'barbaz']]
67
				);
68
				$result = self::$connection->query('SELECT * FROM VarcharListTest WHERE foo = :foo', ['foo' => 'baz2']);
69
				$this->assertEquals(['bazbar', 'barbaz'], $result[0]['bar']);
70
		}
71
72
}