Skip to content

Commit b611352

Browse files
committed
Clean up test suite
1 parent 4f086ce commit b611352

File tree

4 files changed

+58
-56
lines changed

4 files changed

+58
-56
lines changed

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
"autoload": {
1414
"psr-4": { "Clue\\React\\SQLite\\": "src/" }
1515
},
16+
"autoload-dev": {
17+
"psr-4": { "Clue\\Tests\\React\\SQLite\\": "tests/" }
18+
},
1619
"require": {
1720
"php": ">=5.4",
1821
"ext-sqlite3": "*",

phpunit.xml.dist

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<phpunit bootstrap="vendor/autoload.php"
4-
colors="true"
5-
convertErrorsToExceptions="true"
6-
convertNoticesToExceptions="true"
7-
convertWarningsToExceptions="true"
8-
>
3+
<phpunit bootstrap="vendor/autoload.php" colors="true">
94
<testsuites>
105
<testsuite name="SQLite React Test Suite">
116
<directory>./tests/</directory>

tests/FactoryTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace Clue\Tests\React\SQLite;
4+
35
use PHPUnit\Framework\TestCase;
46
use Clue\React\SQLite\Factory;
57

@@ -22,7 +24,7 @@ public function testLoadLazyWithIdleOptionsReturnsDatabaseWithIdleTimeApplied()
2224

2325
$db = $factory->openLazy(':memory:', null, ['idle' => 10.0]);
2426

25-
$ref = new ReflectionProperty($db, 'idlePeriod');
27+
$ref = new \ReflectionProperty($db, 'idlePeriod');
2628
$ref->setAccessible(true);
2729
$value = $ref->getValue($db);
2830

@@ -36,7 +38,7 @@ public function testLoadLazyWithAbsolutePathWillBeUsedAsIs()
3638

3739
$db = $factory->openLazy(__DIR__ . '/users.db');
3840

39-
$ref = new ReflectionProperty($db, 'filename');
41+
$ref = new \ReflectionProperty($db, 'filename');
4042
$ref->setAccessible(true);
4143
$value = $ref->getValue($db);
4244

@@ -50,7 +52,7 @@ public function testLoadLazyWithMemoryPathWillBeUsedAsIs()
5052

5153
$db = $factory->openLazy(':memory:');
5254

53-
$ref = new ReflectionProperty($db, 'filename');
55+
$ref = new \ReflectionProperty($db, 'filename');
5456
$ref->setAccessible(true);
5557
$value = $ref->getValue($db);
5658

@@ -64,7 +66,7 @@ public function testLoadLazyWithEmptyPathWillBeUsedAsIs()
6466

6567
$db = $factory->openLazy('');
6668

67-
$ref = new ReflectionProperty($db, 'filename');
69+
$ref = new \ReflectionProperty($db, 'filename');
6870
$ref->setAccessible(true);
6971
$value = $ref->getValue($db);
7072

@@ -85,7 +87,7 @@ public function testLoadLazyWithRelativePathWillBeResolvedWhenConstructingAndWil
8587

8688
chdir('../');
8789

88-
$ref = new ReflectionProperty($db, 'filename');
90+
$ref = new \ReflectionProperty($db, 'filename');
8991
$ref->setAccessible(true);
9092
$value = $ref->getValue($db);
9193

tests/FunctionalDatabaseTest.php

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace Clue\Tests\React\SQLite;
4+
35
use Clue\React\SQLite\DatabaseInterface;
46
use Clue\React\SQLite\Factory;
57
use Clue\React\SQLite\Result;
@@ -22,10 +24,10 @@ public function provideSocketFlags()
2224
*/
2325
public function testOpenMemoryDatabaseResolvesWithDatabaseAndRunsUntilClose($flag)
2426
{
25-
$loop = React\EventLoop\Factory::create();
27+
$loop = \React\EventLoop\Factory::create();
2628
$factory = new Factory($loop);
2729

28-
$ref = new ReflectionProperty($factory, 'useSocket');
30+
$ref = new \ReflectionProperty($factory, 'useSocket');
2931
$ref->setAccessible(true);
3032
$ref->setValue($factory, $flag);
3133

@@ -48,10 +50,10 @@ public function testOpenMemoryDatabaseResolvesWithDatabaseAndRunsUntilClose($fla
4850
*/
4951
public function testOpenMemoryDatabaseResolvesWithDatabaseAndRunsUntilQuit($flag)
5052
{
51-
$loop = React\EventLoop\Factory::create();
53+
$loop = \React\EventLoop\Factory::create();
5254
$factory = new Factory($loop);
5355

54-
$ref = new ReflectionProperty($factory, 'useSocket');
56+
$ref = new \ReflectionProperty($factory, 'useSocket');
5557
$ref->setAccessible(true);
5658
$ref->setValue($factory, $flag);
5759

@@ -77,7 +79,7 @@ public function testOpenMemoryDatabaseShouldNotInheritActiveFileDescriptors()
7779
$this->markTestSkipped('Platform does not prevent binding to same address (Windows?)');
7880
}
7981

80-
$loop = React\EventLoop\Factory::create();
82+
$loop = \React\EventLoop\Factory::create();
8183
$factory = new Factory($loop);
8284

8385
$promise = $factory->open(':memory:');
@@ -115,10 +117,10 @@ public function testOpenMemoryDatabaseShouldNotInheritActiveFileDescriptors()
115117
*/
116118
public function testOpenInvalidPathRejects($flag)
117119
{
118-
$loop = React\EventLoop\Factory::create();
120+
$loop = \React\EventLoop\Factory::create();
119121
$factory = new Factory($loop);
120122

121-
$ref = new ReflectionProperty($factory, 'useSocket');
123+
$ref = new \ReflectionProperty($factory, 'useSocket');
122124
$ref->setAccessible(true);
123125
$ref->setValue($factory, $flag);
124126

@@ -138,10 +140,10 @@ public function testOpenInvalidPathRejects($flag)
138140
*/
139141
public function testOpenInvalidFlagsRejects($flag)
140142
{
141-
$loop = React\EventLoop\Factory::create();
143+
$loop = \React\EventLoop\Factory::create();
142144
$factory = new Factory($loop);
143145

144-
$ref = new ReflectionProperty($factory, 'useSocket');
146+
$ref = new \ReflectionProperty($factory, 'useSocket');
145147
$ref->setAccessible(true);
146148
$ref->setValue($factory, $flag);
147149

@@ -161,10 +163,10 @@ public function testOpenInvalidFlagsRejects($flag)
161163
*/
162164
public function testQuitResolvesAndRunsUntilQuit($flag)
163165
{
164-
$loop = React\EventLoop\Factory::create();
166+
$loop = \React\EventLoop\Factory::create();
165167
$factory = new Factory($loop);
166168

167-
$ref = new ReflectionProperty($factory, 'useSocket');
169+
$ref = new \ReflectionProperty($factory, 'useSocket');
168170
$ref->setAccessible(true);
169171
$ref->setValue($factory, $flag);
170172

@@ -189,10 +191,10 @@ public function testQuitResolvesAndRunsUntilQuitWhenParentHasManyFileDescriptors
189191
$servers[] = stream_socket_server('tcp://127.0.0.1:0');
190192
}
191193

192-
$loop = React\EventLoop\Factory::create();
194+
$loop = \React\EventLoop\Factory::create();
193195
$factory = new Factory($loop);
194196

195-
$ref = new ReflectionProperty($factory, 'useSocket');
197+
$ref = new \ReflectionProperty($factory, 'useSocket');
196198
$ref->setAccessible(true);
197199
$ref->setValue($factory, $flag);
198200

@@ -216,10 +218,10 @@ public function testQuitResolvesAndRunsUntilQuitWhenParentHasManyFileDescriptors
216218
*/
217219
public function testQuitTwiceWillRejectSecondCall($flag)
218220
{
219-
$loop = React\EventLoop\Factory::create();
221+
$loop = \React\EventLoop\Factory::create();
220222
$factory = new Factory($loop);
221223

222-
$ref = new ReflectionProperty($factory, 'useSocket');
224+
$ref = new \ReflectionProperty($factory, 'useSocket');
223225
$ref->setAccessible(true);
224226
$ref->setValue($factory, $flag);
225227

@@ -240,10 +242,10 @@ public function testQuitTwiceWillRejectSecondCall($flag)
240242
*/
241243
public function testQueryIntegerResolvesWithResultWithTypeIntegerAndRunsUntilQuit($flag)
242244
{
243-
$loop = React\EventLoop\Factory::create();
245+
$loop = \React\EventLoop\Factory::create();
244246
$factory = new Factory($loop);
245247

246-
$ref = new ReflectionProperty($factory, 'useSocket');
248+
$ref = new \ReflectionProperty($factory, 'useSocket');
247249
$ref->setAccessible(true);
248250
$ref->setValue($factory, $flag);
249251

@@ -269,10 +271,10 @@ public function testQueryIntegerResolvesWithResultWithTypeIntegerAndRunsUntilQui
269271
*/
270272
public function testQueryStringResolvesWithResultWithTypeStringAndRunsUntilQuit($flag)
271273
{
272-
$loop = React\EventLoop\Factory::create();
274+
$loop = \React\EventLoop\Factory::create();
273275
$factory = new Factory($loop);
274276

275-
$ref = new ReflectionProperty($factory, 'useSocket');
277+
$ref = new \ReflectionProperty($factory, 'useSocket');
276278
$ref->setAccessible(true);
277279
$ref->setValue($factory, $flag);
278280

@@ -298,18 +300,18 @@ public function testQueryStringResolvesWithResultWithTypeStringAndRunsUntilQuit(
298300
*/
299301
public function testQueryInvalidTableRejectsWithExceptionAndRunsUntilQuit($flag)
300302
{
301-
$loop = React\EventLoop\Factory::create();
303+
$loop = \React\EventLoop\Factory::create();
302304
$factory = new Factory($loop);
303305

304-
$ref = new ReflectionProperty($factory, 'useSocket');
306+
$ref = new \ReflectionProperty($factory, 'useSocket');
305307
$ref->setAccessible(true);
306308
$ref->setValue($factory, $flag);
307309

308310
$promise = $factory->open(':memory:');
309311

310312
$data = null;
311313
$promise->then(function (DatabaseInterface $db) use (&$data){
312-
$db->query('SELECT 1 FROM foo')->then('var_dump', function (Exception $e) use (&$data) {
314+
$db->query('SELECT 1 FROM foo')->then('var_dump', function (\Exception $e) use (&$data) {
313315
$data = $e->getMessage();
314316
});
315317

@@ -327,18 +329,18 @@ public function testQueryInvalidTableRejectsWithExceptionAndRunsUntilQuit($flag)
327329
*/
328330
public function testQueryInvalidTableWithPlaceholderRejectsWithExceptionAndRunsUntilQuit($flag)
329331
{
330-
$loop = React\EventLoop\Factory::create();
332+
$loop = \React\EventLoop\Factory::create();
331333
$factory = new Factory($loop);
332334

333-
$ref = new ReflectionProperty($factory, 'useSocket');
335+
$ref = new \ReflectionProperty($factory, 'useSocket');
334336
$ref->setAccessible(true);
335337
$ref->setValue($factory, $flag);
336338

337339
$promise = $factory->open(':memory:');
338340

339341
$data = null;
340342
$promise->then(function (DatabaseInterface $db) use (&$data){
341-
$db->query('SELECT ? FROM foo', [1])->then('var_dump', function (Exception $e) use (&$data) {
343+
$db->query('SELECT ? FROM foo', [1])->then('var_dump', function (\Exception $e) use (&$data) {
342344
$data = $e->getMessage();
343345
});
344346

@@ -363,7 +365,7 @@ public function provideSqlDataWillBeReturnedWithType()
363365
['X\'01020300\'', "\x01\x02\x03\x00"],
364366
['X\'3FF3\'', "\x3f\xf3"]
365367
],
366-
(SQLite3::version()['versionNumber'] < 3023000) ? [] : [
368+
(\SQLite3::version()['versionNumber'] < 3023000) ? [] : [
367369
// boolean identifiers exist only as of SQLite 3.23.0 (2018-04-02)
368370
// @link https://www.sqlite.org/lang_expr.html#booleanexpr
369371
['true', 1],
@@ -379,7 +381,7 @@ public function provideSqlDataWillBeReturnedWithType()
379381
*/
380382
public function testQueryValueInStatementResolvesWithResultWithTypeAndRunsUntilQuit($value, $expected)
381383
{
382-
$loop = React\EventLoop\Factory::create();
384+
$loop = \React\EventLoop\Factory::create();
383385
$factory = new Factory($loop);
384386

385387
$promise = $factory->open(':memory:');
@@ -422,7 +424,7 @@ public function provideDataWillBeReturnedWithType()
422424
*/
423425
public function testQueryValuePlaceholderPositionalResolvesWithResultWithExactTypeAndRunsUntilQuit($value, $type)
424426
{
425-
$loop = React\EventLoop\Factory::create();
427+
$loop = \React\EventLoop\Factory::create();
426428
$factory = new Factory($loop);
427429

428430
$promise = $factory->open(':memory:');
@@ -447,7 +449,7 @@ public function testQueryValuePlaceholderPositionalResolvesWithResultWithExactTy
447449
*/
448450
public function testQueryValuePlaceholderNamedResolvesWithResultWithExactTypeAndRunsUntilQuit($value, $type)
449451
{
450-
$loop = React\EventLoop\Factory::create();
452+
$loop = \React\EventLoop\Factory::create();
451453
$factory = new Factory($loop);
452454

453455
$promise = $factory->open(':memory:');
@@ -481,7 +483,7 @@ public function provideDataWillBeReturnedWithOtherType()
481483
*/
482484
public function testQueryValuePlaceholderPositionalResolvesWithResultWithOtherTypeAndRunsUntilQuit($value, $expected)
483485
{
484-
$loop = React\EventLoop\Factory::create();
486+
$loop = \React\EventLoop\Factory::create();
485487
$factory = new Factory($loop);
486488

487489
$promise = $factory->open(':memory:');
@@ -507,7 +509,7 @@ public function testQueryValuePlaceholderPositionalResolvesWithResultWithOtherTy
507509
*/
508510
public function testQueryValuePlaceholderNamedResolvesWithResultWithOtherTypeAndRunsUntilQuit($value, $expected)
509511
{
510-
$loop = React\EventLoop\Factory::create();
512+
$loop = \React\EventLoop\Factory::create();
511513
$factory = new Factory($loop);
512514

513515
$promise = $factory->open(':memory:');
@@ -532,10 +534,10 @@ public function testQueryValuePlaceholderNamedResolvesWithResultWithOtherTypeAnd
532534
*/
533535
public function testQueryRejectsWhenQueryIsInvalid($flag)
534536
{
535-
$loop = React\EventLoop\Factory::create();
537+
$loop = \React\EventLoop\Factory::create();
536538
$factory = new Factory($loop);
537539

538-
$ref = new ReflectionProperty($factory, 'useSocket');
540+
$ref = new \ReflectionProperty($factory, 'useSocket');
539541
$ref->setAccessible(true);
540542
$ref->setValue($factory, $flag);
541543

@@ -557,10 +559,10 @@ public function testQueryRejectsWhenQueryIsInvalid($flag)
557559
*/
558560
public function testQueryRejectsWhenClosedImmediately($flag)
559561
{
560-
$loop = React\EventLoop\Factory::create();
562+
$loop = \React\EventLoop\Factory::create();
561563
$factory = new Factory($loop);
562564

563-
$ref = new ReflectionProperty($factory, 'useSocket');
565+
$ref = new \ReflectionProperty($factory, 'useSocket');
564566
$ref->setAccessible(true);
565567
$ref->setValue($factory, $flag);
566568

@@ -582,10 +584,10 @@ public function testQueryRejectsWhenClosedImmediately($flag)
582584
*/
583585
public function testExecCreateTableResolvesWithResultWithoutRows($flag)
584586
{
585-
$loop = React\EventLoop\Factory::create();
587+
$loop = \React\EventLoop\Factory::create();
586588
$factory = new Factory($loop);
587589

588-
$ref = new ReflectionProperty($factory, 'useSocket');
590+
$ref = new \ReflectionProperty($factory, 'useSocket');
589591
$ref->setAccessible(true);
590592
$ref->setValue($factory, $flag);
591593

@@ -611,10 +613,10 @@ public function testExecCreateTableResolvesWithResultWithoutRows($flag)
611613
*/
612614
public function testExecRejectsWhenClosedImmediately($flag)
613615
{
614-
$loop = React\EventLoop\Factory::create();
616+
$loop = \React\EventLoop\Factory::create();
615617
$factory = new Factory($loop);
616618

617-
$ref = new ReflectionProperty($factory, 'useSocket');
619+
$ref = new \ReflectionProperty($factory, 'useSocket');
618620
$ref->setAccessible(true);
619621
$ref->setValue($factory, $flag);
620622

@@ -636,10 +638,10 @@ public function testExecRejectsWhenClosedImmediately($flag)
636638
*/
637639
public function testExecRejectsWhenAlreadyClosed($flag)
638640
{
639-
$loop = React\EventLoop\Factory::create();
641+
$loop = \React\EventLoop\Factory::create();
640642
$factory = new Factory($loop);
641643

642-
$ref = new ReflectionProperty($factory, 'useSocket');
644+
$ref = new \ReflectionProperty($factory, 'useSocket');
643645
$ref->setAccessible(true);
644646
$ref->setValue($factory, $flag);
645647

@@ -660,10 +662,10 @@ public function testExecRejectsWhenAlreadyClosed($flag)
660662
*/
661663
public function testQueryInsertResolvesWithEmptyResultSetWithLastInsertIdAndRunsUntilQuit($flag)
662664
{
663-
$loop = React\EventLoop\Factory::create();
665+
$loop = \React\EventLoop\Factory::create();
664666
$factory = new Factory($loop);
665667

666-
$ref = new ReflectionProperty($factory, 'useSocket');
668+
$ref = new \ReflectionProperty($factory, 'useSocket');
667669
$ref->setAccessible(true);
668670
$ref->setValue($factory, $flag);
669671

@@ -693,10 +695,10 @@ public function testQueryInsertResolvesWithEmptyResultSetWithLastInsertIdAndRuns
693695
*/
694696
public function testQuerySelectEmptyResolvesWithEmptyResultSetWithColumnsAndNoRowsAndRunsUntilQuit($flag)
695697
{
696-
$loop = React\EventLoop\Factory::create();
698+
$loop = \React\EventLoop\Factory::create();
697699
$factory = new Factory($loop);
698700

699-
$ref = new ReflectionProperty($factory, 'useSocket');
701+
$ref = new \ReflectionProperty($factory, 'useSocket');
700702
$ref->setAccessible(true);
701703
$ref->setValue($factory, $flag);
702704

0 commit comments

Comments
 (0)