Skip to content

Commit

Permalink
Update tests to account for internal changes in Twig 3.9 (probably sh…
Browse files Browse the repository at this point in the history
…ould just use a Twig Environment instead of mocking this stuff...)
  • Loading branch information
mbabker committed May 8, 2024
1 parent e15d827 commit 5e6a5ae
Showing 1 changed file with 48 additions and 21 deletions.
69 changes: 48 additions & 21 deletions lib/Twig/Tests/View/TwigViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,23 @@ public function testRendersWithATemplateSpecifiedInTheOptions(): void
{
$options = ['template' => 'test.html.twig'];

/** @var MockObject&Template $template */
$template = $this->createMock(Template::class);
$template->expects(self::once())
->method('displayBlock')
->willReturnCallback(
static function (): void {
echo 'Twig template';
}
);

// As of Twig 3.9, the internal wrapper implementation changed to accommodate the new yield strategy
if (method_exists(Template::class, 'yieldBlock')) {
$template->expects(self::once())
->method('renderBlock')
->willReturn('Twig template');
} else {
$template->expects(self::once())
->method('displayBlock')
->willReturnCallback(
static function (): void {
echo 'Twig template';
}
);
}

$this->twig->expects(self::once())
->method('load')
Expand All @@ -51,14 +60,23 @@ static function (): void {

public function testRendersWithATemplateSpecifiedInTheConstructorWhenNotSetInTheOptions(): void
{
/** @var MockObject&Template $template */
$template = $this->createMock(Template::class);
$template->expects(self::once())
->method('displayBlock')
->willReturnCallback(
static function (): void {
echo 'Twig template';
}
);

// As of Twig 3.9, the internal wrapper implementation changed to accommodate the new yield strategy
if (method_exists(Template::class, 'yieldBlock')) {
$template->expects(self::once())
->method('renderBlock')
->willReturn('Twig template');
} else {
$template->expects(self::once())
->method('displayBlock')
->willReturnCallback(
static function (): void {
echo 'Twig template';
}
);
}

$this->twig->expects(self::once())
->method('load')
Expand All @@ -77,14 +95,23 @@ static function (): void {

public function testRendersWithTheDefaultTemplateWhenNotSetInConstructorOrOptions(): void
{
/** @var MockObject&Template $template */
$template = $this->createMock(Template::class);
$template->expects(self::once())
->method('displayBlock')
->willReturnCallback(
static function (): void {
echo 'Twig template';
}
);

// As of Twig 3.9, the internal wrapper implementation changed to accommodate the new yield strategy
if (method_exists(Template::class, 'yieldBlock')) {
$template->expects(self::once())
->method('renderBlock')
->willReturn('Twig template');
} else {
$template->expects(self::once())
->method('displayBlock')
->willReturnCallback(
static function (): void {
echo 'Twig template';
}
);
}

$this->twig->expects(self::once())
->method('load')
Expand Down

0 comments on commit 5e6a5ae

Please sign in to comment.