<?php
// content of file Fixtures/filter/myfilter.test
/*
--TEST--
"myfilter" filter test
--TEMPLATE--
{{ foo|myfilter }}
{{ notfoo|myfilter }}
--DATA--
return ['foo' => 'this is foo', 'notfoo' => 'nothing changed']
--EXPECT--
this is bar
nothing changed
*/
class TwigExtensionTest extends Twig\Test\IntegrationTestCase
{
public function getExtensions()
{
return [
new MyExtension(),
];
}
public function getFixturesDir()
{
$path = __DIR__ . '/Fixtures/';
return $path;
}
}
class MyExtension extends Twig\Extension\AbstractExtension
{
public function getFilters()
{
return [
new Twig\TwigFilter('myfilter', function ($value) {
return str_replace('foo', 'bar', $value);
}),
];
}
public function getName()
{
return 'myextension';
}
}
Result
Time: 00:00.031, Memory: 18.00 MB
OK, but incomplete, skipped, or risky tests!
Tests: 2, Assertions: 0, Skipped: 1.