Skip to content

Commit

Permalink
Merge pull request #13 from victorwelling/master
Browse files Browse the repository at this point in the history
Fix for inherited variables
  • Loading branch information
Victor Welling committed Oct 3, 2018
2 parents 8397b9a + 84863ae commit 9e049ca
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Twig/PatchingCompiler.php
Expand Up @@ -49,6 +49,6 @@ private function patch($string)

return !is_string($string)
? $string
: preg_replace($patterns, '$1array_merge($originalContext ?? [], $context)$2', $string);
: preg_replace($patterns, '$1array_merge($context, $originalContext ?? [])$2', $string);
}
}
1 change: 1 addition & 0 deletions tests/Integration/Embedding/EmbeddingTest.php
Expand Up @@ -47,6 +47,7 @@ public function testOverriddenBlocksShouldReceiveVariablesFromParent()
{
$output = $this->renderTemplate('page.twig');

$this->assertContains('<title>page_title</title>', $output);
$this->assertContains('<h1>page_title</h1>', $output);
$this->assertContains('<p>page_content</p>', $output);
}
Expand Down
16 changes: 14 additions & 2 deletions tests/Integration/Embedding/Models/Base.php
Expand Up @@ -3,10 +3,22 @@

namespace Shoot\Shoot\Tests\Integration\Embedding\Models;

use Shoot\Shoot\HasPresenterInterface;
use Shoot\Shoot\PresentationModel;
use Shoot\Shoot\Tests\Integration\Embedding\Presenters\BasePresenter;

final class Base extends PresentationModel
final class Base extends PresentationModel implements HasPresenterInterface
{
/** @var string */
protected $title = 'base_title';
protected $title = '';

/**
* Returns the name by which to resolve the presenter through the DI container.
*
* @return string
*/
public function getPresenterName(): string
{
return BasePresenter::class;
}
}
27 changes: 27 additions & 0 deletions tests/Integration/Embedding/Presenters/BasePresenter.php
@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);

namespace Shoot\Shoot\Tests\Integration\Embedding\Presenters;

use Psr\Http\Message\ServerRequestInterface;
use Shoot\Shoot\PresentationModel;
use Shoot\Shoot\PresenterInterface;

final class BasePresenter implements PresenterInterface
{
/**
* Receives the current HTTP request context and the presentation model assigned to the view. If necessary,
* populates the presentation model with data and returns it.
*
* @param ServerRequestInterface $request
* @param PresentationModel $presentationModel
*
* @return PresentationModel
*/
public function present(ServerRequestInterface $request, PresentationModel $presentationModel): PresentationModel
{
return $presentationModel->withVariables([
'title' => 'base_title'
]);
}
}

0 comments on commit 9e049ca

Please sign in to comment.