Skip to content

Commit 4755041

Browse files
committed
Scrub some deprecated methods. Code formatting.
1 parent f241871 commit 4755041

File tree

7 files changed

+48
-119
lines changed

7 files changed

+48
-119
lines changed

src/Command.php

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,6 @@ public function bind($key, $value = null)
5252
return $this;
5353
}
5454

55-
/**
56-
* @deprecated
57-
*
58-
* @param $params
59-
* @return $this
60-
*/
61-
public function bindValues($params)
62-
{
63-
return $this->bind($params);
64-
}
65-
6655
/**
6756
* @param Connection $connection
6857
* @return string
@@ -110,16 +99,4 @@ protected function quoteIntoSql(Connection $connection)
11099

111100
return strtr($quotedSql, $quotedParams);
112101
}
113-
114-
/**
115-
* @deprecated
116-
*
117-
* @return \React\Promise\Promise
118-
*/
119-
public function execute()
120-
{
121-
$thing = $this->db->executeCommand($this);
122-
123-
return $thing;
124-
}
125102
}

src/Connection.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php namespace DustinGraham\ReactMysql;
22

3-
use React\EventLoop\LoopInterface;
43
use React\EventLoop\Timer\TimerInterface;
54
use React\Promise\Deferred;
65

@@ -39,16 +38,6 @@ public function escape($string)
3938
return $this->real_escape_string($string);
4039
}
4140

42-
/**
43-
* @deprecated
44-
*
45-
* Close the mysqli connection.
46-
*/
47-
public function close()
48-
{
49-
$this->mysqli->close();
50-
}
51-
5241
public function execute(Command $command)
5342
{
5443
if ($this->currentQuery)

src/ConnectionFactory.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php namespace DustinGraham\ReactMysql;
22

3-
use React\EventLoop\LoopInterface;
4-
53
class ConnectionFactory
64
{
75
/**

src/ConnectionPool.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public function withConnection($cb)
4141
$connection = $this->available->dequeue();
4242

4343
$cb($connection);
44+
4445
return;
4546
}
4647

src/Database.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function createCommand($sql = null, $params = [])
4444
{
4545
$command = new Command($this, $sql);
4646

47-
return $command->bindValues($params);
47+
return $command->bind($params);
4848
}
4949

5050
/**
@@ -86,7 +86,7 @@ public function executeCommand(Command $command)
8686

8787
/**
8888
* @deprecated Remove from tests.
89-
*
89+
*
9090
* @return ConnectionPool
9191
*/
9292
public function getPool()
@@ -100,7 +100,7 @@ public function statement($sql, $params = null)
100100

101101
$deferred = new Deferred();
102102

103-
$this->pool->withConnection(function(Connection $connection) use ($command, $deferred)
103+
$this->pool->withConnection(function (Connection $connection) use ($command, $deferred)
104104
{
105105
$sql = $command->getPreparedQuery($connection);
106106

@@ -144,7 +144,7 @@ public function loopTick(TimerInterface $timer)
144144
}
145145

146146
$reads = $errors = $rejects = [];
147-
foreach($this->conns as $conn)
147+
foreach ($this->conns as $conn)
148148
{
149149
$reads[] = $conn['mysqli'];
150150
}
@@ -153,7 +153,7 @@ public function loopTick(TimerInterface $timer)
153153
if (mysqli_poll($reads, $errors, $rejects, 0) < 1) return;
154154

155155
/** @var Connection $read */
156-
foreach($reads as $read)
156+
foreach ($reads as $read)
157157
{
158158
/** @var Deferred $deferred */
159159
$deferred = $this->conns[$read->id]['deferred'];
@@ -181,7 +181,7 @@ public function loopTick(TimerInterface $timer)
181181
// Check error pile.
182182
// Current understanding is that this would only happen if the connection
183183
// was closed, or not opened correctly.
184-
foreach($errors as $error)
184+
foreach ($errors as $error)
185185
{
186186
$this->pool->releaseConnection($error);
187187
unset($this->conns[$error->id]);
@@ -192,7 +192,7 @@ public function loopTick(TimerInterface $timer)
192192
// Check rejection pile.
193193
// Current understanding is that this would only happen if we passed a
194194
// connection that was already reaped. But... maybe not.
195-
foreach($rejects as $reject)
195+
foreach ($rejects as $reject)
196196
{
197197
$this->pool->releaseConnection($reject);
198198
unset($this->conns[$reject->id]);

tests/DatabaseTest.php

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ public function XtestCommandClass()
2020
$command = $db->createCommand();
2121

2222
$this->assertInstanceOf(Command::class, $command);
23-
24-
$command->bindValues([]);
2523
}
2624

2725
public function disabled_testMysqliConnection()
@@ -78,30 +76,6 @@ public function disabled_testMysqliAsynchronous()
7876
$this->assertEquals(3, $result->num_rows);
7977
}
8078

81-
public function disabled_testCreateCommandGetPromise()
82-
{
83-
$db = new Database();
84-
85-
$cmd = $db->createCommand();
86-
87-
$cmd->sql = 'SELECT * FROM simple_table WHERE id = :id';
88-
$cmd->bind(':id', 1);
89-
90-
$promise = $cmd->execute();
91-
$this->assertInstanceOf(Promise::class, $promise);
92-
93-
////
94-
95-
$promise = $db->createCommand(
96-
'SELECT * FROM simple_table WHERE id = :test',
97-
[
98-
':test',
99-
1,
100-
]
101-
)->execute();
102-
$this->assertInstanceOf(Promise::class, $promise);
103-
}
104-
10579
// TODO: This test is still todo.
10680
public function disabled_testParamCounting()
10781
{
@@ -128,37 +102,6 @@ public function disabled_testParamCounting()
128102
$query,
129103
'SELECT * FROM simple_table WHERE id = :test'
130104
);
131-
132-
$connection->close();
133-
}
134-
135-
public function disabled_testCommandResolvedResults()
136-
{
137-
$rowCount = false;
138-
$failedReason = false;
139-
140-
$db = new Database();
141-
142-
$db->createCommand(
143-
'SELECT * FROM simple_table WHERE id = :test',
144-
[':test' => 1,]
145-
)
146-
->execute()
147-
->then(function (\mysqli_result $results) use (&$rowCount)
148-
{
149-
$rows = $results->fetch_all(MYSQLI_ASSOC);
150-
$rowCount = count($rows);
151-
})
152-
->otherwise(function ($reason) use (&$failedReason)
153-
{
154-
$failedReason = $reason;
155-
});
156-
157-
ConnectionFactory::$loop->run();
158-
159-
$this->assertFalse($failedReason);
160-
161-
$this->assertEquals(1, $rowCount);
162105
}
163106

164107
public function disabled_testAssertStrings()
@@ -212,25 +155,6 @@ public function disabled_testComplexCommandParameterBinding()
212155
"INSERT INTO simple_table ( `id`, `name`, `value`, `created_at` ) VALUES ( NULL, 'John Cash', 7, NOW() );",
213156
$query
214157
);
215-
216-
$connection->close();
217-
}
218-
219-
public function disabled_testBadQuery()
220-
{
221-
$db = new Database();
222-
223-
$failedReason = null;
224-
$db->createCommand('SELECT * FROM `nonexistant_table`;')
225-
->execute()
226-
->otherwise(function ($reason) use (&$failedReason)
227-
{
228-
$failedReason = $reason;
229-
});
230-
231-
ConnectionFactory::$loop->run();
232-
233-
$this->assertNotNull($failedReason);
234158
}
235159

236160
public function disabled_testPool()

tests/RebuildTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use React\EventLoop\Factory;
88
use React\Promise\Deferred;
99
use React\Promise\Promise;
10+
use React\Promise\UnhandledRejectionException;
1011

1112
class RebuildTest extends TestCaseDatabase
1213
{
@@ -117,6 +118,45 @@ public function testFreeResult()
117118
$db->loop->run();
118119
}
119120

121+
public function testBadQuery()
122+
{
123+
$db = $this->getDatabase();
124+
125+
$errorTriggered = false;
126+
$db->statement('SELECT foo FROM')
127+
->then(function(\mysqli_result $result)
128+
{
129+
$this->fail();
130+
})
131+
->otherwise(function($error) use (&$errorTriggered)
132+
{
133+
$errorTriggered = !!$error;
134+
})
135+
->done();
136+
137+
$db->shuttingDown = true;
138+
$db->loop->run();
139+
140+
$this->assertTrue($errorTriggered, 'Error was sent to otherwise callback.');
141+
}
142+
143+
public function testUnhandledBadQuery()
144+
{
145+
$db = $this->getDatabase();
146+
147+
$db->statement('SELECT foo FROM')
148+
->then(function(\mysqli_result $result)
149+
{
150+
$this->fail();
151+
})
152+
->done();
153+
154+
$this->setExpectedException(UnhandledRejectionException::class);
155+
156+
$db->shuttingDown = true;
157+
$db->loop->run();
158+
}
159+
120160
/**
121161
* Works Brilliantly
122162
*/

0 commit comments

Comments
 (0)