-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
matthes
committed
Jul 27, 2018
1 parent
7331124
commit 0b6d09e
Showing
7 changed files
with
163 additions
and
25 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
return [ | ||
"arrVal1" => [ | ||
"a", "b", "c" | ||
] | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
1: | ||
{print > out1} | ||
AAA | ||
{/print} | ||
2: | ||
{print >> out2} | ||
BBB | ||
{/print} | ||
{print >> out2} | ||
BBB | ||
{/print} | ||
3: | ||
{print > out3} | ||
CCC | ||
{/print} | ||
{print > out3} | ||
CCC | ||
{/print} | ||
4: | ||
{=out1} | ||
5: | ||
{=out2} | ||
6: | ||
{=out3} | ||
7: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
1: | ||
2: | ||
3: | ||
4: | ||
|
||
AAA | ||
5: | ||
|
||
BBB | ||
BBB | ||
6: | ||
|
||
CCC | ||
7: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: matthes | ||
* Date: 25.07.18 | ||
* Time: 11:38 | ||
*/ | ||
|
||
namespace Test; | ||
require __DIR__ . "/../vendor/autoload.php"; | ||
|
||
use http\Exception\InvalidArgumentException; | ||
use Leuffen\TextTemplate\TextTemplate; | ||
use Tester\Assert; | ||
use Tester\Environment; | ||
|
||
Environment::setup(); | ||
|
||
|
||
$tpl = <<<EOT | ||
-A- | ||
{print > out1} | ||
AAA | ||
{/print} | ||
-B- | ||
{print >> out2} | ||
BBB | ||
{/print} | ||
{print >> out2} | ||
BBB | ||
{/print} | ||
-C- | ||
{= out1} | ||
-D- | ||
{= out2} | ||
EOT; | ||
|
||
$compare = <<<EOT | ||
-A-*AAA* | ||
-B- | ||
-C- | ||
*BBB* | ||
EOT; | ||
|
||
|
||
$template = new TextTemplate($tpl); | ||
$sec = []; | ||
$template->addSection("section", function ($content, $params, $command, $context, $cmdParam) use (&$sec) { | ||
$sec[$params["name"]] = $content; | ||
if ($command !== "section") | ||
throw new InvalidArgumentException("Command missing"); | ||
return "*" . trim ($content) . "*"; | ||
}); | ||
$textResult = $template->apply([]); | ||
|
||
Assert::equal($compare, $textResult); | ||
Assert::equal("AAA", trim($sec["A"])); | ||
Assert::equal("BBB", trim($sec["B"])); |