PgSQLTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 39
c 1
b 0
f 0
dl 0
loc 64
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 2
A testToSource() 0 49 1
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2018-2025
6
 */
7
8
9
namespace Aimeos\Base\Criteria\Expression\Compare;
10
11
12
class PgSQLTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $conn;
15
16
17
	protected function setUp() : void
18
	{
19
		if( \TestHelper::getConfig()->get( 'resource/db/adapter', false ) === false ) {
20
			$this->markTestSkipped( 'No database configured' );
21
		}
22
23
		$this->conn = \TestHelper::getConnection();
24
	}
25
26
27
	public function testToSource()
28
	{
29
		$types = array(
30
			'list' => \Aimeos\Base\DB\Statement\Base::PARAM_STR,
31
			'string' => \Aimeos\Base\DB\Statement\Base::PARAM_STR,
32
			'float' => \Aimeos\Base\DB\Statement\Base::PARAM_FLOAT,
33
			'int' => \Aimeos\Base\DB\Statement\Base::PARAM_INT,
34
			'undefined' => \Aimeos\Base\DB\Statement\Base::PARAM_INT,
35
			'bool' => \Aimeos\Base\DB\Statement\Base::PARAM_BOOL,
36
		);
37
38
		$translations = array(
39
			'list' => 't.list',
40
			'string' => 't.string',
41
			'float' => 't.float',
42
			'int' => 't.int',
43
			'undefined' => 't.undefined',
44
			'bool' => 't.bool',
45
		);
46
47
		$expr = new \Aimeos\Base\Criteria\Expression\Compare\PgSQL( $this->conn, '==', 'list', array( 'a', 'b', 'c' ) );
48
		$this->assertEquals( "t.list IN ('a','b','c')", $expr->toSource( $types, $translations ) );
49
50
		$expr = new \Aimeos\Base\Criteria\Expression\Compare\PgSQL( $this->conn, '!=', 'list', array( 'a', 'b', 'c' ) );
51
		$this->assertEquals( "t.list NOT IN ('a','b','c')", $expr->toSource( $types, $translations ) );
52
53
		$expr = new \Aimeos\Base\Criteria\Expression\Compare\PgSQL( $this->conn, '~=', 'string', 'value' );
54
		$this->assertEquals( "t.string LIKE '%value%' ESCAPE '#'", $expr->toSource( $types, $translations ) );
55
56
		$expr = new \Aimeos\Base\Criteria\Expression\Compare\PgSQL( $this->conn, '<', 'float', 0.1 );
57
		$this->assertEquals( "t.float < 0.1", $expr->toSource( $types, $translations ) );
58
59
		$expr = new \Aimeos\Base\Criteria\Expression\Compare\PgSQL( $this->conn, '==', 'float', '' );
60
		$this->assertEquals( "t.float IS NULL", $expr->toSource( $types, $translations ) );
61
62
		$expr = new \Aimeos\Base\Criteria\Expression\Compare\PgSQL( $this->conn, '>', 'int', 10 );
63
		$this->assertEquals( "t.int > 10", $expr->toSource( $types, $translations ) );
64
65
		$expr = new \Aimeos\Base\Criteria\Expression\Compare\PgSQL( $this->conn, '==', 'int', '' );
66
		$this->assertEquals( "t.int IS NULL", $expr->toSource( $types, $translations ) );
67
68
		$expr = new \Aimeos\Base\Criteria\Expression\Compare\PgSQL( $this->conn, '!=', 'undefined', null );
69
		$this->assertEquals( "t.undefined IS NOT NULL", $expr->toSource( $types, $translations ) );
70
71
		$expr = new \Aimeos\Base\Criteria\Expression\Compare\PgSQL( $this->conn, '==', 'bool', true );
72
		$this->assertEquals( "t.bool = 't'", $expr->toSource( $types, $translations ) );
73
74
		$expr = new \Aimeos\Base\Criteria\Expression\Compare\PgSQL( $this->conn, '==', 'bool', false );
75
		$this->assertEquals( "t.bool = 'f'", $expr->toSource( $types, $translations ) );
76
	}
77
}
78