function copyMods()
{
    Vertx::fileSystem()->copyRecursive("src/test/resources/includemod/mods", "target/mods", function ($error) {
        if ($error) {
            Vertx::logger()->error($error);
            return;
        } else {
            Vertx::deployModule('io.vertx~php-includetest-mod~v1.0', NULL, 1, function ($id, $error) {
                if ($error) {
                    Vertx::logger()->error($error);
                    return;
                } else {
                    TestRunner::run(new IncludeTestCase());
                    Vertx::undeployModule($id);
                }
            });
        }
    });
}
                        $this->assertNull($error);
                        $this->complete();
                    });
                });
            });
        });
    }
    /**
     * Tests writing to and reading from a file synchronously.
     */
    public function testWriteReadFileSync()
    {
        $filename = TEST_OUTPUT_DIRECTORY . '/test-file.txt';
        $alphabet = 'abcdefghijklmnopqrstuvwxyz';
        $this->fileSystem->createFileSync($filename, 'rwxr-xr-x');
        $this->assertTrue($this->fileSystem->existsSync($filename));
        $buffer = new Buffer();
        $buffer->appendString($alphabet);
        $this->fileSystem->writeFileSync($filename, $buffer);
        $contents = $this->fileSystem->readFileSync($filename);
        $this->assertEquals($alphabet, (string) $contents);
        $this->fileSystem->deleteSync($filename);
        $this->complete();
    }
    public function tearDown()
    {
        $this->fileSystem->deleteRecursiveSync(TEST_OUTPUT_DIRECTORY);
    }
}
TestRunner::run(new FileSystemTestCase());
    public function testPrintInHandlerCallbackClosure()
    {
        $this->currentHandlerId = $this->eventBus->registerHandler(self::TEST_ADDRESS, function ($echo) use($complete) {
            try {
                print "message:" . $echo;
            } catch (Exception $e) {
                $this->assertNull($e);
            }
            $this->complete();
        });
        $this->assertNotNull($this->currentHandlerId);
        $this->eventBus->send(self::TEST_ADDRESS, array());
    }
    public function callCallback($callback)
    {
        $callback();
    }
    public function testPrintInSimpleCallbackClosure()
    {
        $this->callCallback(function () {
            try {
                print "print sth.";
            } catch (Exception $e) {
                $this->assertNull($e);
            }
            $this->complete();
        });
    }
}
TestRunner::run(new EventBusTestCase());
            $this->assertNotNull($id);
            Vertx::undeployVerticle($id, function ($error) {
                $this->assertNull($error);
                $this->complete();
            });
        });
    }
    /**
     * Tests failing a verticle deploy.
     */
    public function testDeployFail()
    {
        Vertx::deployVerticle('asdlkjsdalf', NULL, 1, function ($id, $error) {
            $this->assertNull($id);
            $this->assertNotNull($error);
            $this->complete();
        });
    }
    /**
     * Tests failing a verticle undeploy.
     */
    public function testUndeployFail()
    {
        Vertx::undeployVerticle('asdlkjsdalf', function ($error) {
            $this->assertNotNull($error);
            $this->complete();
        });
    }
}
TestRunner::run(new DeployTestCase());
 * A Vert.x RecordParser test case.
 */
class RecordParserTestCase extends PhpTestCase
{
    /**
     * Tests delimited record parsing.
     */
    public function testDelimited()
    {
        $input = '';
        for ($i = 0; $i < 100; $i++) {
            $input .= "line {$i}";
            if ($i < 99) {
                $input .= "\n";
            }
        }
        $lines = array();
        $parser = RecordParser::newDelimited("\n", function ($buffer) use(&$lines) {
            $lines[] = trim((string) $buffer);
        });
        $parser->handle(new Vertx\Buffer($input));
        $count = 0;
        foreach ($lines as $line) {
            $this->assertEquals($line, "line {$count}");
            $count++;
        }
        $this->complete();
    }
}
TestRunner::run(new RecordParserTestCase());
            });
            $this->client->get(self::URI, function ($response) {
                $this->assertEquals($response->statusCode, 200);
                $this->complete();
            })->end();
        });
    }
    /**
     * Tests the ALL method with a regular expression.
     */
    public function testAllWithRegex()
    {
        $this->server->listen(8080, '0.0.0.0', function ($server, $error) {
            $this->assertNotNull($server);
            $this->assertNull($error);
            $this->routeMatcher->allWithRegex(self::$regex, function ($request) {
                $this->assertEquals(count($request->params), count(self::$regexParams));
                foreach (self::$regexParams as $key => $value) {
                    $this->assertEquals($value, $request->params[$key]);
                }
                $request->response->end();
            });
            $this->client->get(self::URI, function ($response) {
                $this->assertEquals($response->statusCode, 200);
                $this->complete();
            })->end();
        });
    }
}
TestRunner::run(new RouteMatcherTestCase());
        $float = $buffer->getFloat(26);
        $this->assertEquals(round($float, 3), 1.123);
        $this->complete();
    }
    /**
     * Tests appending a buffer to another buffer.
     */
    public function testAppendBuffer()
    {
        $buffer1 = new Buffer(substr(self::ALPHABET, 0, 10));
        $buffer2 = new Buffer(substr(self::ALPHABET, 10));
        $buffer1->appendBuffer($buffer2);
        $this->assertEquals($buffer1->length(), strlen(self::ALPHABET));
        $this->assertEquals($buffer1->toString(), self::ALPHABET);
        $this->complete();
    }
    /**
     * Tests the basic buffer append method.
     */
    public function testAppendAny()
    {
        $buffer = new Buffer(substr(self::ALPHABET, 0, 10));
        $buffer->append(substr(self::ALPHABET, 10));
        $this->assertEquals(count($buffer), strlen(self::ALPHABET));
        $this->assertEquals($buffer->toString(), self::ALPHABET);
        $this->assertEquals((string) $buffer, self::ALPHABET);
        $this->complete();
    }
}
TestRunner::run(new BufferTestCase());
Exemple #8
0
        $this->assertFalse($client->keepAlive);
        $client->keepAlive(TRUE);
        $this->assertTrue($client->keepAlive());
        $client->reuseAddress = TRUE;
        $this->assertTrue($client->reuseAddress);
        $client->reuseAddress = FALSE;
        $this->assertFalse($client->reuseAddress);
        $client->reuseAddress(TRUE);
        $this->assertTrue($client->reuseAddress());
        $client->trafficClass(12345);
        $this->assertEquals($client->trafficClass(), 12345);
        $client->trafficClass = 12345;
        $this->assertEquals($client->trafficClass, 12345);
        $this->complete();
    }
    private function createBuffer($size)
    {
        $str = '';
        while (strlen($str) < $size) {
            $str .= 'abcdefghijklmnopqrstuvwxyz';
        }
        return new Buffer(substr($str, 0, $size));
    }
    public function tearDown()
    {
        $this->client->close();
        $this->server->close();
    }
}
TestRunner::run(new NetTestCase());
Exemple #9
0
        $this->assertTrue($client->verifyHost());
        $client->trafficClass(12345);
        $this->assertEquals($client->trafficClass(), 12345);
        $client->trafficClass = 12345;
        $this->assertEquals($client->trafficClass, 12345);
        $client->connectTimeout(12345);
        $this->assertEquals($client->connectTimeout(), 12345);
        $client->connectTimeout = 12345;
        $this->assertEquals($client->connectTimeout, 12345);
        $client->maxPoolSize(12345);
        $this->assertEquals($client->maxPoolSize(), 12345);
        $client->maxPoolSize = 12345;
        $this->assertEquals($client->maxPoolSize, 12345);
        $this->complete();
    }
    private function createBuffer($size)
    {
        $str = '';
        while (strlen($str) < $size) {
            $str .= 'abcdefghijklmnopqrstuvwxyz';
        }
        return new Buffer(substr($str, 0, $size));
    }
    public function tearDown()
    {
        $this->client->close();
        $this->server->close();
    }
}
TestRunner::run(new HttpTestCase());
 * limitations under the License.
 */
use Vertx\Test\TestRunner;
use Vertx\Test\PhpTestCase;
/**
 * A Vert.x context test case.
 */
class ContextTestCase extends PhpTestCase
{
    /**
     * Tests the Vertx runOnContext() method.
     */
    public function testRunOnContext()
    {
        Vertx::runOnContext(function () {
            $this->complete();
        });
    }
    /**
     * Tests the Context runOnContext method directly.
     */
    public function testGetContext()
    {
        $context = Vertx::currentContext();
        $context->runOnContext(function () {
            $this->complete();
        });
    }
}
TestRunner::run(new ContextTestCase());
Exemple #11
0
    public function testOneOff()
    {
        Vertx::setTimer(10, function () {
            $this->complete();
        });
    }
    /**
     * Tests a periodic timer.
     */
    public function testPeriodic()
    {
        $total = 10;
        $count = 0;
        Vertx::setPeriodic(10, function ($timer_id) use(&$count, $total) {
            $this->assertNotNull($timer_id);
            $count += 1;
            if ($count == $total) {
                Vertx::cancelTimer($timer_id);
                Vertx::setTimer(10, function () {
                    $this->complete();
                });
            } else {
                if ($count > $total) {
                    $this->assertTrue(FALSE, 'Counter went off too many times!');
                }
            }
        });
    }
}
TestRunner::run(new TimerTestCase());
     * Tests setting and getting integers in a shared map.
     */
    public function testMapInteger()
    {
        $this->doTestValue(12345);
    }
    /**
     * Tests setting and getting floats in a shared map.
     */
    public function testMapFloat()
    {
        $this->doTestValue(1.2345);
    }
    private function doTestValue($value)
    {
        $map1 = $this->sharedData->getMap('map1');
        $this->assertNotNull($map1);
        $map2 = $this->sharedData->getMap('map1');
        $this->assertNotNull($map2);
        $key = 'foo';
        $map1[$key] = $value;
        $this->assertEquals($map1[$key], $value);
        $this->assertEquals($map2[$key], $value);
        $this->assertEquals($map1[$key], $map2[$key]);
        $map3 = $this->sharedData->getMap('map1');
        $this->assertEquals($map3[$key], $value);
        $this->complete();
    }
}
TestRunner::run(new SharedDataTestCase());