|
|
|
@ -41,7 +41,7 @@ class EngineTest extends TestCase
|
|
|
|
$this->assertTrue($engine->getInitializedVar());
|
|
|
|
$this->assertTrue($engine->getInitializedVar());
|
|
|
|
|
|
|
|
|
|
|
|
// we need to setup a dummy route
|
|
|
|
// we need to setup a dummy route
|
|
|
|
$engine->route('/someRoute', function () { });
|
|
|
|
$engine->route('/someRoute', function () {});
|
|
|
|
$engine->request()->url = '/someRoute';
|
|
|
|
$engine->request()->url = '/someRoute';
|
|
|
|
$engine->start();
|
|
|
|
$engine->start();
|
|
|
|
|
|
|
|
|
|
|
|
@ -96,8 +96,7 @@ class EngineTest extends TestCase
|
|
|
|
$engine = new Engine();
|
|
|
|
$engine = new Engine();
|
|
|
|
$this->expectException(Exception::class);
|
|
|
|
$this->expectException(Exception::class);
|
|
|
|
$this->expectExceptionMessage('Cannot override an existing framework method.');
|
|
|
|
$this->expectExceptionMessage('Cannot override an existing framework method.');
|
|
|
|
$engine->map('_start', function () {
|
|
|
|
$engine->map('_start', function () {});
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testRegisterExistingMethod(): void
|
|
|
|
public function testRegisterExistingMethod(): void
|
|
|
|
@ -111,7 +110,7 @@ class EngineTest extends TestCase
|
|
|
|
public function testSetArrayOfValues(): void
|
|
|
|
public function testSetArrayOfValues(): void
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$engine = new Engine();
|
|
|
|
$engine = new Engine();
|
|
|
|
$engine->set([ 'key1' => 'value1', 'key2' => 'value2']);
|
|
|
|
$engine->set(['key1' => 'value1', 'key2' => 'value2']);
|
|
|
|
$this->assertEquals('value1', $engine->get('key1'));
|
|
|
|
$this->assertEquals('value1', $engine->get('key1'));
|
|
|
|
$this->assertEquals('value2', $engine->get('key2'));
|
|
|
|
$this->assertEquals('value2', $engine->get('key2'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -618,7 +617,7 @@ class EngineTest extends TestCase
|
|
|
|
$engine->route('/path1/@param:[0-9]{3}', function () {
|
|
|
|
$engine->route('/path1/@param:[0-9]{3}', function () {
|
|
|
|
echo 'I win';
|
|
|
|
echo 'I win';
|
|
|
|
}, false, 'path1');
|
|
|
|
}, false, 'path1');
|
|
|
|
$url = $engine->getUrl('path1', [ 'param' => 123 ]);
|
|
|
|
$url = $engine->getUrl('path1', ['param' => 123]);
|
|
|
|
$this->assertEquals('/path1/123', $url);
|
|
|
|
$this->assertEquals('/path1/123', $url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -628,7 +627,7 @@ class EngineTest extends TestCase
|
|
|
|
$engine->route('/item/@item_param:[a-z0-9]{16}/by-status/@token:[a-z0-9]{16}', function () {
|
|
|
|
$engine->route('/item/@item_param:[a-z0-9]{16}/by-status/@token:[a-z0-9]{16}', function () {
|
|
|
|
echo 'I win';
|
|
|
|
echo 'I win';
|
|
|
|
}, false, 'path_item_1');
|
|
|
|
}, false, 'path_item_1');
|
|
|
|
$url = $engine->getUrl('path_item_1', [ 'item_param' => 1234567890123456, 'token' => 6543210987654321 ]);
|
|
|
|
$url = $engine->getUrl('path_item_1', ['item_param' => 1234567890123456, 'token' => 6543210987654321]);
|
|
|
|
$this->assertEquals('/item/1234567890123456/by-status/6543210987654321', $url);
|
|
|
|
$this->assertEquals('/item/1234567890123456/by-status/6543210987654321', $url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -666,8 +665,7 @@ class EngineTest extends TestCase
|
|
|
|
|
|
|
|
|
|
|
|
public function testMiddlewareCallableFunctionReturnFalse(): void
|
|
|
|
public function testMiddlewareCallableFunctionReturnFalse(): void
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$engine = new class extends Engine {
|
|
|
|
$engine = new class extends Engine {};
|
|
|
|
};
|
|
|
|
|
|
|
|
$engine->route('/path1/@id', function ($id) {
|
|
|
|
$engine->route('/path1/@id', function ($id) {
|
|
|
|
echo 'OK' . $id;
|
|
|
|
echo 'OK' . $id;
|
|
|
|
})
|
|
|
|
})
|
|
|
|
@ -794,8 +792,7 @@ class EngineTest extends TestCase
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
$engine = new class extends Engine {
|
|
|
|
$engine = new class extends Engine {};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$engine->route('/path1/@id', function ($id) {
|
|
|
|
$engine->route('/path1/@id', function ($id) {
|
|
|
|
echo 'OK' . $id;
|
|
|
|
echo 'OK' . $id;
|
|
|
|
@ -850,7 +847,7 @@ class EngineTest extends TestCase
|
|
|
|
$engine = new Engine();
|
|
|
|
$engine = new Engine();
|
|
|
|
$engine->route('/path1/@id/subpath1/@another_id', function () {
|
|
|
|
$engine->route('/path1/@id/subpath1/@another_id', function () {
|
|
|
|
echo 'OK';
|
|
|
|
echo 'OK';
|
|
|
|
})->addMiddleware([ $middleware, $middleware2 ]);
|
|
|
|
})->addMiddleware([$middleware, $middleware2]);
|
|
|
|
|
|
|
|
|
|
|
|
$engine->request()->url = '/path1/123/subpath1/456';
|
|
|
|
$engine->request()->url = '/path1/123/subpath1/456';
|
|
|
|
$engine->start();
|
|
|
|
$engine->start();
|
|
|
|
@ -887,14 +884,15 @@ class EngineTest extends TestCase
|
|
|
|
$router->map('/@cool_id', function () {
|
|
|
|
$router->map('/@cool_id', function () {
|
|
|
|
echo 'OK';
|
|
|
|
echo 'OK';
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}, [ $middleware, $middleware2 ]);
|
|
|
|
}, [$middleware, $middleware2]);
|
|
|
|
|
|
|
|
|
|
|
|
$engine->request()->url = '/path1/123/subpath1/456';
|
|
|
|
$engine->request()->url = '/path1/123/subpath1/456';
|
|
|
|
$engine->start();
|
|
|
|
$engine->start();
|
|
|
|
$this->expectOutputString('before456before123OKafter123456after123');
|
|
|
|
$this->expectOutputString('before456before123OKafter123456after123');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testContainerBadClass() {
|
|
|
|
public function testContainerBadClass()
|
|
|
|
|
|
|
|
{
|
|
|
|
$engine = new Engine();
|
|
|
|
$engine = new Engine();
|
|
|
|
|
|
|
|
|
|
|
|
$this->expectException(InvalidArgumentException::class);
|
|
|
|
$this->expectException(InvalidArgumentException::class);
|
|
|
|
@ -902,47 +900,50 @@ class EngineTest extends TestCase
|
|
|
|
$engine->registerContainerHandler('BadClass');
|
|
|
|
$engine->registerContainerHandler('BadClass');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testContainerDice() {
|
|
|
|
public function testContainerDice()
|
|
|
|
|
|
|
|
{
|
|
|
|
$engine = new Engine();
|
|
|
|
$engine = new Engine();
|
|
|
|
$dice = new \Dice\Dice();
|
|
|
|
$dice = new \Dice\Dice();
|
|
|
|
$dice = $dice->addRules([
|
|
|
|
$dice = $dice->addRules([
|
|
|
|
PdoWrapper::class => [
|
|
|
|
PdoWrapper::class => [
|
|
|
|
'shared' => true,
|
|
|
|
'shared' => true,
|
|
|
|
'constructParams' => [ 'sqlite::memory:' ]
|
|
|
|
'constructParams' => ['sqlite::memory:']
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
$engine->registerContainerHandler(function ($class, $params) use ($dice) {
|
|
|
|
$engine->registerContainerHandler(function ($class, $params) use ($dice) {
|
|
|
|
return $dice->create($class, $params);
|
|
|
|
return $dice->create($class, $params);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$engine->route('/container', Container::class.'->testTheContainer');
|
|
|
|
$engine->route('/container', Container::class . '->testTheContainer');
|
|
|
|
$engine->request()->url = '/container';
|
|
|
|
$engine->request()->url = '/container';
|
|
|
|
$engine->start();
|
|
|
|
$engine->start();
|
|
|
|
|
|
|
|
|
|
|
|
$this->expectOutputString('yay! I injected a collection, and it has 1 items');
|
|
|
|
$this->expectOutputString('yay! I injected a collection, and it has 1 items');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testContainerDicePdoWrapperTest() {
|
|
|
|
public function testContainerDicePdoWrapperTest()
|
|
|
|
|
|
|
|
{
|
|
|
|
$engine = new Engine();
|
|
|
|
$engine = new Engine();
|
|
|
|
$dice = new \Dice\Dice();
|
|
|
|
$dice = new \Dice\Dice();
|
|
|
|
$dice = $dice->addRules([
|
|
|
|
$dice = $dice->addRules([
|
|
|
|
PdoWrapper::class => [
|
|
|
|
PdoWrapper::class => [
|
|
|
|
'shared' => true,
|
|
|
|
'shared' => true,
|
|
|
|
'constructParams' => [ 'sqlite::memory:' ]
|
|
|
|
'constructParams' => ['sqlite::memory:']
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
$engine->registerContainerHandler(function ($class, $params) use ($dice) {
|
|
|
|
$engine->registerContainerHandler(function ($class, $params) use ($dice) {
|
|
|
|
return $dice->create($class, $params);
|
|
|
|
return $dice->create($class, $params);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$engine->route('/container', Container::class.'->testThePdoWrapper');
|
|
|
|
$engine->route('/container', Container::class . '->testThePdoWrapper');
|
|
|
|
$engine->request()->url = '/container';
|
|
|
|
$engine->request()->url = '/container';
|
|
|
|
$engine->start();
|
|
|
|
$engine->start();
|
|
|
|
|
|
|
|
|
|
|
|
$this->expectOutputString('Yay! I injected a PdoWrapper, and it returned the number 5 from the database!');
|
|
|
|
$this->expectOutputString('Yay! I injected a PdoWrapper, and it returned the number 5 from the database!');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testContainerDiceFlightEngine() {
|
|
|
|
public function testContainerDiceFlightEngine()
|
|
|
|
|
|
|
|
{
|
|
|
|
$engine = new Engine();
|
|
|
|
$engine = new Engine();
|
|
|
|
$engine->set('test_me_out', 'You got it boss!');
|
|
|
|
$engine->set('test_me_out', 'You got it boss!');
|
|
|
|
$dice = new \Dice\Dice();
|
|
|
|
$dice = new \Dice\Dice();
|
|
|
|
@ -955,14 +956,15 @@ class EngineTest extends TestCase
|
|
|
|
return $dice->create($class, $params);
|
|
|
|
return $dice->create($class, $params);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$engine->route('/container', ContainerDefault::class.'->echoTheContainer');
|
|
|
|
$engine->route('/container', ContainerDefault::class . '->echoTheContainer');
|
|
|
|
$engine->request()->url = '/container';
|
|
|
|
$engine->request()->url = '/container';
|
|
|
|
$engine->start();
|
|
|
|
$engine->start();
|
|
|
|
|
|
|
|
|
|
|
|
$this->expectOutputString('You got it boss!');
|
|
|
|
$this->expectOutputString('You got it boss!');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testContainerDiceBadClass() {
|
|
|
|
public function testContainerDiceBadClass()
|
|
|
|
|
|
|
|
{
|
|
|
|
$engine = new Engine();
|
|
|
|
$engine = new Engine();
|
|
|
|
$dice = new \Dice\Dice();
|
|
|
|
$dice = new \Dice\Dice();
|
|
|
|
$engine->registerContainerHandler(function ($class, $params) use ($dice) {
|
|
|
|
$engine->registerContainerHandler(function ($class, $params) use ($dice) {
|
|
|
|
@ -978,20 +980,21 @@ class EngineTest extends TestCase
|
|
|
|
$engine->start();
|
|
|
|
$engine->start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testContainerDiceBadMethod() {
|
|
|
|
public function testContainerDiceBadMethod()
|
|
|
|
|
|
|
|
{
|
|
|
|
$engine = new Engine();
|
|
|
|
$engine = new Engine();
|
|
|
|
$dice = new \Dice\Dice();
|
|
|
|
$dice = new \Dice\Dice();
|
|
|
|
$dice = $dice->addRules([
|
|
|
|
$dice = $dice->addRules([
|
|
|
|
PdoWrapper::class => [
|
|
|
|
PdoWrapper::class => [
|
|
|
|
'shared' => true,
|
|
|
|
'shared' => true,
|
|
|
|
'constructParams' => [ 'sqlite::memory:' ]
|
|
|
|
'constructParams' => ['sqlite::memory:']
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
$engine->registerContainerHandler(function ($class, $params) use ($dice) {
|
|
|
|
$engine->registerContainerHandler(function ($class, $params) use ($dice) {
|
|
|
|
return $dice->create($class, $params);
|
|
|
|
return $dice->create($class, $params);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$engine->route('/container', Container::class.'->badMethod');
|
|
|
|
$engine->route('/container', Container::class . '->badMethod');
|
|
|
|
$engine->request()->url = '/container';
|
|
|
|
$engine->request()->url = '/container';
|
|
|
|
|
|
|
|
|
|
|
|
$this->expectException(Exception::class);
|
|
|
|
$this->expectException(Exception::class);
|
|
|
|
@ -1000,7 +1003,8 @@ class EngineTest extends TestCase
|
|
|
|
$engine->start();
|
|
|
|
$engine->start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testContainerPsr11(): void {
|
|
|
|
public function testContainerPsr11(): void
|
|
|
|
|
|
|
|
{
|
|
|
|
$engine = new Engine();
|
|
|
|
$engine = new Engine();
|
|
|
|
$container = new \League\Container\Container();
|
|
|
|
$container = new \League\Container\Container();
|
|
|
|
$container->add(Container::class)->addArgument(Collection::class)->addArgument(PdoWrapper::class);
|
|
|
|
$container->add(Container::class)->addArgument(Collection::class)->addArgument(PdoWrapper::class);
|
|
|
|
@ -1008,14 +1012,15 @@ class EngineTest extends TestCase
|
|
|
|
$container->add(PdoWrapper::class)->addArgument('sqlite::memory:');
|
|
|
|
$container->add(PdoWrapper::class)->addArgument('sqlite::memory:');
|
|
|
|
$engine->registerContainerHandler($container);
|
|
|
|
$engine->registerContainerHandler($container);
|
|
|
|
|
|
|
|
|
|
|
|
$engine->route('/container', Container::class.'->testTheContainer');
|
|
|
|
$engine->route('/container', Container::class . '->testTheContainer');
|
|
|
|
$engine->request()->url = '/container';
|
|
|
|
$engine->request()->url = '/container';
|
|
|
|
$engine->start();
|
|
|
|
$engine->start();
|
|
|
|
|
|
|
|
|
|
|
|
$this->expectOutputString('yay! I injected a collection, and it has 1 items');
|
|
|
|
$this->expectOutputString('yay! I injected a collection, and it has 1 items');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testContainerPsr11ClassNotFound() {
|
|
|
|
public function testContainerPsr11ClassNotFound()
|
|
|
|
|
|
|
|
{
|
|
|
|
$engine = new Engine();
|
|
|
|
$engine = new Engine();
|
|
|
|
$container = new \League\Container\Container();
|
|
|
|
$container = new \League\Container\Container();
|
|
|
|
$container->add(Container::class)->addArgument(Collection::class);
|
|
|
|
$container->add(Container::class)->addArgument(Collection::class);
|
|
|
|
@ -1031,7 +1036,8 @@ class EngineTest extends TestCase
|
|
|
|
$engine->start();
|
|
|
|
$engine->start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testContainerPsr11MethodNotFound(): void {
|
|
|
|
public function testContainerPsr11MethodNotFound(): void
|
|
|
|
|
|
|
|
{
|
|
|
|
$engine = new Engine();
|
|
|
|
$engine = new Engine();
|
|
|
|
$container = new \League\Container\Container();
|
|
|
|
$container = new \League\Container\Container();
|
|
|
|
$container->add(Container::class)->addArgument(Collection::class)->addArgument(PdoWrapper::class);
|
|
|
|
$container->add(Container::class)->addArgument(Collection::class)->addArgument(PdoWrapper::class);
|
|
|
|
@ -1039,7 +1045,7 @@ class EngineTest extends TestCase
|
|
|
|
$container->add(PdoWrapper::class)->addArgument('sqlite::memory:');
|
|
|
|
$container->add(PdoWrapper::class)->addArgument('sqlite::memory:');
|
|
|
|
$engine->registerContainerHandler($container);
|
|
|
|
$engine->registerContainerHandler($container);
|
|
|
|
|
|
|
|
|
|
|
|
$engine->route('/container', Container::class.'->badMethod');
|
|
|
|
$engine->route('/container', Container::class . '->badMethod');
|
|
|
|
$engine->request()->url = '/container';
|
|
|
|
$engine->request()->url = '/container';
|
|
|
|
|
|
|
|
|
|
|
|
$this->expectException(Exception::class);
|
|
|
|
$this->expectException(Exception::class);
|
|
|
|
@ -1048,7 +1054,8 @@ class EngineTest extends TestCase
|
|
|
|
$engine->start();
|
|
|
|
$engine->start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testRouteFoundButBadMethod(): void {
|
|
|
|
public function testRouteFoundButBadMethod(): void
|
|
|
|
|
|
|
|
{
|
|
|
|
$engine = new class extends Engine {
|
|
|
|
$engine = new class extends Engine {
|
|
|
|
public function getLoader()
|
|
|
|
public function getLoader()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -1118,7 +1125,7 @@ class EngineTest extends TestCase
|
|
|
|
$streamPath = stream_get_meta_data($tmpfile)['uri'];
|
|
|
|
$streamPath = stream_get_meta_data($tmpfile)['uri'];
|
|
|
|
$this->expectOutputString('I am a teapot');
|
|
|
|
$this->expectOutputString('I am a teapot');
|
|
|
|
$engine->download($streamPath);
|
|
|
|
$engine->download($streamPath);
|
|
|
|
$this->assertContains('Content-Disposition: attachment; filename="'.basename($streamPath).'"', $engine->response()->headersSent);
|
|
|
|
$this->assertContains('Content-Disposition: attachment; filename="' . basename($streamPath) . '"', $engine->response()->headersSent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testDownloadWithDefaultFileName(): void
|
|
|
|
public function testDownloadWithDefaultFileName(): void
|
|
|
|
@ -1151,11 +1158,11 @@ class EngineTest extends TestCase
|
|
|
|
$this->assertContains('Content-Disposition: attachment; filename="something.txt"', $engine->response()->headersSent);
|
|
|
|
$this->assertContains('Content-Disposition: attachment; filename="something.txt"', $engine->response()->headersSent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testDownloadBadPath() {
|
|
|
|
public function testDownloadBadPath()
|
|
|
|
|
|
|
|
{
|
|
|
|
$engine = new Engine();
|
|
|
|
$engine = new Engine();
|
|
|
|
$this->expectException(Exception::class);
|
|
|
|
$this->expectException(Exception::class);
|
|
|
|
$this->expectExceptionMessage("/path/to/nowhere cannot be found.");
|
|
|
|
$this->expectExceptionMessage("/path/to/nowhere cannot be found.");
|
|
|
|
$engine->download('/path/to/nowhere');
|
|
|
|
$engine->download('/path/to/nowhere');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|