Skip to content

Commit

Permalink
Merge pull request #710 from doctrine/do_not_use_get_mock
Browse files Browse the repository at this point in the history
Use getMockBuilder instead of getMock
  • Loading branch information
dbu authored Jun 18, 2016
2 parents 8168015 + 5e26996 commit ba31531
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 28 deletions.
22 changes: 11 additions & 11 deletions tests/Doctrine/Tests/ODM/PHPCR/DocumentManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function testFindTranslation()
*/
public function testNewInstanceFromConfiguration()
{
$session = $this->getMock('PHPCR\SessionInterface');
$session = $this->getMockBuilder('PHPCR\SessionInterface')->getMock();
$config = new \Doctrine\ODM\PHPCR\Configuration();

$dm = DocumentManager::create($session, $config);
Expand All @@ -68,7 +68,7 @@ public function testNewInstanceFromConfiguration()
*/
public function testGetMetadataFactory()
{
$session = $this->getMock('PHPCR\SessionInterface');
$session = $this->getMockBuilder('PHPCR\SessionInterface')->getMock();

$dm = DocumentManager::create($session);

Expand All @@ -80,7 +80,7 @@ public function testGetMetadataFactory()
*/
public function testGetClassMetadataFor()
{
$session = $this->getMock('PHPCR\SessionInterface');
$session = $this->getMockBuilder('PHPCR\SessionInterface')->getMock();

$dm = DocumentManager::create($session);

Expand All @@ -95,7 +95,7 @@ public function testGetClassMetadataFor()
*/
public function testContains()
{
$session = $this->getMock('PHPCR\SessionInterface');
$session = $this->getMockBuilder('PHPCR\SessionInterface')->getMock();

$dm = DocumentManager::create($session);

Expand All @@ -115,7 +115,7 @@ public function testContains()
*/
public function testGetRepository()
{
$session = $this->getMock('PHPCR\SessionInterface');
$session = $this->getMockBuilder('PHPCR\SessionInterface')->getMock();

$dm = new DocumentManagerGetClassMetadata($session);

Expand All @@ -131,7 +131,7 @@ public function testGetRepository()
*/
public function testEscapeFullText()
{
$session = $this->getMock('PHPCR\SessionInterface');
$session = $this->getMockBuilder('PHPCR\SessionInterface')->getMock();

$dm = DocumentManager::create($session);

Expand All @@ -144,11 +144,11 @@ public function testEscapeFullText()
*/
public function testCreateQueryBuilder()
{
$session = $this->getMock('PHPCR\SessionInterface');
$workspace = $this->getMock('PHPCR\WorkspaceInterface');
$queryManager = $this->getMock('PHPCR\Query\QueryManagerInterface');
$qomf = $this->getMock('PHPCR\Query\QOM\QueryObjectModelFactoryInterface');
$baseQuery = $this->getMock('PHPCR\Query\QueryInterface');
$session = $this->getMockBuilder('PHPCR\SessionInterface')->getMock();
$workspace = $this->getMockBuilder('PHPCR\WorkspaceInterface')->getMock();
$queryManager = $this->getMockBuilder('PHPCR\Query\QueryManagerInterface')->getMock();
$qomf = $this->getMockBuilder('PHPCR\Query\QOM\QueryObjectModelFactoryInterface')->getMock();
$baseQuery = $this->getMockBuilder('PHPCR\Query\QueryInterface')->getMock();

$session->expects($this->once())
->method('getWorkspace')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function testGenerate()
{
$id = 'moo';
$cm = new RepositoryClassMetadataProxy($id);
$repository = $this->getMock('Doctrine\ODM\PHPCR\Id\RepositoryIdInterface');
$repository = $this->getMockBuilder('Doctrine\ODM\PHPCR\Id\RepositoryIdInterface')->getMock();
$repository
->expects($this->once())
->method('generateId')
Expand All @@ -39,7 +39,7 @@ public function testGenerateNoIdException()
$id = 'moo';
$generator = new RepositoryIdGenerator;
$cm = new ClassMetadataProxy($id);
$repository = $this->getMock('Doctrine\ODM\PHPCR\Id\RepositoryIdInterface');
$repository = $this->getMockBuilder('Doctrine\ODM\PHPCR\Id\RepositoryIdInterface')->getMock();
$repository
->expects($this->once())
->method('generateId')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public function testParentWithPrivatePropertyMapping()
$this->assertTrue(isset($class->identifier));
$this->assertEmpty($class->fieldMappings);

$session = $this->getMock('PHPCR\SessionInterface');
$session = $this->getMockBuilder('PHPCR\SessionInterface')->getMock();
$dm = \Doctrine\ODM\PHPCR\DocumentManager::create($session);
$dm->getConfiguration()->setMetadataDriverImpl($this->loadDriver());
$cmf = new ClassMetadataFactory($dm);
Expand Down Expand Up @@ -756,7 +756,7 @@ public function testStringExtendedMapping()
$this->loadMetadataForClassname($className);

$className = 'Doctrine\Tests\ODM\PHPCR\Mapping\Model\StringExtendedMappingObject';
$session = $this->getMock('PHPCR\SessionInterface');
$session = $this->getMockBuilder('PHPCR\SessionInterface')->getMock();
$dm = \Doctrine\ODM\PHPCR\DocumentManager::create($session);
$dm->getConfiguration()->setMetadataDriverImpl($this->loadDriver());
$cmf = new ClassMetadataFactory($dm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected function getMetadataFor($fqn)

public function setUp()
{
$session = $this->getMock('PHPCR\SessionInterface');
$session = $this->getMockBuilder('PHPCR\SessionInterface')->getMock();
$this->dm = \Doctrine\ODM\PHPCR\DocumentManager::create($session);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function setUp()
$me = $this;
// note: this "factory" seems unnecessary in current jackalope
// implementation
$this->qomfFactory = $this->getMock('Jackalope\FactoryInterface');
$this->qomfFactory = $this->getMockBuilder('Jackalope\FactoryInterface')->getMock();

$this->qomf = new QueryObjectModelFactory($this->qomfFactory);

Expand Down Expand Up @@ -651,7 +651,7 @@ public function testGetQuery()
);

// return something ..
$qom = $me->getMock('PHPCR\Query\QOM\QueryObjectModelInterface');
$qom = $me->getMockBuilder('PHPCR\Query\QOM\QueryObjectModelInterface')->getMock();
return $qom;
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function testCloningQueryBuilderUniqueConverterInstance()
$property = $reflection->getProperty('converter');
$property->setAccessible(true);

$this->node->setConverter($this->getMock('Doctrine\ODM\PHPCR\Query\Builder\ConverterInterface'));
$this->node->setConverter($this->getMockBuilder('Doctrine\ODM\PHPCR\Query\Builder\ConverterInterface')->getMock());

$clone = clone $this->node;

Expand Down
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/ODM/PHPCR/Query/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class QueryTest extends \PHPUnit_Framework_Testcase
{
public function setUp()
{
$this->phpcrQuery = $this->getMock('PHPCR\Query\QueryInterface');
$this->phpcrQuery = $this->getMockBuilder('PHPCR\Query\QueryInterface')->getMock();
$this->dm = $this->getMockBuilder('Doctrine\ODM\PHPCR\DocumentManager')
->disableOriginalConstructor()
->getMock();
$this->arrayCollection = $this->getMock('Doctrine\Common\Collections\ArrayCollection');
$this->arrayCollection = $this->getMockBuilder('Doctrine\Common\Collections\ArrayCollection')->getMock();
$this->query = new Query($this->phpcrQuery, $this->dm);
$this->aliasQuery = new Query($this->phpcrQuery, $this->dm, 'a');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ class DocumentConvertTranslationCommandTest extends \PHPUnit_Framework_TestCase

public function setUp()
{
$this->mockSession = $this->getMock('PHPCR\SessionInterface');
$mockHelper = $this->getMock(
'Symfony\Component\Console\Helper\HelperInterface',
array('getSession', 'setHelperSet', 'getHelperSet', 'getName')
);
$this->mockSession = $this->getMockBuilder('PHPCR\SessionInterface')->getMock();
$mockHelper = $this->getMockBuilder('PHPCR\Util\Console\Helper\PhpcrHelper')
->disableOriginalConstructor()
->getMock();
$mockHelper
->expects($this->once())
->method('getSession')
Expand Down
8 changes: 6 additions & 2 deletions tests/Doctrine/Tests/ODM/PHPCR/UnitOfWorkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ public function setUp()
}

$this->factory = new Factory;
$this->session = $this->getMock('Jackalope\Session', array(), array($this->factory), '', false);
$this->session = $this->getMockBuilder('Jackalope\Session')
->disableOriginalConstructor()
->getMock();

$this->objectManager = $this->getMock('Jackalope\ObjectManager', array(), array($this->factory), '', false);
$this->objectManager = $this->getMockBuilder('Jackalope\ObjectManager')
->disableOriginalConstructor()
->getMock();

$this->type = 'Doctrine\Tests\ODM\PHPCR\UoWUser';
$this->dm = DocumentManager::create($this->session);
Expand Down

0 comments on commit ba31531

Please sign in to comment.