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

SQLTest::testGetOperators()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2011
6
 * @copyright Aimeos (aimeos.org), 2015-2022
7
 */
8
9
10
namespace Aimeos\Base\Criteria\Expression\Sort;
11
12
13
class SQLTest extends \PHPUnit\Framework\TestCase
14
{
15
	private $conn = null;
16
17
18
	protected function setUp() : void
19
	{
20
		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...
21
			$this->markTestSkipped( 'No database configured' );
22
		}
23
24
25
		$dbm = \TestHelperMw::getDBManager();
26
		$this->conn = $dbm->acquire();
27
	}
28
29
30
	protected function tearDown() : void
31
	{
32
		$dbm = \TestHelperMw::getDBManager();
33
		$dbm->release( $this->conn );
34
	}
35
36
37
	public function testGetOperators()
38
	{
39
		$expected = array( '+', '-' );
40
		$actual = \Aimeos\Base\Criteria\Expression\Sort\SQL::getOperators();
41
		$this->assertEquals( $expected, $actual );
42
	}
43
44
45
	public function testGetOperator()
46
	{
47
		$expr = new \Aimeos\Base\Criteria\Expression\Sort\SQL( $this->conn, '+', 'test' );
48
		$this->assertEquals( '+', $expr->getOperator() );
49
	}
50
51
52
	public function testGetName()
53
	{
54
		$expr = new \Aimeos\Base\Criteria\Expression\Sort\SQL( $this->conn, '-', 'test' );
55
		$this->assertEquals( 'test', $expr->getName() );
56
	}
57
58
59
	public function testToString()
60
	{
61
		$types = array(
62
			'test' => \Aimeos\Base\DB\Statement\Base::PARAM_STR,
63
			'test()' => \Aimeos\Base\DB\Statement\Base::PARAM_STR,
64
		);
65
66
		$translations = array(
67
			'test()' => 'testfunc($1,$2)',
68
		);
69
70
		$object = new \Aimeos\Base\Criteria\Expression\Sort\SQL( $this->conn, '-', 'test' );
71
		$this->assertEquals( 'test DESC', $object->toSource( $types ) );
72
73
		$object = new \Aimeos\Base\Criteria\Expression\Sort\SQL( $this->conn, '+', 'test(1,2.1)' );
74
		$this->assertEquals( 'testfunc(1,2.1) ASC', $object->toSource( $types, $translations ) );
75
76
		$object = new \Aimeos\Base\Criteria\Expression\Sort\SQL( $this->conn, '-', 'test("a",2)' );
77
		$this->assertEquals( 'testfunc(\'a\',2) DESC', $object->toSource( $types, $translations ) );
78
	}
79
80
81
	public function testToArray()
82
	{
83
		$dbm = \TestHelperMw::getDBManager();
84
		$conn = $dbm->acquire();
85
		$dbm->release( $conn );
86
87
		$object = new \Aimeos\Base\Criteria\Expression\Sort\SQL( $conn, '+', 'stringvar' );
88
89
		$this->assertEquals( ['stringvar' => '+'], $object->__toArray() );
90
	}
91
}
92