diff --git a/.travis.yml b/.travis.yml index ca5cb26d3..8d98c994d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/src/Helper/Partial.php b/src/Helper/Partial.php index 911878734..a50d24fe8 100644 --- a/src/Helper/Partial.php +++ b/src/Helper/Partial.php @@ -9,6 +9,7 @@ namespace Zend\View\Helper; +use Traversable; use Zend\View\Exception; use Zend\View\Model\ModelInterface; @@ -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); } } diff --git a/test/Helper/AbstractTest.php b/test/Helper/AbstractTest.php index a5ce85aaf..aa0dca0e9 100644 --- a/test/Helper/AbstractTest.php +++ b/test/Helper/AbstractTest.php @@ -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()); diff --git a/test/Helper/FlashMessengerTest.php b/test/Helper/FlashMessengerTest.php index e7fd3d9f6..57a733bfb 100644 --- a/test/Helper/FlashMessengerTest.php +++ b/test/Helper/FlashMessengerTest.php @@ -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; @@ -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(); @@ -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(); diff --git a/test/Helper/HeadTitleTest.php b/test/Helper/HeadTitleTest.php index ba48b5745..b95c38202 100644 --- a/test/Helper/HeadTitleTest.php +++ b/test/Helper/HeadTitleTest.php @@ -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()); diff --git a/test/Helper/Navigation/NavigationTest.php b/test/Helper/Navigation/NavigationTest.php index 05a4a8638..0e8bc4a4f 100644 --- a/test/Helper/Navigation/NavigationTest.php +++ b/test/Helper/Navigation/NavigationTest.php @@ -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 @@ -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()); diff --git a/test/Helper/PartialTest.php b/test/Helper/PartialTest.php index cbfd75077..f1ea037c1 100644 --- a/test/Helper/PartialTest.php +++ b/test/Helper/PartialTest.php @@ -9,6 +9,7 @@ namespace ZendTest\View\Helper; +use ArrayObject; use PHPUnit\Framework\TestCase; use Zend\View\Helper\Partial; use Zend\View\Model\ViewModel; @@ -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([ diff --git a/test/Resolver/PrefixPathStackResolverTest.php b/test/Resolver/PrefixPathStackResolverTest.php index c2580cbbe..103419e8d 100644 --- a/test/Resolver/PrefixPathStackResolverTest.php +++ b/test/Resolver/PrefixPathStackResolverTest.php @@ -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')); diff --git a/test/Resolver/RelativeFallbackResolverTest.php b/test/Resolver/RelativeFallbackResolverTest.php index 15ce28a76..aec9bd6c6 100644 --- a/test/Resolver/RelativeFallbackResolverTest.php +++ b/test/Resolver/RelativeFallbackResolverTest.php @@ -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; @@ -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())); } }