Пример #1
0
 public function test()
 {
     $container = new \MicroVFS\Container();
     $container->set('tpl/test.tpl', 'content: foo = <?= $foo ?>');
     \MicroVFS\StreamWrapper::unregister('vfs');
     \MicroVFS\StreamWrapper::register('vfs', $container);
     $settings = $this->mockSettings(['path' => 'vfs://tpl'], ['ext' => ['.tpl', '.tpl']]);
     $renderer = new HtmlTemplateRenderer($settings);
     $doc = $renderer->render('test', ['foo' => 'baz']);
     $this->assertEquals('text/html', $doc->mime());
     $this->assertEquals('content: foo = baz', $doc->content());
 }
Пример #2
0
 public function testPartial()
 {
     $container = new \MicroVFS\Container();
     $container->set('tpl/test.tpl', 'content: foo = <?= $this->render("foo", ["x" => 5]) ?>');
     $container->set('tpl/foo.tpl', '"x: <?= $x ?>"');
     \MicroVFS\StreamWrapper::unregister('vfs');
     \MicroVFS\StreamWrapper::register('vfs', $container);
     $settings = $this->mockSettings(['path' => 'vfs://tpl'], ['ext' => ['.tpl', '.tpl']]);
     $renderer = new TemplateRenderer($settings);
     $body = $renderer->render('test', []);
     $this->assertEquals('content: foo = "x: 5"', $body);
 }
Пример #3
0
 public function testMoveWithFuncMock()
 {
     $container = new \MicroVFS\Container();
     $container->set('tmp/xxxxx.tmp', 'test text');
     $container->setDir('target');
     \MicroVFS\StreamWrapper::unregister('vfs');
     \MicroVFS\StreamWrapper::register('vfs', $container);
     $defunc = (new \Defunc\Builder())->in('Yen\\Http');
     $defunc->move_uploaded_file('vfs://tmp/xxxxx.tmp', 'vfs://target/test.txt')->willReturn(true);
     $ufile = new Http\UploadedFile(UPLOAD_ERR_OK, 9, 'test.txt', 'text/plain', 'vfs://tmp/xxxxx.tmp');
     $moved = $ufile->moveTo('vfs://target/test.txt');
     $this->assertTrue($moved);
     $defunc->clear();
 }
Пример #4
0
 public function testDuplicateRouteNameException()
 {
     $this->expectException(\LogicException::class);
     $this->expectExceptionMessage('Route with name "test" already added');
     $rules = ['@test /test/:foo => test/info', '@fzz /fzz => test/fzz', '@test /foobar => /foo/bar', '/* => $uri'];
     $vfs = new \MicroVFS\Container();
     $vfs->set('router.rules', implode("\n", $rules));
     \MicroVFS\StreamWrapper::register('mvfs', $vfs);
     $router = Router::createFromRoutesFile('mvfs://router.rules');
 }