From da1c48bc0729baaa93f8d6620905dbe05e521d3b Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Mon, 4 Oct 2021 10:55:53 +0200 Subject: [PATCH] Use new Eventloop in tests --- tests/FunctionalDatabaseTest.php | 126 +++++++++++++------------------ 1 file changed, 51 insertions(+), 75 deletions(-) diff --git a/tests/FunctionalDatabaseTest.php b/tests/FunctionalDatabaseTest.php index adb1e66..f40f4a3 100644 --- a/tests/FunctionalDatabaseTest.php +++ b/tests/FunctionalDatabaseTest.php @@ -6,6 +6,7 @@ use Clue\React\SQLite\Factory; use Clue\React\SQLite\Result; use PHPUnit\Framework\TestCase; +use React\EventLoop\Loop; class FunctionalDatabaseTest extends TestCase { @@ -24,8 +25,7 @@ public function provideSocketFlags() */ public function testOpenMemoryDatabaseResolvesWithDatabaseAndRunsUntilClose($flag) { - $loop = \React\EventLoop\Factory::create(); - $factory = new Factory($loop); + $factory = new Factory(); $ref = new \ReflectionProperty($factory, 'useSocket'); $ref->setAccessible(true); @@ -41,7 +41,7 @@ public function testOpenMemoryDatabaseResolvesWithDatabaseAndRunsUntilClose($fla $db->close(); }); - $loop->run(); + Loop::run(); } /** @@ -50,8 +50,7 @@ public function testOpenMemoryDatabaseResolvesWithDatabaseAndRunsUntilClose($fla */ public function testOpenMemoryDatabaseResolvesWithDatabaseAndRunsUntilQuit($flag) { - $loop = \React\EventLoop\Factory::create(); - $factory = new Factory($loop); + $factory = new Factory(); $ref = new \ReflectionProperty($factory, 'useSocket'); $ref->setAccessible(true); @@ -67,7 +66,7 @@ public function testOpenMemoryDatabaseResolvesWithDatabaseAndRunsUntilQuit($flag $db->quit(); }); - $loop->run(); + Loop::run(); } public function testOpenMemoryDatabaseShouldNotInheritActiveFileDescriptors() @@ -79,8 +78,7 @@ public function testOpenMemoryDatabaseShouldNotInheritActiveFileDescriptors() $this->markTestSkipped('Platform does not prevent binding to same address (Windows?)'); } - $loop = \React\EventLoop\Factory::create(); - $factory = new Factory($loop); + $factory = new Factory(); $promise = $factory->open(':memory:'); @@ -108,7 +106,7 @@ public function testOpenMemoryDatabaseShouldNotInheritActiveFileDescriptors() $db->close(); }); - $loop->run(); + Loop::run(); } /** @@ -117,8 +115,7 @@ public function testOpenMemoryDatabaseShouldNotInheritActiveFileDescriptors() */ public function testOpenInvalidPathRejects($flag) { - $loop = \React\EventLoop\Factory::create(); - $factory = new Factory($loop); + $factory = new Factory(); $ref = new \ReflectionProperty($factory, 'useSocket'); $ref->setAccessible(true); @@ -131,7 +128,7 @@ public function testOpenInvalidPathRejects($flag) $this->expectCallableOnceWith($this->isInstanceOf('RuntimeException')) ); - $loop->run(); + Loop::run(); } /** @@ -140,8 +137,7 @@ public function testOpenInvalidPathRejects($flag) */ public function testOpenInvalidPathWithNullByteRejects($flag) { - $loop = \React\EventLoop\Factory::create(); - $factory = new Factory($loop); + $factory = new Factory(); $ref = new \ReflectionProperty($factory, 'useSocket'); $ref->setAccessible(true); @@ -154,7 +150,7 @@ public function testOpenInvalidPathWithNullByteRejects($flag) $this->expectCallableOnceWith($this->isInstanceOf('RuntimeException')) ); - $loop->run(); + Loop::run(); } /** @@ -163,8 +159,7 @@ public function testOpenInvalidPathWithNullByteRejects($flag) */ public function testOpenInvalidFlagsRejects($flag) { - $loop = \React\EventLoop\Factory::create(); - $factory = new Factory($loop); + $factory = new Factory(); $ref = new \ReflectionProperty($factory, 'useSocket'); $ref->setAccessible(true); @@ -177,7 +172,7 @@ public function testOpenInvalidFlagsRejects($flag) $this->expectCallableOnceWith($this->isInstanceOf('RuntimeException')) ); - $loop->run(); + Loop::run(); } /** @@ -186,8 +181,7 @@ public function testOpenInvalidFlagsRejects($flag) */ public function testQuitResolvesAndRunsUntilQuit($flag) { - $loop = \React\EventLoop\Factory::create(); - $factory = new Factory($loop); + $factory = new Factory(); $ref = new \ReflectionProperty($factory, 'useSocket'); $ref->setAccessible(true); @@ -200,7 +194,7 @@ public function testQuitResolvesAndRunsUntilQuit($flag) $db->quit()->then($once); }); - $loop->run(); + Loop::run(); } /** @@ -214,8 +208,7 @@ public function testQuitResolvesAndRunsUntilQuitWhenParentHasManyFileDescriptors $servers[] = stream_socket_server('tcp://127.0.0.1:0'); } - $loop = \React\EventLoop\Factory::create(); - $factory = new Factory($loop); + $factory = new Factory(); $ref = new \ReflectionProperty($factory, 'useSocket'); $ref->setAccessible(true); @@ -228,7 +221,7 @@ public function testQuitResolvesAndRunsUntilQuitWhenParentHasManyFileDescriptors $db->quit()->then($once); }); - $loop->run(); + Loop::run(); foreach ($servers as $server) { fclose($server); @@ -241,8 +234,7 @@ public function testQuitResolvesAndRunsUntilQuitWhenParentHasManyFileDescriptors */ public function testQuitTwiceWillRejectSecondCall($flag) { - $loop = \React\EventLoop\Factory::create(); - $factory = new Factory($loop); + $factory = new Factory(); $ref = new \ReflectionProperty($factory, 'useSocket'); $ref->setAccessible(true); @@ -256,7 +248,7 @@ public function testQuitTwiceWillRejectSecondCall($flag) $db->quit()->then(null, $once); }); - $loop->run(); + Loop::run(); } /** @@ -265,8 +257,7 @@ public function testQuitTwiceWillRejectSecondCall($flag) */ public function testQueryIntegerResolvesWithResultWithTypeIntegerAndRunsUntilQuit($flag) { - $loop = \React\EventLoop\Factory::create(); - $factory = new Factory($loop); + $factory = new Factory(); $ref = new \ReflectionProperty($factory, 'useSocket'); $ref->setAccessible(true); @@ -283,7 +274,7 @@ public function testQueryIntegerResolvesWithResultWithTypeIntegerAndRunsUntilQui $db->quit(); }); - $loop->run(); + Loop::run(); $this->assertSame(array(array('value' => 1)), $data); } @@ -294,8 +285,7 @@ public function testQueryIntegerResolvesWithResultWithTypeIntegerAndRunsUntilQui */ public function testQueryStringResolvesWithResultWithTypeStringAndRunsUntilQuit($flag) { - $loop = \React\EventLoop\Factory::create(); - $factory = new Factory($loop); + $factory = new Factory(); $ref = new \ReflectionProperty($factory, 'useSocket'); $ref->setAccessible(true); @@ -312,7 +302,7 @@ public function testQueryStringResolvesWithResultWithTypeStringAndRunsUntilQuit( $db->quit(); }); - $loop->run(); + Loop::run(); $this->assertSame(array(array('value' => 'hellö')), $data); } @@ -323,8 +313,7 @@ public function testQueryStringResolvesWithResultWithTypeStringAndRunsUntilQuit( */ public function testQueryInvalidTableRejectsWithExceptionAndRunsUntilQuit($flag) { - $loop = \React\EventLoop\Factory::create(); - $factory = new Factory($loop); + $factory = new Factory(); $ref = new \ReflectionProperty($factory, 'useSocket'); $ref->setAccessible(true); @@ -341,7 +330,7 @@ public function testQueryInvalidTableRejectsWithExceptionAndRunsUntilQuit($flag) $db->quit(); }); - $loop->run(); + Loop::run(); $this->assertSame('no such table: foo', $data); } @@ -352,8 +341,7 @@ public function testQueryInvalidTableRejectsWithExceptionAndRunsUntilQuit($flag) */ public function testQueryInvalidTableWithPlaceholderRejectsWithExceptionAndRunsUntilQuit($flag) { - $loop = \React\EventLoop\Factory::create(); - $factory = new Factory($loop); + $factory = new Factory(); $ref = new \ReflectionProperty($factory, 'useSocket'); $ref->setAccessible(true); @@ -370,7 +358,7 @@ public function testQueryInvalidTableWithPlaceholderRejectsWithExceptionAndRunsU $db->quit(); }); - $loop->run(); + Loop::run(); $this->assertSame('no such table: foo', $data); } @@ -404,8 +392,7 @@ public function provideSqlDataWillBeReturnedWithType() */ public function testQueryValueInStatementResolvesWithResultWithTypeAndRunsUntilQuit($value, $expected) { - $loop = \React\EventLoop\Factory::create(); - $factory = new Factory($loop); + $factory = new Factory(); $promise = $factory->open(':memory:'); @@ -418,7 +405,7 @@ public function testQueryValueInStatementResolvesWithResultWithTypeAndRunsUntilQ $db->quit(); }); - $loop->run(); + Loop::run(); $this->assertSame(array(array('value' => $expected)), $data); } @@ -447,8 +434,7 @@ public function provideDataWillBeReturnedWithType() */ public function testQueryValuePlaceholderPositionalResolvesWithResultWithExactTypeAndRunsUntilQuit($value, $type) { - $loop = \React\EventLoop\Factory::create(); - $factory = new Factory($loop); + $factory = new Factory(); $promise = $factory->open(':memory:'); @@ -461,7 +447,7 @@ public function testQueryValuePlaceholderPositionalResolvesWithResultWithExactTy $db->quit(); }); - $loop->run(); + Loop::run(); $this->assertSame(array(array('value' => $value, 'type' => $type)), $data); } @@ -472,8 +458,7 @@ public function testQueryValuePlaceholderPositionalResolvesWithResultWithExactTy */ public function testQueryValuePlaceholderNamedResolvesWithResultWithExactTypeAndRunsUntilQuit($value, $type) { - $loop = \React\EventLoop\Factory::create(); - $factory = new Factory($loop); + $factory = new Factory(); $promise = $factory->open(':memory:'); @@ -486,7 +471,7 @@ public function testQueryValuePlaceholderNamedResolvesWithResultWithExactTypeAnd $db->quit(); }); - $loop->run(); + Loop::run(); $this->assertSame(array(array('value' => $value, 'type' => $type)), $data); } @@ -506,8 +491,7 @@ public function provideDataWillBeReturnedWithOtherType() */ public function testQueryValuePlaceholderPositionalResolvesWithResultWithOtherTypeAndRunsUntilQuit($value, $expected) { - $loop = \React\EventLoop\Factory::create(); - $factory = new Factory($loop); + $factory = new Factory(); $promise = $factory->open(':memory:'); @@ -520,7 +504,7 @@ public function testQueryValuePlaceholderPositionalResolvesWithResultWithOtherTy $db->quit(); }); - $loop->run(); + Loop::run(); $this->assertSame(array(array('value' => $expected)), $data); } @@ -532,8 +516,7 @@ public function testQueryValuePlaceholderPositionalResolvesWithResultWithOtherTy */ public function testQueryValuePlaceholderNamedResolvesWithResultWithOtherTypeAndRunsUntilQuit($value, $expected) { - $loop = \React\EventLoop\Factory::create(); - $factory = new Factory($loop); + $factory = new Factory(); $promise = $factory->open(':memory:'); @@ -546,7 +529,7 @@ public function testQueryValuePlaceholderNamedResolvesWithResultWithOtherTypeAnd $db->quit(); }); - $loop->run(); + Loop::run(); $this->assertSame(array(array('value' => $expected)), $data); } @@ -557,8 +540,7 @@ public function testQueryValuePlaceholderNamedResolvesWithResultWithOtherTypeAnd */ public function testQueryRejectsWhenQueryIsInvalid($flag) { - $loop = \React\EventLoop\Factory::create(); - $factory = new Factory($loop); + $factory = new Factory(); $ref = new \ReflectionProperty($factory, 'useSocket'); $ref->setAccessible(true); @@ -573,7 +555,7 @@ public function testQueryRejectsWhenQueryIsInvalid($flag) $db->quit(); }); - $loop->run(); + Loop::run(); } /** @@ -582,8 +564,7 @@ public function testQueryRejectsWhenQueryIsInvalid($flag) */ public function testQueryRejectsWhenClosedImmediately($flag) { - $loop = \React\EventLoop\Factory::create(); - $factory = new Factory($loop); + $factory = new Factory(); $ref = new \ReflectionProperty($factory, 'useSocket'); $ref->setAccessible(true); @@ -598,7 +579,7 @@ public function testQueryRejectsWhenClosedImmediately($flag) $db->close(); }); - $loop->run(); + Loop::run(); } /** @@ -607,8 +588,7 @@ public function testQueryRejectsWhenClosedImmediately($flag) */ public function testExecCreateTableResolvesWithResultWithoutRows($flag) { - $loop = \React\EventLoop\Factory::create(); - $factory = new Factory($loop); + $factory = new Factory(); $ref = new \ReflectionProperty($factory, 'useSocket'); $ref->setAccessible(true); @@ -625,7 +605,7 @@ public function testExecCreateTableResolvesWithResultWithoutRows($flag) $db->quit(); }); - $loop->run(); + Loop::run(); $this->assertNull($data); } @@ -636,8 +616,7 @@ public function testExecCreateTableResolvesWithResultWithoutRows($flag) */ public function testExecRejectsWhenClosedImmediately($flag) { - $loop = \React\EventLoop\Factory::create(); - $factory = new Factory($loop); + $factory = new Factory(); $ref = new \ReflectionProperty($factory, 'useSocket'); $ref->setAccessible(true); @@ -652,7 +631,7 @@ public function testExecRejectsWhenClosedImmediately($flag) $db->close(); }); - $loop->run(); + Loop::run(); } /** @@ -661,8 +640,7 @@ public function testExecRejectsWhenClosedImmediately($flag) */ public function testExecRejectsWhenAlreadyClosed($flag) { - $loop = \React\EventLoop\Factory::create(); - $factory = new Factory($loop); + $factory = new Factory(); $ref = new \ReflectionProperty($factory, 'useSocket'); $ref->setAccessible(true); @@ -676,7 +654,7 @@ public function testExecRejectsWhenAlreadyClosed($flag) $db->exec('USE a')->then('var_dump', $once); }); - $loop->run(); + Loop::run(); } /** @@ -685,8 +663,7 @@ public function testExecRejectsWhenAlreadyClosed($flag) */ public function testQueryInsertResolvesWithEmptyResultSetWithLastInsertIdAndRunsUntilQuit($flag) { - $loop = \React\EventLoop\Factory::create(); - $factory = new Factory($loop); + $factory = new Factory(); $ref = new \ReflectionProperty($factory, 'useSocket'); $ref->setAccessible(true); @@ -704,7 +681,7 @@ public function testQueryInsertResolvesWithEmptyResultSetWithLastInsertIdAndRuns $db->quit(); }); - $loop->run(); + Loop::run(); $this->assertInstanceOf('Clue\React\SQLite\Result', $data); $this->assertSame(1, $data->insertId); @@ -718,8 +695,7 @@ public function testQueryInsertResolvesWithEmptyResultSetWithLastInsertIdAndRuns */ public function testQuerySelectEmptyResolvesWithEmptyResultSetWithColumnsAndNoRowsAndRunsUntilQuit($flag) { - $loop = \React\EventLoop\Factory::create(); - $factory = new Factory($loop); + $factory = new Factory(); $ref = new \ReflectionProperty($factory, 'useSocket'); $ref->setAccessible(true); @@ -737,7 +713,7 @@ public function testQuerySelectEmptyResolvesWithEmptyResultSetWithColumnsAndNoRo $db->quit(); }); - $loop->run(); + Loop::run(); $this->assertInstanceOf('Clue\React\SQLite\Result', $data); $this->assertSame(['id', 'bar'], $data->columns);