Skip to content

Commit 3cdd04d

Browse files
committed
updated tests
1 parent 7c6902e commit 3cdd04d

File tree

5 files changed

+71
-11
lines changed

5 files changed

+71
-11
lines changed

src/Connection.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ public function getParams()
116116
return $this->connection_params;
117117
}
118118

119+
/**
120+
* Returns the internal encoding.
121+
*
122+
* @return string current multibyte internal encoding
123+
*/
124+
public function getInternalEncoding()
125+
{
126+
return $this->internal_encoding;
127+
}
128+
119129
/**
120130
* Returns the connection parameters (host, port) for the current instance.
121131
*
@@ -156,13 +166,13 @@ public function connect($suppress_error = false)
156166
$data = $this->getParams();
157167
$conn = mysqli_init();
158168

159-
if ( ! empty($data['options'])) {
169+
if (!empty($data['options'])) {
160170
foreach ($data['options'] as $option => $value) {
161171
$conn->options($option, $value);
162172
}
163173
}
164174

165-
if ( ! $suppress_error && ! $this->silence_connection_warning) {
175+
if (!$suppress_error && ! $this->silence_connection_warning) {
166176
$conn->real_connect($data['host'], null, null, null, (int) $data['port'], $data['socket']);
167177
} else {
168178
@ $conn->real_connect($data['host'], null, null, null, (int) $data['port'], $data['socket']);
@@ -174,7 +184,6 @@ public function connect($suppress_error = false)
174184
}
175185

176186
$conn->set_charset('utf8');
177-
178187
$this->connection = $conn;
179188
$this->mbPush();
180189

@@ -413,6 +422,8 @@ public function mbPush()
413422
{
414423
$this->internal_encoding = mb_internal_encoding();
415424
mb_internal_encoding('UTF-8');
425+
426+
return $this;
416427
}
417428

418429
/**
@@ -422,5 +433,7 @@ public function mbPop()
422433
{
423434
mb_internal_encoding($this->internal_encoding);
424435
$this->internal_encoding = null;
436+
437+
return $this;
425438
}
426439
}

src/SphinxQL.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,7 @@ function (&$val, $key) {
789789
$query .= 'OPTION '.implode(', ', $options);
790790
}
791791

792+
$query = trim($query);
792793
$this->last_compiled = $query;
793794

794795
return $this;
@@ -826,6 +827,7 @@ public function compileInsert()
826827
$query .= implode(', ', $query_sub);
827828
}
828829

830+
$query = trim($query);
829831
$this->last_compiled = $query;
830832

831833
return $this;
@@ -865,6 +867,7 @@ public function compileUpdate()
865867

866868
$query .= $this->compileMatch().$this->compileWhere();
867869

870+
$query = trim($query);
868871
$this->last_compiled = $query;
869872

870873
return $this;
@@ -887,6 +890,7 @@ public function compileDelete()
887890
$query .= $this->compileWhere();
888891
}
889892

893+
$query = trim($query);
890894
$this->last_compiled = $query;
891895

892896
return $this;
@@ -1399,13 +1403,6 @@ public function reset()
13991403
return $this;
14001404
}
14011405

1402-
public function resetOrderBy()
1403-
{
1404-
$this->order_by = array();
1405-
1406-
return $this;
1407-
}
1408-
14091406
public function resetWhere()
14101407
{
14111408
$this->where = array();
@@ -1434,6 +1431,13 @@ public function resetWithinGroupOrderBy()
14341431
return $this;
14351432
}
14361433

1434+
public function resetOrderBy()
1435+
{
1436+
$this->order_by = array();
1437+
1438+
return $this;
1439+
}
1440+
14371441
public function resetOptions()
14381442
{
14391443
$this->options = array();

tests/classes/ConnectionTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ public function setUp()
1414
$this->connection->silenceConnectionWarning(false);
1515
}
1616

17+
public function tearDown()
18+
{
19+
$this->connection = null;
20+
}
21+
1722
public function test()
1823
{
1924
new Connection();
@@ -209,4 +214,16 @@ public function testQuoteArr()
209214
$this->connection->quoteArr(array(null, true, false, new Expression("fo'o'bar"), 123, 12.3, '12.3', '12'))
210215
);
211216
}
217+
218+
public function testMbPush()
219+
{
220+
$this->connection->mbPush();
221+
$this->assertEquals('UTF-8', $this->connection->getInternalEncoding());
222+
}
223+
224+
public function testMbPop()
225+
{
226+
$this->connection->mbPush()->mbPop();
227+
$this->assertEquals(null, $this->connection->getInternalEncoding());
228+
}
212229
}

tests/classes/HelperTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public function testDescribe()
3434
array_shift($describe);
3535
$this->assertSame(
3636
array(
37-
// array('Field' => 'id', 'Type' => 'integer'), this can be bigint on id64 sphinx
3837
array('Field' => 'title', 'Type' => 'field'),
3938
array('Field' => 'content', 'Type' => 'field'),
4039
array('Field' => 'gid', 'Type' => 'uint'),

tests/classes/SphinxQLTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,4 +573,31 @@ public function testQueue()
573573
$this->assertEquals('1', $result[1][0]['Value']);
574574
$this->assertEquals('11', $result[2][0]['id']);
575575
}
576+
577+
/**
578+
* @covers \Foolz\SphinxQL\SphinxQL::resetWhere
579+
* @covers \Foolz\SphinxQL\SphinxQL::resetMatch
580+
* @covers \Foolz\SphinxQL\SphinxQL::resetGroupBy
581+
* @covers \Foolz\SphinxQL\SphinxQL::resetWithinGroupOrderBy
582+
* @covers \Foolz\SphinxQL\SphinxQL::resetOptions
583+
*/
584+
public function testResetMethods()
585+
{
586+
$result = SphinxQL::create($this->conn)->select()
587+
->from('rt')
588+
->where('id', 'IN', array(10, 11))
589+
->resetWhere()
590+
->match('title', 'value')
591+
->resetMatch()
592+
->groupBy('gid')
593+
->resetGroupBy()
594+
->withinGroupOrderBy('id', 'desc')
595+
->resetWithinGroupOrderBy()
596+
->option('comment', 'this should be quoted')
597+
->resetOptions()
598+
->compile()
599+
->getCompiled();
600+
601+
$this->assertEquals('SELECT * FROM `rt`', $result);
602+
}
576603
}

0 commit comments

Comments
 (0)