Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/203'
Browse files Browse the repository at this point in the history
Close #203
Fix #202
  • Loading branch information
michalbundyra committed Dec 4, 2019
2 parents b838a5d + 6942439 commit cb7e643
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 50 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ matrix:
- php: 7.3
env:
- DEPS=latest
- php: 7.4snapshot
env:
- DEPS=latest

before_install:
- if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#203](https://github.com/zendframework/zend-view/pull/203) fixes PHP 7.4 compatibility.

## 2.11.3 - 2019-10-11

Expand Down
3 changes: 2 additions & 1 deletion src/Helper/Partial.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Zend\View\Helper;

use Traversable;
use Zend\View\Exception;
use Zend\View\Model\ModelInterface;

Expand Down Expand Up @@ -53,7 +54,7 @@ public function __invoke($name = null, $values = null)
$values = [$objectKey => $values];
} elseif (method_exists($values, 'toArray')) {
$values = $values->toArray();
} else {
} elseif (! $values instanceof Traversable) {
$values = get_object_vars($values);
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/Helper/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function setUp()

public function testViewSettersGetters()
{
$viewMock = $this->getMockBuilder(RendererInterface::class)->getMock();
$viewMock = $this->prophesize(RendererInterface::class)->reveal();

$this->helper->setView($viewMock);
$this->assertEquals($viewMock, $this->helper->getView());
Expand Down
17 changes: 7 additions & 10 deletions test/Helper/FlashMessengerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace ZendTest\View\Helper;

use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Zend\I18n\Translator\Translator;
use Zend\Mvc\Controller\Plugin\FlashMessenger as V2PluginFlashMessenger;
use Zend\Mvc\Controller\PluginManager;
Expand Down Expand Up @@ -398,12 +399,10 @@ public function testCanDisplayListOfCurrentMessagesCustomisedByConfigSeparator()

public function testCanTranslateMessages()
{
$mockTranslator = $this->getMockBuilder(Translator::class)->getMock();
$mockTranslator->expects($this->exactly(1))
->method('translate')
->will($this->returnValue('translated message'));
$mockTranslator = $this->prophesize(Translator::class);
$mockTranslator->translate('bar-info', 'default')->willReturn('translated message')->shouldBeCalledTimes(1);

$this->helper->setTranslator($mockTranslator);
$this->helper->setTranslator($mockTranslator->reveal());
$this->assertTrue($this->helper->hasTranslator());

$this->seedMessages();
Expand All @@ -415,12 +414,10 @@ public function testCanTranslateMessages()

public function testCanTranslateCurrentMessages()
{
$mockTranslator = $this->getMockBuilder(Translator::class)->getMock();
$mockTranslator->expects($this->exactly(1))
->method('translate')
->will($this->returnValue('translated message'));
$mockTranslator = $this->prophesize(Translator::class);
$mockTranslator->translate('bar-info', 'default')->willReturn('translated message')->shouldBeCalledTimes(1);

$this->helper->setTranslator($mockTranslator);
$this->helper->setTranslator($mockTranslator->reveal());
$this->assertTrue($this->helper->hasTranslator());

$this->seedCurrentMessages();
Expand Down
2 changes: 1 addition & 1 deletion test/Helper/HeadTitleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public function testCanTranslateTitle()

public function testTranslatorMethods()
{
$translatorMock = $this->getMockBuilder(Translator::class)->getMock();
$translatorMock = $this->prophesize(Translator::class)->reveal();
$this->helper->setTranslator($translatorMock, 'foo');

$this->assertEquals($translatorMock, $this->helper->getTranslator());
Expand Down
3 changes: 2 additions & 1 deletion test/Helper/Navigation/NavigationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Zend\View;
use Zend\View\Helper\Navigation;
use Zend\View\Renderer\PhpRenderer;
use Zend\I18n\Translator\Translator;

/**
* Tests Zend\View\Helper\Navigation
Expand Down Expand Up @@ -219,7 +220,7 @@ public function testDisablingTranslatorInjection()

public function testTranslatorMethods()
{
$translatorMock = $this->getMockBuilder('Zend\I18n\Translator\Translator')->getMock();
$translatorMock = $this->prophesize(Translator::class)->reveal();
$this->_helper->setTranslator($translatorMock, 'foo');

$this->assertEquals($translatorMock, $this->_helper->getTranslator());
Expand Down
19 changes: 19 additions & 0 deletions test/Helper/PartialTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace ZendTest\View\Helper;

use ArrayObject;
use PHPUnit\Framework\TestCase;
use Zend\View\Helper\Partial;
use Zend\View\Model\ViewModel;
Expand Down Expand Up @@ -148,6 +149,24 @@ public function testCanPassViewModelAsSecondArgument()
}
}

public function testCanPassArrayObjectAsSecondArgument()
{
$model = new ArrayObject([
'foo' => 'bar',
'bar' => 'baz',
]);

$view = new View();
$view->resolver()->addPath($this->basePath . '/application/views/scripts');
$this->helper->setView($view);
$return = $this->helper->__invoke('partialVars.phtml', $model);

foreach ($model as $key => $value) {
$string = sprintf('%s: %s', $key, $value);
$this->assertContains($string, $return);
}
}

public function testCanPassViewModelAsSoleArgument()
{
$model = new ViewModel([
Expand Down
11 changes: 5 additions & 6 deletions test/Resolver/PrefixPathStackResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,15 @@ public function testResolveWithCongruentPrefix()

public function testSetCustomPathStackResolver()
{
$mockResolver = $this->getMockBuilder(ResolverInterface::class)->getMock();
$mockResolver = $this->prophesize(ResolverInterface::class);
$mockResolver->resolve('/bar', null)->willReturn('1111');
$mockResolver->resolve('/baz', null)->willReturn('2222');
$mockResolver->resolve('/tab', null)->willReturn(false);

$resolver = new PrefixPathStackResolver([
'foo' => $mockResolver,
'foo' => $mockResolver->reveal(),
]);

$mockResolver->expects($this->at(0))->method('resolve')->with('/bar')->will($this->returnValue('1111'));
$mockResolver->expects($this->at(1))->method('resolve')->with('/baz')->will($this->returnValue('2222'));
$mockResolver->expects($this->at(2))->method('resolve')->with('/tab')->will($this->returnValue(false));

$this->assertSame('1111', $resolver->resolve('foo/bar'));
$this->assertSame('2222', $resolver->resolve('foo/baz'));
$this->assertNull($resolver->resolve('foo/tab'));
Expand Down
50 changes: 21 additions & 29 deletions test/Resolver/RelativeFallbackResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
namespace ZendTest\View\Resolver;

use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use stdClass;
use Zend\View\Helper\ViewModel as ViewModelHelper;
use Zend\View\Model\ViewModel;
use Zend\View\Renderer\PhpRenderer;
use Zend\View\Renderer\RendererInterface;
use Zend\View\Resolver\RelativeFallbackResolver;
use Zend\View\Resolver\ResolverInterface;
use Zend\View\Resolver\TemplateMapResolver;
Expand Down Expand Up @@ -81,47 +81,39 @@ public function testReturnsResourceFromTopLevelIfExistsInsteadOfTheSameNameSpace

public function testSkipsResolutionOnViewRendererWithoutPlugins()
{
/* @var $baseResolver ResolverInterface|\PHPUnit_Framework_MockObject_MockObject */
$baseResolver = $this->getMockBuilder(ResolverInterface::class)->getMock();
$fallback = new RelativeFallbackResolver($baseResolver);
/* @var $renderer RendererInterface|\PHPUnit_Framework_MockObject_MockObject */
$renderer = $this->getMockBuilder(RendererInterface::class)->getMock();
$baseResolver = $this->prophesize(ResolverInterface::class);
$baseResolver->resolve()->shouldNotBeCalled();
$fallback = new RelativeFallbackResolver($baseResolver->reveal());

$baseResolver->expects($this->never())->method('resolve');
$renderer = $this->prophesize(PhpRenderer::class)->reveal();

$this->assertFalse($fallback->resolve('foo/bar', $renderer));
}

public function testSkipsResolutionOnViewRendererWithoutCorrectCurrentPlugin()
{
/* @var $baseResolver ResolverInterface|\PHPUnit_Framework_MockObject_MockObject */
$baseResolver = $this->getMockBuilder(ResolverInterface::class)->getMock();
$fallback = new RelativeFallbackResolver($baseResolver);
/* @var $renderer RendererInterface|\PHPUnit_Framework_MockObject_MockObject */
$renderer = $this->getMockBuilder(RendererInterface::class)
->setMethods(['getEngine', 'setResolver', 'plugin', 'render'])
->getMock();
$baseResolver = $this->prophesize(ResolverInterface::class);
$baseResolver->resolve()->shouldNotBeCalled();

$baseResolver->expects($this->never())->method('resolve');
$renderer->expects($this->once())->method('plugin')->will($this->returnValue(new stdClass()));
$fallback = new RelativeFallbackResolver($baseResolver->reveal());

$this->assertFalse($fallback->resolve('foo/bar', $renderer));
$renderer = $this->prophesize(PhpRenderer::class);
$renderer->plugin(Argument::any())->willReturn(new stdClass())->shouldBeCalledTimes(1);

$this->assertFalse($fallback->resolve('foo/bar', $renderer->reveal()));
}

public function testSkipsResolutionOnNonExistingCurrentViewModel()
{
/* @var $baseResolver ResolverInterface|\PHPUnit_Framework_MockObject_MockObject */
$baseResolver = $this->getMockBuilder(ResolverInterface::class)->getMock();
$fallback = new RelativeFallbackResolver($baseResolver);
$viewModel = new ViewModelHelper();
/* @var $renderer RendererInterface|\PHPUnit_Framework_MockObject_MockObject */
$renderer = $this->getMockBuilder(RendererInterface::class)
->setMethods(['getEngine', 'setResolver', 'plugin', 'render'])
->getMock();

$baseResolver->expects($this->never())->method('resolve');
$renderer->expects($this->once())->method('plugin')->will($this->returnValue($viewModel));
$baseResolver = $this->prophesize(ResolverInterface::class);
$baseResolver->resolve()->shouldNotBeCalled();

$this->assertFalse($fallback->resolve('foo/bar', $renderer));
$fallback = new RelativeFallbackResolver($baseResolver->reveal());
$viewModel = new ViewModelHelper();

$renderer = $this->prophesize(PhpRenderer::class);
$renderer->plugin(Argument::any())->willReturn($viewModel)->shouldBeCalledTimes(1);

$this->assertFalse($fallback->resolve('foo/bar', $renderer->reveal()));
}
}

0 comments on commit cb7e643

Please sign in to comment.