Skip to content

Commit

Permalink
Merge pull request #68 from cakephp/deprecate-upper
Browse files Browse the repository at this point in the history
Deprecate low and up filters
  • Loading branch information
othercorey authored Dec 13, 2020
2 parents f21b07b + 019fce1 commit 668dd6a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/Twig/Extension/BasicExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,24 @@ public function getFilters(): array

return pr(...func_get_args());
}),
new TwigFilter('low', 'strtolower'),
new TwigFilter('up', 'strtoupper'),
new TwigFilter('low', function () {
static $logged = false;
if (!$logged) {
$logged = true;
deprecationWarning('`low` filter is deprecated, use `lower` instead.');
}

return strtolower(...func_get_args());
}),
new TwigFilter('up', function () {
static $logged = false;
if (!$logged) {
$logged = true;
deprecationWarning('`up` filter is deprecated, use `upper` instead.');
}

return strtoupper(...func_get_args());
}),
new TwigFilter('env', 'env'),
new TwigFilter('count', function () {
static $logged = false;
Expand Down
16 changes: 16 additions & 0 deletions tests/TestCase/Twig/Extension/BasicExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ public function testDeprecatedPr()
call_user_func_array($callable, ['test']);
}

public function testDeprecatedLow()
{
$this->deprecated(function () {
$callable = $this->getFilter('low')->getCallable();
$this->assertSame('test', call_user_func_array($callable, ['TEST']));
});
}

public function testDeprecatedUp()
{
$this->deprecated(function () {
$callable = $this->getFilter('up')->getCallable();
$this->assertSame('TEST', call_user_func_array($callable, ['test']));
});
}

public function testDeprecatedCount()
{
$callable = $this->getFilter('count')->getCallable();
Expand Down

0 comments on commit 668dd6a

Please sign in to comment.