TemplateTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php declare(strict_types=1);
  2. /*
  3. * This file is part of phpunit/php-text-template.
  4. *
  5. * (c) Sebastian Bergmann <sebastian@phpunit.de>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace SebastianBergmann\Template;
  11. use PHPUnit\Framework\TestCase;
  12. /**
  13. * @covers \SebastianBergmann\Template\Template
  14. */
  15. final class TemplateTest extends TestCase
  16. {
  17. public function testRendersFromGivenTemplateFileToString(): void
  18. {
  19. $template = new Template(__DIR__ . '/_fixture/one.txt');
  20. $template->setVar(
  21. [
  22. 'foo' => 'baz',
  23. 'bar' => 'barbara',
  24. ]
  25. );
  26. $this->assertSame("baz barbara\n", $template->render());
  27. }
  28. public function testRendersFromFallbackTemplateFileToString(): void
  29. {
  30. $template = new Template(__DIR__ . '/_fixture/two.txt');
  31. $template->setVar(
  32. [
  33. 'foo' => 'baz',
  34. 'bar' => 'barbara',
  35. ]
  36. );
  37. $this->assertSame("baz barbara\n", $template->render());
  38. }
  39. public function testVariablesCanBeMerged(): void
  40. {
  41. $template = new Template(__DIR__ . '/_fixture/one.txt');
  42. $template->setVar(
  43. [
  44. 'foo' => 'baz',
  45. ]
  46. );
  47. $template->setVar(
  48. [
  49. 'bar' => 'barbara',
  50. ]
  51. );
  52. $this->assertSame("baz barbara\n", $template->render());
  53. }
  54. public function testCannotRenderTemplateThatDoesNotExist(): void
  55. {
  56. $this->expectException(InvalidArgumentException::class);
  57. new Template('does_not_exist.html');
  58. }
  59. }