Skip to content

Latest commit

 

History

History
81 lines (58 loc) · 2.15 KB

Tests.md

File metadata and controls

81 lines (58 loc) · 2.15 KB

Meritoo Common Bundle

Common & useful classes, resources, extensions. Based on Symfony framework.

Tests

Twig extension

Use BaseTwigExtensionTestCase class. It's a base test case for Twig extension.

Implementation

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;
}
Simple and quick verification of functions, filters etc.

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);
Custom verification of functions, filters etc.

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);

More

  1. Configuration
  2. Dependency Injection Extension
  3. Descriptor of application
  4. Descriptor of bundle
  5. Descriptors of bundles
  6. Services:
  7. Tests
  8. Translations
  9. Twig extensions:

‹ Back to Readme