Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Commit

Permalink
Removed usages of deprecated getMock()
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj committed Feb 10, 2017
1 parent b399f4e commit b377a22
Show file tree
Hide file tree
Showing 13 changed files with 144 additions and 186 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -15,7 +15,7 @@ env:
matrix: SYMFONY_VERSION=3.2.*
global:
- SYMFONY_DEPRECATIONS_HELPER=2
- SYMFONY_PHPUNIT_DIR=.phpunit SYMFONY_PHPUNIT_REMOVE="symfony/yaml"
- SYMFONY_PHPUNIT_DIR=.phpunit SYMFONY_PHPUNIT_REMOVE="symfony/yaml" SYMFONY_PHPUNIT_VERSION=5.7

matrix:
include:
Expand Down
17 changes: 9 additions & 8 deletions tests/Functional/Block/ActionBlockServiceTest.php
Expand Up @@ -11,11 +11,13 @@

namespace Symfony\Cmf\Bundle\BlockBundle\Tests\Functional\Block;

use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
use Symfony\Component\Templating\EngineInterface;
use Sonata\BlockBundle\Block\BlockContext;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Cmf\Bundle\BlockBundle\Block\ActionBlockService;
use Symfony\Cmf\Bundle\BlockBundle\Doctrine\Phpcr\ActionBlock;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;

class ActionBlockServiceTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -31,12 +33,11 @@ class ActionBlockServiceTest extends \PHPUnit_Framework_TestCase

private $requestStack;

public function setUp()
protected function setUp()
{
$this->templating = $this->getMock('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface');
$this->kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Fragment\FragmentHandler')
->disableOriginalConstructor()->getMock();
$this->requestStack = $this->getMock('Symfony\Component\HttpFoundation\RequestStack');
$this->templating = $this->createMock(EngineInterface::class);
$this->kernel = $this->createMock(FragmentHandler::class);
$this->requestStack = $this->createMock(RequestStack::class);
}

public function testExecutionOfDisabledBlock()
Expand All @@ -62,7 +63,7 @@ public function testExecutionOfEnabledBlock()

$content = 'Rendered Action Block.';

$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
$request = $this->createMock(Request::class);

$this->kernel
->expects($this->any())
Expand Down
37 changes: 12 additions & 25 deletions tests/Functional/Block/ContainerBlockServiceTest.php
Expand Up @@ -11,11 +11,14 @@

namespace Symfony\Cmf\Bundle\BlockBundle\Tests\Functional\Block;

use Doctrine\ODM\PHPCR\ChildrenCollection;
use Sonata\BlockBundle\Block\BlockContext;
use Symfony\Component\HttpFoundation\Response;
use Sonata\BlockBundle\Block\BlockRendererInterface;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Cmf\Bundle\BlockBundle\Block\ContainerBlockService;
use Symfony\Cmf\Bundle\BlockBundle\Doctrine\Phpcr\ContainerBlock;
use Symfony\Cmf\Bundle\BlockBundle\Doctrine\Phpcr\SimpleBlock;
use Symfony\Component\HttpFoundation\Response;

class ContainerBlockServiceTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -24,15 +27,11 @@ public function testExecutionOfDisabledBlock()
$containerBlock = new ContainerBlock();
$containerBlock->setEnabled(false);

$blockRendererMock = $this->getMockBuilder('Sonata\BlockBundle\Block\BlockRendererInterface')
->disableOriginalConstructor()
->getMock();
$blockRendererMock = $this->createMock(BlockRendererInterface::class);
$blockRendererMock->expects($this->never())
->method('render');

$templatingMock = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface')
->disableOriginalConstructor()
->getMock();
$templatingMock = $this->createMock(EngineInterface::class);

$containerBlockService = new ContainerBlockService('test-service', $templatingMock, $blockRendererMock);
$containerBlockService->execute(new BlockContext($containerBlock));
Expand All @@ -48,9 +47,7 @@ public function testExecutionOfEnabledBlock()
$simpleBlock2 = new SimpleBlock();
$simpleBlock2->setId(2);

$childrenCollectionMock = $this->getMockBuilder('Doctrine\ODM\PHPCR\ChildrenCollection')
->disableOriginalConstructor()
->getMock();
$childrenCollectionMock = $this->createMock(ChildrenCollection::class);

$containerBlock = new ContainerBlock('foo');
$containerBlock->setEnabled(true);
Expand All @@ -63,13 +60,9 @@ public function testExecutionOfEnabledBlock()
$responseContent1 = 'Rendered Simple Block 1.';
$responseContent2 = 'Rendered Simple Block 2.';

$blockRendererMock = $this->getMockBuilder('Sonata\BlockBundle\Block\BlockRendererInterface')
->disableOriginalConstructor()
->getMock();
$blockRendererMock = $this->createMock(BlockRendererInterface::class);

$templatingMock = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface')
->disableOriginalConstructor()
->getMock();
$templatingMock = $this->createMock(EngineInterface::class);

$templatingMock
->expects($this->once())
Expand All @@ -95,9 +88,7 @@ public function testExecutionOfBlockWithNoChildren()
{
$template = 'CmfBlockBundle:Block:block_container.html.twig';

$childrenCollectionMock = $this->getMockBuilder('Doctrine\ODM\PHPCR\ChildrenCollection')
->disableOriginalConstructor()
->getMock();
$childrenCollectionMock = $this->createMock(ChildrenCollection::class);

$containerBlock = new ContainerBlock('foo');
$containerBlock->setEnabled(true);
Expand All @@ -107,13 +98,9 @@ public function testExecutionOfBlockWithNoChildren()

$blockContext = new BlockContext($containerBlock, $settings);

$blockRendererMock = $this->getMockBuilder('Sonata\BlockBundle\Block\BlockRendererInterface')
->disableOriginalConstructor()
->getMock();
$blockRendererMock = $this->createMock(BlockRendererInterface::class);

$templatingMock = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface')
->disableOriginalConstructor()
->getMock();
$templatingMock = $this->createMock(EngineInterface::class);

$templatingMock
->expects($this->once())
Expand Down
36 changes: 14 additions & 22 deletions tests/Functional/Block/MenuBlockServiceTest.php
Expand Up @@ -11,7 +11,11 @@

namespace Symfony\Cmf\Bundle\BlockBundle\Tests\Functional\Block;

use Knp\Menu\NodeInterface;
use Sonata\BlockBundle\Block\BlockContext;
use Sonata\BlockBundle\Block\BlockContextManagerInterface;
use Sonata\BlockBundle\Block\BlockRendererInterface;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Cmf\Bundle\BlockBundle\Block\MenuBlockService;
use Symfony\Cmf\Bundle\BlockBundle\Doctrine\Phpcr\MenuBlock;
use Symfony\Cmf\Bundle\MenuBundle\Doctrine\Phpcr\MenuNode;
Expand All @@ -23,18 +27,12 @@ public function testExecutionOfDisabledBlock()
$menuBlock = new MenuBlock();
$menuBlock->setEnabled(false);

$templatingMock = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface')
->disableOriginalConstructor()
->getMock();
$templatingMock = $this->createMock(EngineInterface::class);

$blockRendererMock = $this->getMockBuilder('Sonata\BlockBundle\Block\BlockRendererInterface')
->disableOriginalConstructor()
->getMock();
$blockRendererMock->expects($this->never())
->method('render');
$blockContextManagerMock = $this->getMockBuilder('Sonata\BlockBundle\Block\BlockContextManagerInterface')
->disableOriginalConstructor()
->getMock();
$blockRendererMock = $this->createMock(BlockRendererInterface::class);
$blockRendererMock->expects($this->never())->method('render');

$blockContextManagerMock = $this->createMock(BlockContextManagerInterface::class);

$menuBlockService = new MenuBlockService('test-service', $templatingMock, $blockRendererMock, $blockContextManagerMock);
$menuBlockService->execute(new BlockContext($menuBlock));
Expand All @@ -51,17 +49,11 @@ public function testExecutionOfEnabledBlock()

$menuBlockContext = new BlockContext($menuBlock, array('template' => $template));

$templatingMock = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface')
->disableOriginalConstructor()
->getMock();
$templatingMock = $this->createMock(EngineInterface::class);

$blockRendererMock = $this->getMockBuilder('Sonata\BlockBundle\Block\BlockRendererInterface')
->disableOriginalConstructor()
->getMock();
$blockRendererMock = $this->createMock(BlockRendererInterface::class);

$blockContextManagerMock = $this->getMockBuilder('Sonata\BlockBundle\Block\BlockContextManagerInterface')
->disableOriginalConstructor()
->getMock();
$blockContextManagerMock = $this->createMock(BlockContextManagerInterface::class);

$menuBlockService = new MenuBlockService('test-service', $templatingMock, $blockRendererMock, $blockContextManagerMock);
$menuBlockService->execute($menuBlockContext);
Expand All @@ -72,8 +64,8 @@ public function testSetMenuNode()
$menuBlock = new MenuBlock();
$this->assertAttributeEmpty('menuNode', $menuBlock);

$menuBlock->setMenuNode($this->getMock('Knp\Menu\NodeInterface'));
$this->assertAttributeInstanceOf('Knp\Menu\NodeInterface', 'menuNode', $menuBlock);
$menuBlock->setMenuNode($this->createMock(NodeInterface::class));
$this->assertAttributeInstanceOf(NodeInterface::class, 'menuNode', $menuBlock);

$menuBlock->setMenuNode(null);
$this->assertAttributeSame(null, 'menuNode', $menuBlock);
Expand Down
56 changes: 23 additions & 33 deletions tests/Functional/Block/PhpcrBlockLoaderTest.php
Expand Up @@ -11,10 +11,16 @@

namespace Symfony\Cmf\Bundle\BlockBundle\Tests\Functional\Block;

use Doctrine\Bundle\PHPCRBundle\ManagerRegistry;
use Doctrine\ODM\PHPCR\DocumentManager;
use Doctrine\ODM\PHPCR\UnitOfWork;
use Sonata\BlockBundle\Model\BlockInterface;
use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishWorkflowChecker;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Cmf\Bundle\BlockBundle\Block\PhpcrBlockLoader;
use Symfony\Cmf\Bundle\BlockBundle\Doctrine\Phpcr\SimpleBlock;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;

class PhpcrBlockLoaderTest extends \PHPUnit_Framework_TestCase
Expand All @@ -37,23 +43,17 @@ class PhpcrBlockLoaderTest extends \PHPUnit_Framework_TestCase

public function setUp()
{
$this->registryMock = $this->getMockBuilder('Doctrine\Bundle\PHPCRBundle\ManagerRegistry')
->disableOriginalConstructor()
->getMock()
;
$this->dmMock = $this->getMockBuilder('Doctrine\ODM\PHPCR\DocumentManager')
->disableOriginalConstructor()
->getMock()
;
$this->pwcMock = $this->getMock(AuthorizationCheckerInterface::class);
$this->registryMock = $this->createMock(ManagerRegistry::class);
$this->dmMock = $this->createMock(DocumentManager::class);
$this->pwcMock = $this->createMock(AuthorizationCheckerInterface::class);
$this->registryMock->expects($this->any())
->method('getManager')
->with($this->equalTo('themanager'))
->will($this->returnValue($this->dmMock))
;

$this->request = Request::create('/');
$this->requestStackMock = $this->getMock('Symfony\Component\HttpFoundation\RequestStack');
$this->requestStackMock = $this->createMock(RequestStack::class);
$this->requestStackMock
->expects($this->any())
->method('getCurrentRequest')
Expand Down Expand Up @@ -83,7 +83,7 @@ public function testSupport()
public function testLoadWithAbsolutePath()
{
$absoluteBlockPath = '/some/absolute/path';
$block = $this->getMock('Sonata\BlockBundle\Model\BlockInterface');
$block = $this->createMock(BlockInterface::class);

$blockLoader = $this->getSimpleBlockLoaderInstance();
$this->dmMock->expects($this->once())
Expand All @@ -108,13 +108,11 @@ public function testFindByNameWithRelativePath()
{
$contentPath = '/absolute/content';
$relativeBlockPath = 'some/relative/path';
$block = $this->getMock('Sonata\BlockBundle\Model\BlockInterface');
$block = $this->createMock(BlockInterface::class);

$content = new MockContent($contentPath);

$parameterBagMock = $this->getMockBuilder('Symfony\Component\HttpFoundation\ParameterBag')
->disableOriginalConstructor()
->getMock();
$parameterBagMock = $this->createMock(ParameterBag::class);
$parameterBagMock->expects($this->once())
->method('get')
->with($this->equalTo('contentDocument'))
Expand All @@ -128,9 +126,7 @@ public function testFindByNameWithRelativePath()

$this->request->attributes = $parameterBagMock;

$unitOfWorkMock = $this->getMockBuilder('Doctrine\ODM\PHPCR\UnitOfWork')
->disableOriginalConstructor()
->getMock();
$unitOfWorkMock = $this->createMock(UnitOfWork::class);
$unitOfWorkMock->expects($this->any())
->method('getDocumentId')
->with($this->equalTo($content))
Expand Down Expand Up @@ -205,13 +201,13 @@ public function testLoadWithAlternativeDocumentManager()
{
$absoluteBlockPath = '/some/absolute/path';

$block = $this->getMock('Sonata\BlockBundle\Model\BlockInterface');
$block = $this->createMock(BlockInterface::class);
$block->expects($this->any())
->method('getName')
->will($this->returnValue('the-block'))
;

$altBlock = $this->getMock('Sonata\BlockBundle\Model\BlockInterface');
$altBlock = $this->createMock(BlockInterface::class);
$altBlock->expects($this->any())
->method('getName')
->will($this->returnValue('alt-block'))
Expand All @@ -226,10 +222,7 @@ public function testLoadWithAlternativeDocumentManager()
->will($this->returnValue($block))
;

$altDmMock = $this->getMockBuilder('Doctrine\ODM\PHPCR\DocumentManager')
->disableOriginalConstructor()
->getMock()
;
$altDmMock = $this->createMock(DocumentManager::class);
$altDmMock->expects($this->once())
->method('find')
->with(
Expand All @@ -244,15 +237,12 @@ public function testLoadWithAlternativeDocumentManager()
->will($this->returnValue(true))
;
$this->pwcMock->expects($this->at(1))
->method('isGranted')
->with(PublishWorkflowChecker::VIEW_ATTRIBUTE, $this->equalTo($altBlock))
->will($this->returnValue(true))
;

$registryMock = $this->getMockBuilder('Doctrine\Bundle\PHPCRBundle\ManagerRegistry')
->disableOriginalConstructor()
->getMock()
->method('isGranted')
->with(PublishWorkflowChecker::VIEW_ATTRIBUTE, $this->equalTo($altBlock))
->will($this->returnValue(true))
;

$registryMock = $this->createMock(ManagerRegistry::class);
$registryMock->expects($this->at(0))
->method('getManager')
->with($this->equalTo('themanager'))
Expand Down
27 changes: 9 additions & 18 deletions tests/Functional/Block/ReferenceBlockServiceTest.php
Expand Up @@ -12,6 +12,9 @@
namespace Symfony\Cmf\Bundle\BlockBundle\Tests\Functional\Block;

use Sonata\BlockBundle\Block\BlockContext;
use Sonata\BlockBundle\Block\BlockRendererInterface;
use Sonata\BlockBundle\Block\BlockContextManagerInterface;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Cmf\Bundle\BlockBundle\Block\ReferenceBlockService;
use Symfony\Cmf\Bundle\BlockBundle\Doctrine\Phpcr\ReferenceBlock;
use Symfony\Cmf\Bundle\BlockBundle\Doctrine\Phpcr\SimpleBlock;
Expand All @@ -23,18 +26,12 @@ public function testExecutionOfDisabledBlock()
$referenceBlock = new ReferenceBlock();
$referenceBlock->setEnabled(false);

$templatingMock = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface')
->disableOriginalConstructor()
->getMock();
$templatingMock = $this->createMock(EngineInterface::class);

$blockRendererMock = $this->getMockBuilder('Sonata\BlockBundle\Block\BlockRendererInterface')
->disableOriginalConstructor()
->getMock();
$blockRendererMock = $this->createMock(BlockRendererInterface::class);
$blockRendererMock->expects($this->never())
->method('render');
$blockContextManagerMock = $this->getMockBuilder('Sonata\BlockBundle\Block\BlockContextManagerInterface')
->disableOriginalConstructor()
->getMock();
$blockContextManagerMock = $this->createMock(BlockContextManagerInterface::class);

$referenceBlockService = new ReferenceBlockService('test-service', $templatingMock, $blockRendererMock, $blockContextManagerMock);
$referenceBlockService->execute(new BlockContext($referenceBlock));
Expand All @@ -52,21 +49,15 @@ public function testExecutionOfEnabledBlock()

$referenceBlockContext = new BlockContext($referenceBlock);

$templatingMock = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface')
->disableOriginalConstructor()
->getMock();
$templatingMock = $this->createMock(EngineInterface::class);

$blockRendererMock = $this->getMockBuilder('Sonata\BlockBundle\Block\BlockRendererInterface')
->disableOriginalConstructor()
->getMock();
$blockRendererMock = $this->createMock(BlockRendererInterface::class);
$blockRendererMock->expects($this->once())
->method('render')
->with(
$this->equalTo($simpleBlockContext)
);
$blockContextManagerMock = $this->getMockBuilder('Sonata\BlockBundle\Block\BlockContextManagerInterface')
->disableOriginalConstructor()
->getMock();
$blockContextManagerMock = $this->createMock(BlockContextManagerInterface::class);
$blockContextManagerMock->expects($this->once())
->method('get')
->will(
Expand Down

0 comments on commit b377a22

Please sign in to comment.