Passed
Push — master ( 9b3ef7...f502a6 )
by Aimeos
02:50
created

PgSQLTest::testToSource()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 43
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 30
c 1
b 0
f 0
dl 0
loc 43
rs 9.44
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2018-2022
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( \TestHelperMw::getConfig()->get( 'resource/db/adapter', false ) === false ) {
0 ignored issues
show
Bug introduced by
The type TestHelperMw was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
			$this->markTestSkipped( 'No database configured' );
21
		}
22
23
24
		$dbm = \TestHelperMw::getDBManager();
25
		$this->conn = $dbm->acquire();
26
	}
27
28
	protected function tearDown() : void
29
	{
30
		$dbm = \TestHelperMw::getDBManager();
31
		$dbm->release( $this->conn );
32
	}
33
34
35
	public function testToSource()
36
	{
37
		$types = array(
38
			'list' => \Aimeos\Base\DB\Statement\Base::PARAM_STR,
39
			'string' => \Aimeos\Base\DB\Statement\Base::PARAM_STR,
40
			'float' => \Aimeos\Base\DB\Statement\Base::PARAM_FLOAT,
41
			'int' => \Aimeos\Base\DB\Statement\Base::PARAM_INT,
42
			'undefined' => \Aimeos\Base\DB\Statement\Base::PARAM_INT,
43
			'bool' => \Aimeos\Base\DB\Statement\Base::PARAM_BOOL,
44
		);
45
46
		$translations = array(
47
			'list' => 't.list',
48
			'string' => 't.string',
49
			'float' => 't.float',
50
			'int' => 't.int',
51
			'undefined' => 't.undefined',
52
			'bool' => 't.bool',
53
		);
54
55
		$expr = new \Aimeos\Base\Criteria\Expression\Compare\PgSQL( $this->conn, '==', 'list', array( 'a', 'b', 'c' ) );
56
		$this->assertEquals( "t.list IN ('a','b','c')", $expr->toSource( $types, $translations ) );
57
58
		$expr = new \Aimeos\Base\Criteria\Expression\Compare\PgSQL( $this->conn, '!=', 'list', array( 'a', 'b', 'c' ) );
59
		$this->assertEquals( "t.list NOT IN ('a','b','c')", $expr->toSource( $types, $translations ) );
60
61
		$expr = new \Aimeos\Base\Criteria\Expression\Compare\PgSQL( $this->conn, '~=', 'string', 'value' );
62
		$this->assertEquals( "t.string LIKE '%value%' ESCAPE '#'", $expr->toSource( $types, $translations ) );
63
64
		$expr = new \Aimeos\Base\Criteria\Expression\Compare\PgSQL( $this->conn, '<', 'float', 0.1 );
65
		$this->assertEquals( "t.float < 0.1", $expr->toSource( $types, $translations ) );
66
67
		$expr = new \Aimeos\Base\Criteria\Expression\Compare\PgSQL( $this->conn, '>', 'int', 10 );
68
		$this->assertEquals( "t.int > 10", $expr->toSource( $types, $translations ) );
69
70
		$expr = new \Aimeos\Base\Criteria\Expression\Compare\PgSQL( $this->conn, '!=', 'undefined', null );
71
		$this->assertEquals( "t.undefined IS NOT NULL", $expr->toSource( $types, $translations ) );
72
73
		$expr = new \Aimeos\Base\Criteria\Expression\Compare\PgSQL( $this->conn, '==', 'bool', true );
74
		$this->assertEquals( "t.bool = 't'", $expr->toSource( $types, $translations ) );
75
76
		$expr = new \Aimeos\Base\Criteria\Expression\Compare\PgSQL( $this->conn, '==', 'bool', false );
77
		$this->assertEquals( "t.bool = 'f'", $expr->toSource( $types, $translations ) );
78
	}
79
}
80