Common & useful classes, resources, extensions. Based on Symfony framework.
Use BaseTwigExtensionTestCase
class. It's a base test case for Twig extension.
Extend this class, implement abstract getExtensionNamespace()
method and you can easily verify Twig extension.
Example of getExtensionNamespace()
method implementation:
/**
* {@inheritdoc}
*/
protected function getExtensionNamespace(): string
{
return ApplicationExtension::class;
}
Use verifyRenderedTemplate()
method to verify template. Pass:
- name of template (anything you want)
- source code of the template
- expected result of rendering the template
Example:
$name = 'anything';
$sourceCode = '{{ meritoo_common_application_descriptor().description }}';
$expected = 'Just for Testing';
$this->verifyRenderedTemplate($name, $sourceCode, $expected);
In verifyRenderedTemplate()
method the assertSame()
assert is used. If you want to use another assert, render
your template and make proper comparison of result with expected result.
Example:
//...
$rendered = $this
->getTwigEnvironment($templates)
->render($name);
static::assertEquals('lorem ipsum', $rendered);
- Configuration
- Dependency Injection Extension
- Descriptor of application
- Descriptor of bundle
- Descriptors of bundles
- Services:
- Tests
- Translations
- Twig extensions: