From 7bdbcbc09a30ea36c8b74dae9b1edb659ea25a0e Mon Sep 17 00:00:00 2001 From: Tomas Prochazka Date: Mon, 20 Nov 2017 00:04:47 +0100 Subject: [PATCH] Fixed PHPUnit warnings Changed all uses of getMock() to getMockBuilder(). --- src/test/php/PDepend/AbstractTest.php | 16 +++- ...rShouldOnlyFilterOnLocalPathBug164Test.php | 3 +- src/test/php/PDepend/Input/IteratorTest.php | 9 +- .../Metrics/Analyzer/CouplingAnalyzerTest.php | 7 +- .../Analyzer/CrapIndexAnalyzerTest.php | 3 +- .../CyclomaticComplexityAnalyzerTest.php | 8 +- .../Metrics/Analyzer/HalsteadAnalyzerTest.php | 4 +- .../MaintainabilityIndexAnalyzerTest.php | 4 +- .../PDepend/Metrics/AnalyzerIteratorTest.php | 6 +- src/test/php/PDepend/ParserTest.php | 3 +- .../PDepend/Report/Dependencies/XmlTest.php | 17 +++- .../php/PDepend/Report/Jdepend/ChartTest.php | 14 +-- .../PDepend/Report/Overview/PyramidTest.php | 15 ++- .../php/PDepend/Report/Summary/XmlTest.php | 10 +- .../AST/ASTClassOrInterfaceReferenceTest.php | 5 +- .../Source/AST/ASTClassReferenceTest.php | 5 +- .../php/PDepend/Source/AST/ASTClassTest.php | 76 ++++++--------- .../Source/AST/ASTCompilationUnitTest.php | 12 +-- .../PDepend/Source/AST/ASTFunctionTest.php | 94 +++++++------------ .../PDepend/Source/AST/ASTInterfaceTest.php | 88 +++++++---------- .../php/PDepend/Source/AST/ASTMethodTest.php | 81 ++++++---------- .../php/PDepend/Source/AST/ASTNodeTest.php | 57 +++++------ .../PDepend/Source/AST/ASTParameterTest.php | 7 +- .../Source/AST/ASTParentReferenceTest.php | 14 +-- .../PDepend/Source/AST/ASTPropertyTest.php | 3 +- .../Source/AST/ASTSelfReferenceTest.php | 11 ++- .../Source/AST/ASTStaticReferenceTest.php | 11 ++- .../Source/AST/ASTTraitReferenceTest.php | 8 +- .../CollectionArtifactFilterTest.php | 3 +- .../Source/ASTVisitor/DefaultListenerTest.php | 24 +++-- .../Source/ASTVisitor/DefaultVisitorTest.php | 77 ++++++++++----- .../GlobalBuilderContextTest.php | 21 +++-- .../Source/Language/PHP/PHPBuilderTest.php | 8 +- .../Util/Coverage/CloverReportTest.php | 8 +- 34 files changed, 379 insertions(+), 353 deletions(-) diff --git a/src/test/php/PDepend/AbstractTest.php b/src/test/php/PDepend/AbstractTest.php index 5fc5e1b5f2..3ce0c0e0ea 100644 --- a/src/test/php/PDepend/AbstractTest.php +++ b/src/test/php/PDepend/AbstractTest.php @@ -492,7 +492,12 @@ public static function assertInternalType($expected, $actual, $message = '') */ protected function getMockWithoutConstructor($className) { - return $this->getMock($className, array('__construct'), array(), '', false); + $mock = $this->getMockBuilder($className) + ->setMethods(array('__construct')) + ->disableOriginalConstructor() + ->getMock(); + + return $mock; } /** @@ -539,7 +544,10 @@ protected function createConfigurationFixture() */ protected function createCacheFixture() { - return $this->getMock('\\PDepend\\Util\\Cache\\CacheDriver'); + $cache = $this->getMockBuilder('\\PDepend\\Util\\Cache\\CacheDriver') + ->getMock(); + + return $cache; } /** @@ -588,7 +596,9 @@ protected function createClassFixture($name = null) $class = new ASTClass($name); $class->setCompilationUnit(new ASTCompilationUnit($GLOBALS['argv'][0])); $class->setCache(new MemoryCacheDriver()); - $class->setContext($this->getMock('PDepend\\Source\\Builder\\BuilderContext')); + $context = $this->getMockBuilder('PDepend\\Source\\Builder\\BuilderContext') + ->getMock(); + $class->setContext($context); return $class; } diff --git a/src/test/php/PDepend/Bugs/InputIteratorShouldOnlyFilterOnLocalPathBug164Test.php b/src/test/php/PDepend/Bugs/InputIteratorShouldOnlyFilterOnLocalPathBug164Test.php index ed15af48ab..c3a876d875 100644 --- a/src/test/php/PDepend/Bugs/InputIteratorShouldOnlyFilterOnLocalPathBug164Test.php +++ b/src/test/php/PDepend/Bugs/InputIteratorShouldOnlyFilterOnLocalPathBug164Test.php @@ -63,7 +63,8 @@ class InputIteratorShouldOnlyFilterOnLocalPathBug164Test extends AbstractRegress */ public function testIteratorOnlyPassesLocalPathToFilter() { - $filter = $this->getMock('\\PDepend\\Input\\Filter'); + $filter = $this->getMockBuilder('\\PDepend\\Input\\Filter') + ->getMock(); $filter->expects($this->once()) ->method('accept') ->with($this->equalTo(DIRECTORY_SEPARATOR . basename(__FILE__))); diff --git a/src/test/php/PDepend/Input/IteratorTest.php b/src/test/php/PDepend/Input/IteratorTest.php index af5eb0f5aa..b986e2ac70 100644 --- a/src/test/php/PDepend/Input/IteratorTest.php +++ b/src/test/php/PDepend/Input/IteratorTest.php @@ -88,7 +88,8 @@ public function testIteratorWithMultipleFileExtensions() */ public function testIteratorPassesLocalPathToFilterWhenRootIsPresent() { - $filter = $this->getMock('\\PDepend\\Input\\Filter'); + $filter = $this->getMockBuilder('\\PDepend\\Input\\Filter') + ->getMock(); $filter->expects($this->once()) ->method('accept') ->with($this->equalTo(DIRECTORY_SEPARATOR . basename(__FILE__))); @@ -110,7 +111,8 @@ public function testIteratorPassesAbsolutePathToFilterWhenNoRootIsPresent() { $files = new \ArrayIterator(array(new \SplFileInfo(__FILE__))); - $filter = $this->getMock('\\PDepend\\Input\\Filter'); + $filter = $this->getMockBuilder('\\PDepend\\Input\\Filter') + ->getMock(); $filter->expects($this->once()) ->method('accept') ->with($this->equalTo(__FILE__), $this->equalTo(__FILE__)); @@ -128,7 +130,8 @@ public function testIteratorPassesAbsolutePathToFilterWhenRootNotMatches() { $files = new \ArrayIterator(array(new \SplFileInfo(__FILE__))); - $filter = $this->getMock('\\PDepend\\Input\\Filter'); + $filter = $this->getMockBuilder('\\PDepend\\Input\\Filter') + ->getMock(); $filter->expects($this->once()) ->method('accept') ->with($this->equalTo(__FILE__), $this->equalTo(__FILE__)); diff --git a/src/test/php/PDepend/Metrics/Analyzer/CouplingAnalyzerTest.php b/src/test/php/PDepend/Metrics/Analyzer/CouplingAnalyzerTest.php index d5b29735a2..262a924242 100644 --- a/src/test/php/PDepend/Metrics/Analyzer/CouplingAnalyzerTest.php +++ b/src/test/php/PDepend/Metrics/Analyzer/CouplingAnalyzerTest.php @@ -63,12 +63,13 @@ class CouplingAnalyzerTest extends AbstractMetricsTest */ public function testGetNodeMetricsReturnsAnEmptyArrayByDefault() { + $astArtifact = $this->getMockBuilder('\\PDepend\\Source\\AST\\ASTArtifact') + ->getMock(); + $analyzer = new CouplingAnalyzer(); $this->assertEquals( array(), - $analyzer->getNodeMetrics( - $this->getMock('\\PDepend\\Source\\AST\\ASTArtifact') - ) + $analyzer->getNodeMetrics($astArtifact) ); } diff --git a/src/test/php/PDepend/Metrics/Analyzer/CrapIndexAnalyzerTest.php b/src/test/php/PDepend/Metrics/Analyzer/CrapIndexAnalyzerTest.php index 52f0bcc447..1b59973fe4 100644 --- a/src/test/php/PDepend/Metrics/Analyzer/CrapIndexAnalyzerTest.php +++ b/src/test/php/PDepend/Metrics/Analyzer/CrapIndexAnalyzerTest.php @@ -241,7 +241,8 @@ private function _createCloverReportFile() */ private function _createCyclomaticComplexityAnalyzerMock($ccn = 42) { - $mock = $this->getMock('PDepend\\Metrics\\Analyzer\\CyclomaticComplexityAnalyzer'); + $mock = $this->getMockBuilder('PDepend\\Metrics\\Analyzer\\CyclomaticComplexityAnalyzer') + ->getMock(); $mock->expects($this->any()) ->method('getCCN2') ->will($this->returnValue($ccn)); diff --git a/src/test/php/PDepend/Metrics/Analyzer/CyclomaticComplexityAnalyzerTest.php b/src/test/php/PDepend/Metrics/Analyzer/CyclomaticComplexityAnalyzerTest.php index 6bc06ea00c..b133efb1e9 100644 --- a/src/test/php/PDepend/Metrics/Analyzer/CyclomaticComplexityAnalyzerTest.php +++ b/src/test/php/PDepend/Metrics/Analyzer/CyclomaticComplexityAnalyzerTest.php @@ -83,7 +83,9 @@ protected function setUp() public function testGetCCNReturnsZeroForUnknownNode() { $analyzer = $this->_createAnalyzer(); - $this->assertEquals(0, $analyzer->getCcn($this->getMock('\\PDepend\\Source\\AST\\ASTArtifact'))); + $astArtifact = $this->getMockBuilder('\\PDepend\\Source\\AST\\ASTArtifact') + ->getMock(); + $this->assertEquals(0, $analyzer->getCcn($astArtifact)); } /** @@ -94,7 +96,9 @@ public function testGetCCNReturnsZeroForUnknownNode() public function testGetCCN2ReturnsZeroForUnknownNode() { $analyzer = $this->_createAnalyzer(); - $this->assertEquals(0, $analyzer->getCcn2($this->getMock('\\PDepend\\Source\\AST\\ASTArtifact'))); + $astArtifact = $this->getMockBuilder('\\PDepend\\Source\\AST\\ASTArtifact') + ->getMock(); + $this->assertEquals(0, $analyzer->getCcn2($astArtifact)); } /** diff --git a/src/test/php/PDepend/Metrics/Analyzer/HalsteadAnalyzerTest.php b/src/test/php/PDepend/Metrics/Analyzer/HalsteadAnalyzerTest.php index ec7b881620..09526e878c 100644 --- a/src/test/php/PDepend/Metrics/Analyzer/HalsteadAnalyzerTest.php +++ b/src/test/php/PDepend/Metrics/Analyzer/HalsteadAnalyzerTest.php @@ -83,7 +83,9 @@ protected function setUp() public function testGetNodeMetricsReturnsNothingForUnknownNode() { $analyzer = $this->_createAnalyzer(); - $this->assertEquals(array(), $analyzer->getNodeMetrics($this->getMock('\\PDepend\\Source\\AST\\ASTArtifact'))); + $astArtifact = $this->getMockBuilder('\\PDepend\\Source\\AST\\ASTArtifact') + ->getMock(); + $this->assertEquals(array(), $analyzer->getNodeMetrics($astArtifact)); } /** diff --git a/src/test/php/PDepend/Metrics/Analyzer/MaintainabilityIndexAnalyzerTest.php b/src/test/php/PDepend/Metrics/Analyzer/MaintainabilityIndexAnalyzerTest.php index 6c1c7186d3..3bbfbd791b 100644 --- a/src/test/php/PDepend/Metrics/Analyzer/MaintainabilityIndexAnalyzerTest.php +++ b/src/test/php/PDepend/Metrics/Analyzer/MaintainabilityIndexAnalyzerTest.php @@ -83,7 +83,9 @@ protected function setUp() public function testGetNodeMetricsReturnsNothingForUnknownNode() { $analyzer = $this->_createAnalyzer(); - $this->assertEquals(array(), $analyzer->getNodeMetrics($this->getMock('\\PDepend\\Source\\AST\\ASTArtifact'))); + $astArtifact = $this->getMockBuilder('\\PDepend\\Source\\AST\\ASTArtifact') + ->getMock(); + $this->assertEquals(array(), $analyzer->getNodeMetrics($astArtifact)); } /** diff --git a/src/test/php/PDepend/Metrics/AnalyzerIteratorTest.php b/src/test/php/PDepend/Metrics/AnalyzerIteratorTest.php index 1b186555d7..62d08d35b8 100644 --- a/src/test/php/PDepend/Metrics/AnalyzerIteratorTest.php +++ b/src/test/php/PDepend/Metrics/AnalyzerIteratorTest.php @@ -62,7 +62,8 @@ class AnalyzerIteratorTest extends AbstractTest */ public function testIteratorReturnsEnabledAnalyzerInstances() { - $analyzer = $this->getMock('\\PDepend\\Metrics\\Analyzer'); + $analyzer = $this->getMockBuilder('\\PDepend\\Metrics\\Analyzer') + ->getMock(); $analyzer->expects($this->exactly(2)) ->method('isEnabled') ->will($this->returnValue(true)); @@ -78,7 +79,8 @@ public function testIteratorReturnsEnabledAnalyzerInstances() */ public function testIteratorDoesNotReturnDisabledAnalyzerInstances() { - $analyzer = $this->getMock('\\PDepend\\Metrics\\Analyzer'); + $analyzer = $this->getMockBuilder('\\PDepend\\Metrics\\Analyzer') + ->getMock(); $analyzer->expects($this->at(0)) ->method('isEnabled') ->will($this->returnValue(true)); diff --git a/src/test/php/PDepend/ParserTest.php b/src/test/php/PDepend/ParserTest.php index 7b36082f5d..fde6acb905 100644 --- a/src/test/php/PDepend/ParserTest.php +++ b/src/test/php/PDepend/ParserTest.php @@ -1438,7 +1438,8 @@ public function testParserHandlesStringWithQuestionMarkNotAsTernaryOperator() */ public function testParserStopsProcessingWhenCacheContainsValidResult() { - $builder = $this->getMock('\\PDepend\\Source\\Builder\\Builder'); + $builder = $this->getMockBuilder('\\PDepend\\Source\\Builder\\Builder') + ->getMock(); $tokenizer = new PHPTokenizerInternal(); $tokenizer->setSourceFile(__FILE__); diff --git a/src/test/php/PDepend/Report/Dependencies/XmlTest.php b/src/test/php/PDepend/Report/Dependencies/XmlTest.php index 7d99bcf459..ef2fcf7f3e 100644 --- a/src/test/php/PDepend/Report/Dependencies/XmlTest.php +++ b/src/test/php/PDepend/Report/Dependencies/XmlTest.php @@ -134,8 +134,11 @@ public function testThrowsExceptionForInvalidLogTarget() */ public function testLogMethodReturnsFalseForWrongAnalyzer() { + $analyzer = $this->getMockBuilder('\\PDepend\\Metrics\\AnalyzerNodeAware') + ->getMock(); + $logger = new Xml(); - $actual = $logger->log($this->getMock('\\PDepend\\Metrics\\AnalyzerNodeAware')); + $actual = $logger->log($analyzer); $this->assertFalse($actual); } @@ -147,8 +150,11 @@ public function testLogMethodReturnsFalseForWrongAnalyzer() */ public function testLogMethodReturnsTrueForAnalyzerOfTypeClassDepenendecyAnalyzer() { + $analyzer = $this->getMockBuilder('\\PDepend\\Metrics\\Analyzer\\ClassDependencyAnalyzer') + ->getMock(); + $logger = new Xml(); - $actual = $logger->log($this->getMock('\\PDepend\\Metrics\\Analyzer\\ClassDependencyAnalyzer')); + $actual = $logger->log($analyzer); $this->assertTrue($actual); } @@ -186,7 +192,9 @@ public function testXmlLogWithMetrics() { $this->namespaces = self::parseCodeResourceForTest(); - $type = $this->getMock('\\PDepend\\Source\\AST\\AbstractASTClassOrInterface', array(), array(), '', false); + $type = $this->getMockBuilder('\\PDepend\\Source\\AST\\AbstractASTClassOrInterface') + ->disableOriginalConstructor() + ->getMock(); $type ->expects($this->any()) ->method('getName') @@ -196,7 +204,8 @@ public function testXmlLogWithMetrics() ->method('getNamespaceName') ->will($this->returnValue('namespace')); - $analyzer = $this->getMock('\\PDepend\\Metrics\\Analyzer\\ClassDependencyAnalyzer'); + $analyzer = $this->getMockBuilder('\\PDepend\\Metrics\\Analyzer\\ClassDependencyAnalyzer') + ->getMock(); $analyzer ->expects($this->any()) ->method('getEfferents') diff --git a/src/test/php/PDepend/Report/Jdepend/ChartTest.php b/src/test/php/PDepend/Report/Jdepend/ChartTest.php index 99c2ce5fad..642b14a77e 100644 --- a/src/test/php/PDepend/Report/Jdepend/ChartTest.php +++ b/src/test/php/PDepend/Report/Jdepend/ChartTest.php @@ -226,7 +226,8 @@ public function testCalculateCorrectEllipseSize() { $nodes = $this->_createPackages(true, true); - $analyzer = $this->getMock('\\PDepend\\Metrics\\Analyzer\\DependencyAnalyzer'); + $analyzer = $this->getMockBuilder('\\PDepend\\Metrics\\Analyzer\\DependencyAnalyzer') + ->getMock(); $analyzer->expects($this->atLeastOnce()) ->method('getStats') ->will( @@ -345,12 +346,11 @@ private function _createPackages() */ private function _createPackage($userDefined, $packageName) { - $packageA = $this->getMock( - '\\PDepend\\Source\\AST\\ASTNamespace', - array('isUserDefined'), - array($packageName), - 'package_' . md5(microtime()) - ); + $packageA = $this->getMockBuilder('\\PDepend\\Source\\AST\\ASTNamespace') + ->setMethods(array('isUserDefined')) + ->setConstructorArgs(array($packageName)) + ->setMockClassName('package_' . md5(microtime())) + ->getMock(); $packageA->expects($this->atLeastOnce()) ->method('isUserDefined') ->will($this->returnValue($userDefined)); diff --git a/src/test/php/PDepend/Report/Overview/PyramidTest.php b/src/test/php/PDepend/Report/Overview/PyramidTest.php index 970725e2f7..cf91f67611 100644 --- a/src/test/php/PDepend/Report/Overview/PyramidTest.php +++ b/src/test/php/PDepend/Report/Overview/PyramidTest.php @@ -265,7 +265,8 @@ public function testCollectedAndComputedValuesInOutputSVG() private function createCouplingAnalyzer() { - $mock = $this->getMock('\\PDepend\\Metrics\\Analyzer\\CouplingAnalyzer'); + $mock = $this->getMockBuilder('\\PDepend\\Metrics\\Analyzer\\CouplingAnalyzer') + ->getMock(); $mock->expects($this->any()) ->method('getProjectMetrics') ->will($this->returnValue( @@ -280,7 +281,8 @@ private function createCouplingAnalyzer() private function createComplexityAnalyzer() { - $mock = $this->getMock('\\PDepend\\Metrics\\Analyzer\\CyclomaticComplexityAnalyzer'); + $mock = $this->getMockBuilder('\\PDepend\\Metrics\\Analyzer\\CyclomaticComplexityAnalyzer') + ->getMock(); $mock->expects($this->any()) ->method('getProjectMetrics') ->will($this->returnValue( @@ -294,7 +296,8 @@ private function createComplexityAnalyzer() private function createInheritanceAnalyzer() { - $mock = $this->getMock('\\PDepend\\Metrics\\Analyzer\\InheritanceAnalyzer'); + $mock = $this->getMockBuilder('\\PDepend\\Metrics\\Analyzer\\InheritanceAnalyzer') + ->getMock(); $mock->expects($this->any()) ->method('getProjectMetrics') ->will($this->returnValue( @@ -309,7 +312,8 @@ private function createInheritanceAnalyzer() private function createNodeCountAnalyzer() { - $mock = $this->getMock('\\PDepend\\Metrics\\Analyzer\\NodeCountAnalyzer'); + $mock = $this->getMockBuilder('\\PDepend\\Metrics\\Analyzer\\NodeCountAnalyzer') + ->getMock(); $mock->expects($this->any()) ->method('getProjectMetrics') ->will($this->returnValue( @@ -326,7 +330,8 @@ private function createNodeCountAnalyzer() private function createNodeLocAnalyzer() { - $mock = $this->getMock('\\PDepend\\Metrics\\Analyzer\\NodeLocAnalyzer'); + $mock = $this->getMockBuilder('\\PDepend\\Metrics\\Analyzer\\NodeLocAnalyzer') + ->getMock(); $mock->expects($this->any()) ->method('getProjectMetrics') ->will($this->returnValue( diff --git a/src/test/php/PDepend/Report/Summary/XmlTest.php b/src/test/php/PDepend/Report/Summary/XmlTest.php index 5fe4c1132f..94f0dd9eeb 100644 --- a/src/test/php/PDepend/Report/Summary/XmlTest.php +++ b/src/test/php/PDepend/Report/Summary/XmlTest.php @@ -146,8 +146,11 @@ public function testThrowsExceptionForInvalidLogTarget() */ public function testLogMethodReturnsTrueForAnalyzerOfTypeProjectAware() { + $analyzer = $this->getMockBuilder('\\PDepend\\Metrics\\AnalyzerProjectAware') + ->getMock(); + $logger = new Xml(); - $actual = $logger->log($this->getMock('\\PDepend\\Metrics\\AnalyzerProjectAware')); + $actual = $logger->log($analyzer); $this->assertTrue($actual); } @@ -159,8 +162,11 @@ public function testLogMethodReturnsTrueForAnalyzerOfTypeProjectAware() */ public function testLogMethodReturnsTrueForAnalyzerOfTypeNodeAware() { + $analyzer = $this->getMockBuilder('\\PDepend\\Metrics\\AnalyzerNodeAware') + ->getMock(); + $logger = new Xml(); - $actual = $logger->log($this->getMock('\\PDepend\\Metrics\\AnalyzerNodeAware')); + $actual = $logger->log($analyzer); $this->assertTrue($actual); } diff --git a/src/test/php/PDepend/Source/AST/ASTClassOrInterfaceReferenceTest.php b/src/test/php/PDepend/Source/AST/ASTClassOrInterfaceReferenceTest.php index ca6330f83c..0e3de4aa26 100644 --- a/src/test/php/PDepend/Source/AST/ASTClassOrInterfaceReferenceTest.php +++ b/src/test/php/PDepend/Source/AST/ASTClassOrInterfaceReferenceTest.php @@ -324,6 +324,9 @@ protected function createNodeInstance() */ protected function getBuilderContextMock() { - return $this->getMock('PDepend\\Source\\Builder\\BuilderContext'); + $context = $this->getMockBuilder('PDepend\\Source\\Builder\\BuilderContext') + ->getMock(); + + return $context; } } diff --git a/src/test/php/PDepend/Source/AST/ASTClassReferenceTest.php b/src/test/php/PDepend/Source/AST/ASTClassReferenceTest.php index 68a80859de..f087cec257 100644 --- a/src/test/php/PDepend/Source/AST/ASTClassReferenceTest.php +++ b/src/test/php/PDepend/Source/AST/ASTClassReferenceTest.php @@ -248,6 +248,9 @@ protected function createNodeInstance() */ protected function getBuilderContextMock() { - return $this->getMock('PDepend\\Source\\Builder\\BuilderContext'); + $context = $this->getMockBuilder('PDepend\\Source\\Builder\\BuilderContext') + ->getMock(); + + return $context; } } diff --git a/src/test/php/PDepend/Source/AST/ASTClassTest.php b/src/test/php/PDepend/Source/AST/ASTClassTest.php index 8341ebbca4..efe7d99f44 100644 --- a/src/test/php/PDepend/Source/AST/ASTClassTest.php +++ b/src/test/php/PDepend/Source/AST/ASTClassTest.php @@ -596,22 +596,16 @@ public function testGetDependenciesContainsParentClassAndInterfaces() */ public function testGetFirstChildOfTypeReturnsTheExpectedFirstMatch() { - $node1 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Class_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node1 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Class_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node1->expects($this->once()) ->method('getFirstChildOfType') ->will($this->returnValue(null)); - $node2 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Class_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node2 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Class_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node2->expects($this->never()) ->method('getFirstChildOfType') ->will($this->returnValue(null)); @@ -631,31 +625,22 @@ public function testGetFirstChildOfTypeReturnsTheExpectedFirstMatch() */ public function testGetFirstChildOfTypeReturnsTheExpectedNestedMatch() { - $node1 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Class_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node1 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Class_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node1->expects($this->never()) ->method('getFirstChildOfType'); - $node2 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Class_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node2 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Class_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node2->expects($this->once()) ->method('getFirstChildOfType') ->will($this->returnValue(null)); - $node3 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Class_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node3 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Class_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node3->expects($this->once()) ->method('getFirstChildOfType') ->will($this->returnValue($node1)); @@ -675,22 +660,16 @@ public function testGetFirstChildOfTypeReturnsTheExpectedNestedMatch() */ public function testGetFirstChildOfTypeReturnsTheExpectedNull() { - $node1 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Class_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node1 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Class_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node1->expects($this->once()) ->method('getFirstChildOfType') ->will($this->returnValue(null)); - $node2 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Class_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node2 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Class_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node2->expects($this->once()) ->method('getFirstChildOfType') ->will($this->returnValue(null)); @@ -1641,7 +1620,10 @@ public function testMagicWakeupSetsSourceFileOnChildMethods() $method = new ASTMethod(__FUNCTION__); $class->addMethod($method); - $class->setContext($this->getMock('PDepend\\Source\\Builder\\BuilderContext')); + + $context = $this->getMockBuilder('PDepend\\Source\\Builder\\BuilderContext') + ->getMock(); + $class->setContext($context); $file = new ASTCompilationUnit(__FILE__); $class->setCompilationUnit($file); @@ -1659,7 +1641,8 @@ public function testMagicWakeupCallsRegisterClassOnBuilderContext() { $class = new ASTClass(__CLASS__); - $context = $this->getMock('PDepend\\Source\\Builder\\BuilderContext'); + $context = $this->getMockBuilder('PDepend\\Source\\Builder\\BuilderContext') + ->getMock(); $context->expects($this->once()) ->method('registerClass') ->with($this->isInstanceOf('PDepend\\Source\\AST\\ASTClass')); @@ -1677,7 +1660,10 @@ protected function createItem() $class = new ASTClass(__CLASS__); $class->setCompilationUnit(new ASTCompilationUnit(__FILE__)); $class->setCache(new MemoryCacheDriver()); - $class->setContext($this->getMock('PDepend\\Source\\Builder\\BuilderContext')); + + $context = $this->getMockBuilder('PDepend\\Source\\Builder\\BuilderContext') + ->getMock(); + $class->setContext($context); return $class; } diff --git a/src/test/php/PDepend/Source/AST/ASTCompilationUnitTest.php b/src/test/php/PDepend/Source/AST/ASTCompilationUnitTest.php index b3a4c3d81c..62c2c5f76b 100644 --- a/src/test/php/PDepend/Source/AST/ASTCompilationUnitTest.php +++ b/src/test/php/PDepend/Source/AST/ASTCompilationUnitTest.php @@ -178,7 +178,8 @@ public function testSetTokensDelegatesCallToCacheStoreWithFileId() */ public function testAcceptInvokesVisitFileOnGivenVisitor() { - $visitor = $this->getMock('\\PDepend\\Source\\ASTVisitor\\ASTVisitor'); + $visitor = $this->getMockBuilder('\\PDepend\\Source\\ASTVisitor\\ASTVisitor') + ->getMock(); $visitor->expects($this->once()) ->method('visitCompilationUnit') ->with($this->isInstanceOf('PDepend\\Source\\AST\\ASTCompilationUnit')); @@ -238,11 +239,10 @@ public function testMagicSleepMethodReturnsExpectedSetOfPropertyNames() */ public function testMagicWakeupMethodInvokesSetSourceFileOnChildNodes() { - $node = $this->getMock( - 'PDepend\\Source\\AST\\ASTClass', - array('setCompilationUnit'), - array(__CLASS__) - ); + $node = $this->getMockBuilder('PDepend\\Source\\AST\\ASTClass') + ->setMethods(array('setCompilationUnit')) + ->setConstructorArgs(array(__CLASS__)) + ->getMock(); $node->expects($this->once()) ->method('setCompilationUnit') ->with($this->isInstanceOf('PDepend\\Source\\AST\\ASTCompilationUnit')); diff --git a/src/test/php/PDepend/Source/AST/ASTFunctionTest.php b/src/test/php/PDepend/Source/AST/ASTFunctionTest.php index a30abb044b..1a9d4194a8 100644 --- a/src/test/php/PDepend/Source/AST/ASTFunctionTest.php +++ b/src/test/php/PDepend/Source/AST/ASTFunctionTest.php @@ -202,11 +202,9 @@ public function testNamespaceForJavaStyleArrayNotation(AbstractASTClassOrInterfa */ public function testSetNamespaceNotEstablishesBackReference() { - $namespace = $this->getMock( - 'PDepend\\Source\\AST\\ASTNamespace', - array(), - array(__FUNCTION__) - ); + $namespace = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNamespace') + ->setConstructorArgs(array(__FUNCTION__)) + ->getMock(); $namespace->expects($this->never()) ->method('addFunction'); @@ -375,22 +373,16 @@ public function testGetTokensReturnsArrayEvenWhenCacheReturnsNull() */ public function testGetFirstChildOfTypeReturnsTheExpectedFirstMatch() { - $node1 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Class_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node1 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Class_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node1->expects($this->once()) ->method('getFirstChildOfType') ->will($this->returnValue(null)); - $node2 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Class_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node2 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Class_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node2->expects($this->never()) ->method('getFirstChildOfType') ->will($this->returnValue(null)); @@ -410,31 +402,22 @@ public function testGetFirstChildOfTypeReturnsTheExpectedFirstMatch() */ public function testGetFirstChildOfTypeReturnsTheExpectedNestedMatch() { - $node1 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Class_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node1 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Class_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node1->expects($this->never()) ->method('getFirstChildOfType'); - $node2 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Class_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node2 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Class_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node2->expects($this->once()) ->method('getFirstChildOfType') ->will($this->returnValue(null)); - $node3 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Class_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node3 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Class_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node3->expects($this->once()) ->method('getFirstChildOfType') ->will($this->returnValue($node1)); @@ -454,22 +437,16 @@ public function testGetFirstChildOfTypeReturnsTheExpectedNestedMatch() */ public function testGetFirstChildOfTypeReturnsTheExpectedNull() { - $node1 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Class_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node1 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Class_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node1->expects($this->once()) ->method('getFirstChildOfType') ->will($this->returnValue(null)); - $node2 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Class_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node2 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Class_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node2->expects($this->once()) ->method('getFirstChildOfType') ->will($this->returnValue(null)); @@ -489,22 +466,16 @@ public function testGetFirstChildOfTypeReturnsTheExpectedNull() */ public function testFindChildrenOfTypeReturnsExpectedResult() { - $node1 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Class_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node1 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Class_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node1->expects($this->once()) ->method('findChildrenOfType') ->will($this->returnValue(array())); - $node2 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Class_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node2 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Class_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node2->expects($this->once()) ->method('findChildrenOfType') ->will($this->returnValue(array())); @@ -689,7 +660,10 @@ protected function createItem() { $function = new ASTFunction(__FUNCTION__); $function->setCompilationUnit(new ASTCompilationUnit(__FILE__)); - $function->setContext($this->getMock('PDepend\\Source\\Builder\\BuilderContext')); + + $context = $this->getMockBuilder('PDepend\\Source\\Builder\\BuilderContext') + ->getMock(); + $function->setContext($context); return $function; } diff --git a/src/test/php/PDepend/Source/AST/ASTInterfaceTest.php b/src/test/php/PDepend/Source/AST/ASTInterfaceTest.php index af0a6290f7..0730065cec 100644 --- a/src/test/php/PDepend/Source/AST/ASTInterfaceTest.php +++ b/src/test/php/PDepend/Source/AST/ASTInterfaceTest.php @@ -66,22 +66,16 @@ class ASTInterfaceTest extends AbstractASTArtifactTest */ public function testGetFirstChildOfTypeReturnsTheExpectedFirstMatch() { - $node1 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Mock_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node1 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Mock_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node1->expects($this->once()) ->method('getFirstChildOfType') ->will($this->returnValue(null)); - $node2 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Mock_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node2 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Mock_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node2->expects($this->never()) ->method('getFirstChildOfType') ->will($this->returnValue(null)); @@ -101,31 +95,22 @@ public function testGetFirstChildOfTypeReturnsTheExpectedFirstMatch() */ public function testGetFirstChildOfTypeReturnsTheExpectedNestedMatch() { - $node1 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Mock_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node1 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Mock_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node1->expects($this->never()) ->method('getFirstChildOfType'); - $node2 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Mock_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node2 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Mock_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node2->expects($this->once()) ->method('getFirstChildOfType') ->will($this->returnValue(null)); - $node3 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Mock_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node3 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Mock_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node3->expects($this->once()) ->method('getFirstChildOfType') ->will($this->returnValue($node1)); @@ -145,22 +130,16 @@ public function testGetFirstChildOfTypeReturnsTheExpectedNestedMatch() */ public function testGetFirstChildOfTypeReturnsTheExpectedNull() { - $node1 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Mock_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node1 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Mock_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node1->expects($this->once()) ->method('getFirstChildOfType') ->will($this->returnValue(null)); - $node2 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Mock_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node2 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Mock_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node2->expects($this->once()) ->method('getFirstChildOfType') ->will($this->returnValue(null)); @@ -396,15 +375,11 @@ public function testFindChildrenOfTypeFindsASTNodeInMethodDeclarations() public function testInterfaceThrowsExpectedExceptionOnSetParentClassReference() { $interface = $this->createItem(); - $interface->setParentClassReference( - $this->getMock( - '\\PDepend\\Source\\AST\\ASTClassReference', - array(), - array(), - '', - false - ) - ); + + $reference = $this->getMockBuilder('\\PDepend\\Source\\AST\\ASTClassReference') + ->disableOriginalConstructor() + ->getMock(); + $interface->setParentClassReference($reference); } /** @@ -919,7 +894,8 @@ public function testMagicWakeupCallsRegisterInterfaceOnBuilderContext() { $interface = $this->createItem(); - $context = $this->getMock('PDepend\\Source\\Builder\\BuilderContext'); + $context = $this->getMockBuilder('PDepend\\Source\\Builder\\BuilderContext') + ->getMock(); $context->expects($this->once()) ->method('registerInterface') ->with($this->isInstanceOf('PDepend\\Source\\AST\\ASTInterface')); @@ -934,7 +910,8 @@ public function testMagicWakeupCallsRegisterInterfaceOnBuilderContext() */ public function testAcceptInvokesVisitInterfaceOnGivenVisitor() { - $visitor = $this->getMock('\\PDepend\\Source\\ASTVisitor\\ASTVisitor'); + $visitor = $this->getMockBuilder('\\PDepend\\Source\\ASTVisitor\\ASTVisitor') + ->getMock(); $visitor->expects($this->once()) ->method('visitInterface') ->with($this->isInstanceOf('PDepend\\Source\\AST\\ASTInterface')); @@ -953,7 +930,10 @@ protected function createItem() $interface = new ASTInterface(__CLASS__); $interface->setCompilationUnit(new ASTCompilationUnit(__FILE__)); $interface->setCache(new MemoryCacheDriver()); - $interface->setContext($this->getMock('PDepend\\Source\\Builder\\BuilderContext')); + + $context = $this->getMockBuilder('PDepend\\Source\\Builder\\BuilderContext') + ->getMock(); + $interface->setContext($context); return $interface; } diff --git a/src/test/php/PDepend/Source/AST/ASTMethodTest.php b/src/test/php/PDepend/Source/AST/ASTMethodTest.php index afb6ccc7d1..774a91e25e 100644 --- a/src/test/php/PDepend/Source/AST/ASTMethodTest.php +++ b/src/test/php/PDepend/Source/AST/ASTMethodTest.php @@ -581,22 +581,16 @@ public function testIsPublicByDefaultReturnsFalse() */ public function testGetFirstChildOfTypeReturnsTheExpectedFirstMatch() { - $node1 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Class_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node1 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Class_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node1->expects($this->once()) ->method('getFirstChildOfType') ->will($this->returnValue(null)); - $node2 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Class_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node2 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Class_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node2->expects($this->never()) ->method('getFirstChildOfType') ->will($this->returnValue(null)); @@ -616,31 +610,22 @@ public function testGetFirstChildOfTypeReturnsTheExpectedFirstMatch() */ public function testGetFirstChildOfTypeReturnsTheExpectedNestedMatch() { - $node1 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Class_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node1 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Class_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node1->expects($this->never()) ->method('getFirstChildOfType'); - $node2 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Class_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node2 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Class_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node2->expects($this->once()) ->method('getFirstChildOfType') ->will($this->returnValue(null)); - $node3 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Class_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node3 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Class_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node3->expects($this->once()) ->method('getFirstChildOfType') ->will($this->returnValue($node1)); @@ -660,22 +645,16 @@ public function testGetFirstChildOfTypeReturnsTheExpectedNestedMatch() */ public function testGetFirstChildOfTypeReturnsTheExpectedNull() { - $node1 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Class_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node1 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Class_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node1->expects($this->once()) ->method('getFirstChildOfType') ->will($this->returnValue(null)); - $node2 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Class_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node2 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Class_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node2->expects($this->once()) ->method('getFirstChildOfType') ->will($this->returnValue(null)); @@ -697,22 +676,16 @@ public function testGetFirstChildOfTypeReturnsTheExpectedNull() */ public function testFindChildrenOfTypeReturnsExpectedResult() { - $node1 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Class_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node1 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Class_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node1->expects($this->once()) ->method('findChildrenOfType') ->will($this->returnValue(array())); - $node2 = $this->getMock( - 'PDepend\\Source\\AST\\ASTNode', - array(), - array(), - 'Class_' . __FUNCTION__ . '_' . md5(microtime()) - ); + $node2 = $this->getMockBuilder('PDepend\\Source\\AST\\ASTNode') + ->setMockClassName('Class_' . __FUNCTION__ . '_' . md5(microtime())) + ->getMock(); $node2->expects($this->once()) ->method('findChildrenOfType') ->will($this->returnValue(array())); diff --git a/src/test/php/PDepend/Source/AST/ASTNodeTest.php b/src/test/php/PDepend/Source/AST/ASTNodeTest.php index 7d9b64853c..a0ea1c1b98 100644 --- a/src/test/php/PDepend/Source/AST/ASTNodeTest.php +++ b/src/test/php/PDepend/Source/AST/ASTNodeTest.php @@ -604,8 +604,10 @@ private function getNodeMock() */ public function testPrependChildAddsChildAtFirstPosition() { - $child1 = $this->getMock('PDepend\\Source\\AST\\AbstractASTNode'); - $child2 = $this->getMock('PDepend\\Source\\AST\\AbstractASTNode'); + $child1 = $this->getMockBuilder('PDepend\\Source\\AST\\AbstractASTNode') + ->getMock(); + $child2 = $this->getMockBuilder('PDepend\\Source\\AST\\AbstractASTNode') + ->getMock(); $parent = $this->createNodeInstance(); $parent->prependChild($child2); @@ -623,7 +625,8 @@ public function testAcceptInvokesVisitOnGivenVisitor() { $methodName = 'visit' . substr(get_class($this), 22, -4); - $visitor = $this->getMock('\\PDepend\\Source\ASTVisitor\\ASTVisitor'); + $visitor = $this->getMockBuilder('\\PDepend\\Source\ASTVisitor\\ASTVisitor') + ->getMock(); $visitor->expects($this->once()) ->method('__call') ->with($this->equalTo($methodName)); @@ -641,7 +644,8 @@ public function testAcceptReturnsReturnValueOfVisitMethod() { $methodName = 'visit' . substr(get_class($this), 22, -4); - $visitor = $this->getMock('\\PDepend\\Source\ASTVisitor\\ASTVisitor'); + $visitor = $this->getMockBuilder('\\PDepend\\Source\ASTVisitor\\ASTVisitor') + ->getMock(); $visitor->expects($this->once()) ->method('__call') ->with($this->equalTo($methodName)) @@ -658,12 +662,9 @@ public function testAcceptReturnsReturnValueOfVisitMethod() */ public function testGetFirstChildOfTypeReturnsTheExpectedFirstMatch() { - $node2 = $this->getMock( - '\PDepend\Source\AST\AbstractASTNode', - array(), - array(), - 'PDepend_Source_AST_ASTNode_' . md5(microtime()) - ); + $node2 = $this->getMockBuilder('\PDepend\Source\AST\AbstractASTNode') + ->setMockClassName('PDepend_Source_AST_ASTNode_' . md5(microtime())) + ->getMock(); $node2->expects($this->never()) ->method('getFirstChildOfType') ->will($this->returnValue(null)); @@ -682,21 +683,15 @@ public function testGetFirstChildOfTypeReturnsTheExpectedFirstMatch() */ public function testGetFirstChildOfTypeReturnsTheExpectedNestedMatch() { - $node1 = $this->getMock( - '\PDepend\Source\AST\AbstractASTNode', - array(), - array(), - 'PDepend_Source_AST_ASTNode_' . md5(microtime()) - ); + $node1 = $this->getMockBuilder('\PDepend\Source\AST\AbstractASTNode') + ->setMockClassName('PDepend_Source_AST_ASTNode_' . md5(microtime())) + ->getMock(); $node1->expects($this->never()) ->method('getFirstChildOfType'); - $node3 = $this->getMock( - '\PDepend\Source\AST\AbstractASTNode', - array(), - array(), - 'PDepend_Source_AST_ASTNode_' . md5(microtime()) - ); + $node3 = $this->getMockBuilder('\PDepend\Source\AST\AbstractASTNode') + ->setMockClassName('PDepend_Source_AST_ASTNode_' . md5(microtime())) + ->getMock(); $node3->expects($this->once()) ->method('getFirstChildOfType') ->will($this->returnValue($node1)); @@ -717,12 +712,9 @@ public function testGetFirstChildOfTypeReturnsTheExpectedNull() { $name = 'PDepend_Source_AST_ASTNode_' . md5(microtime()); - $node2 = $this->getMock( - '\PDepend\Source\AST\AbstractASTNode', - array(), - array(), - $name - ); + $node2 = $this->getMockBuilder('\PDepend\Source\AST\AbstractASTNode') + ->setMockClassName($name) + ->getMock(); $node2->expects($this->once()) ->method('getFirstChildOfType') ->will($this->returnValue(null)); @@ -742,12 +734,9 @@ public function testFindChildrenOfTypeReturnsExpectedResult() { $name = 'PDepend_Source_AST_ASTNode_' . md5(microtime()); - $node2 = $this->getMock( - '\PDepend\Source\AST\AbstractASTNode', - array(), - array(), - $name - ); + $node2 = $this->getMockBuilder('\PDepend\Source\AST\AbstractASTNode') + ->setMockClassName($name) + ->getMock(); $node2->expects($this->once()) ->method('findChildrenOfType') ->will($this->returnValue(array())); diff --git a/src/test/php/PDepend/Source/AST/ASTParameterTest.php b/src/test/php/PDepend/Source/AST/ASTParameterTest.php index 4c9135a81e..ae8774b058 100644 --- a/src/test/php/PDepend/Source/AST/ASTParameterTest.php +++ b/src/test/php/PDepend/Source/AST/ASTParameterTest.php @@ -248,12 +248,15 @@ private function _getFirstMethodInClass() */ public function testAcceptInvokesVisitParameterOnSuppliedVisitor() { - $visitor = $this->getMock('\\PDepend\\Source\\ASTVisitor\\ASTVisitor'); + $visitor = $this->getMockBuilder('\\PDepend\\Source\\ASTVisitor\\ASTVisitor') + ->getMock(); $visitor->expects($this->once()) ->method('visitParameter') ->with($this->isInstanceOf('\\PDepend\\Source\\AST\\ASTParameter')); - $parameter = new ASTParameter($this->getMock('PDepend\\Source\\AST\\ASTFormalParameter')); + $formalParameter = $this->getMockBuilder('PDepend\\Source\\AST\\ASTFormalParameter') + ->getMock(); + $parameter = new ASTParameter($formalParameter); $parameter->accept($visitor); } } diff --git a/src/test/php/PDepend/Source/AST/ASTParentReferenceTest.php b/src/test/php/PDepend/Source/AST/ASTParentReferenceTest.php index 996da337c2..8370e603e1 100644 --- a/src/test/php/PDepend/Source/AST/ASTParentReferenceTest.php +++ b/src/test/php/PDepend/Source/AST/ASTParentReferenceTest.php @@ -192,15 +192,11 @@ public function testParentReferenceHasExpectedEndColumn() */ protected function createNodeInstance() { - return new \PDepend\Source\AST\ASTParentReference( - $this->referenceMock = $this->getMock( - '\PDepend\Source\AST\ASTClassOrInterfaceReference', - array(), - array(null, __CLASS__), - '', - false - ) - ); + $this->referenceMock = $this->getMockBuilder('\PDepend\Source\AST\ASTClassOrInterfaceReference') + ->disableOriginalConstructor() + ->getMock(); + + return new \PDepend\Source\AST\ASTParentReference($this->referenceMock); } /** diff --git a/src/test/php/PDepend/Source/AST/ASTPropertyTest.php b/src/test/php/PDepend/Source/AST/ASTPropertyTest.php index b05597cac5..a290f505f1 100644 --- a/src/test/php/PDepend/Source/AST/ASTPropertyTest.php +++ b/src/test/php/PDepend/Source/AST/ASTPropertyTest.php @@ -472,7 +472,8 @@ public function testIsStaticReturnsTrueForStaticProperty() */ public function testAcceptCallsVisitorMethodVisitProperty() { - $visitor = $this->getMock('\\PDepend\\Source\\ASTVisitor\\ASTVisitor'); + $visitor = $this->getMockBuilder('\\PDepend\\Source\\ASTVisitor\\ASTVisitor') + ->getMock(); $visitor->expects($this->once()) ->method('visitProperty'); diff --git a/src/test/php/PDepend/Source/AST/ASTSelfReferenceTest.php b/src/test/php/PDepend/Source/AST/ASTSelfReferenceTest.php index 853698c6f1..6562ce914f 100644 --- a/src/test/php/PDepend/Source/AST/ASTSelfReferenceTest.php +++ b/src/test/php/PDepend/Source/AST/ASTSelfReferenceTest.php @@ -65,7 +65,8 @@ class ASTSelfReferenceTest extends ASTNodeTest public function testGetTypeReturnsInjectedConstructorTargetArgument() { $target = $this->getMockForAbstractClass('\\PDepend\\Source\\AST\\AbstractASTClassOrInterface', array(__CLASS__)); - $context = $this->getMock('PDepend\\Source\\Builder\\BuilderContext'); + $context = $this->getMockBuilder('PDepend\\Source\\Builder\\BuilderContext') + ->getMock(); $reference = new \PDepend\Source\AST\ASTSelfReference($context, $target); $this->assertSame($target, $reference->getType()); @@ -80,7 +81,8 @@ public function testGetTypeInvokesBuilderContextWhenTypeInstanceIsNull() { $target = $this->getMockForAbstractClass('\\PDepend\\Source\\AST\\AbstractASTClassOrInterface', array(__CLASS__)); - $builder = $this->getMock('\\PDepend\\Source\\Builder\\Builder'); + $builder = $this->getMockBuilder('\\PDepend\\Source\\Builder\\Builder') + ->getMock(); $builder->expects($this->once()) ->method('getClassOrInterface'); @@ -218,8 +220,11 @@ public function testSelfReferenceHasExpectedEndColumn($reference) */ protected function createNodeInstance() { + $context = $this->getMockBuilder('PDepend\\Source\\Builder\\BuilderContext') + ->getMock(); + return new \PDepend\Source\AST\ASTSelfReference( - $this->getMock('PDepend\\Source\\Builder\\BuilderContext'), + $context, $this->getMockForAbstractClass('\\PDepend\\Source\\AST\\AbstractASTClassOrInterface', array(__CLASS__)) ); } diff --git a/src/test/php/PDepend/Source/AST/ASTStaticReferenceTest.php b/src/test/php/PDepend/Source/AST/ASTStaticReferenceTest.php index cdc3a1c1dd..f51db70758 100644 --- a/src/test/php/PDepend/Source/AST/ASTStaticReferenceTest.php +++ b/src/test/php/PDepend/Source/AST/ASTStaticReferenceTest.php @@ -67,7 +67,8 @@ public function testGetTypeReturnsInjectedConstructorTargetArgument() '\\PDepend\\Source\\AST\\AbstractASTClassOrInterface', array(__CLASS__) ); - $context = $this->getMock('\\PDepend\\Source\\Builder\\BuilderContext'); + $context = $this->getMockBuilder('\\PDepend\\Source\\Builder\\BuilderContext') + ->getMock(); $reference = new \PDepend\Source\AST\ASTStaticReference($context, $target); $this->assertSame($target, $reference->getType()); @@ -85,7 +86,8 @@ public function testGetTypeInvokesBuilderContextWhenTypeInstanceIsNull() array(__CLASS__) ); - $builder = $this->getMock('\\PDepend\\Source\\Builder\\Builder'); + $builder = $this->getMockBuilder('\\PDepend\\Source\\Builder\\Builder') + ->getMock(); $builder->expects($this->once()) ->method('getClassOrInterface'); @@ -231,8 +233,11 @@ public function testStaticReferenceHasExpectedEndColumn($reference) */ protected function createNodeInstance() { + $context = $this->getMockBuilder('\\PDepend\\Source\\Builder\\BuilderContext') + ->getMock(); + return new \PDepend\Source\AST\ASTStaticReference( - $this->getMock('\\PDepend\\Source\\Builder\\BuilderContext'), + $context, $this->getMockForAbstractClass( '\\PDepend\\Source\\AST\\AbstractASTClassOrInterface', array(__CLASS__) diff --git a/src/test/php/PDepend/Source/AST/ASTTraitReferenceTest.php b/src/test/php/PDepend/Source/AST/ASTTraitReferenceTest.php index 217b560cb2..42216ddaf9 100644 --- a/src/test/php/PDepend/Source/AST/ASTTraitReferenceTest.php +++ b/src/test/php/PDepend/Source/AST/ASTTraitReferenceTest.php @@ -65,7 +65,8 @@ class ASTTraitReferenceTest extends ASTNodeTest */ public function testGetTraitDelegatesToContextGetTraitMethod() { - $context = $this->getMock('PDepend\\Source\\Builder\\BuilderContext'); + $context = $this->getMockBuilder('PDepend\\Source\\Builder\\BuilderContext') + ->getMock(); $context->expects($this->once()) ->method('getTrait') ->with($this->equalTo(__CLASS__)); @@ -173,6 +174,9 @@ protected function createNodeInstance() */ protected function getBuilderContextMock() { - return $this->getMock('PDepend\\Source\\Builder\\BuilderContext'); + $context = $this->getMockBuilder('PDepend\\Source\\Builder\\BuilderContext') + ->getMock(); + + return $context; } } diff --git a/src/test/php/PDepend/Source/AST/ArtifactFilter/CollectionArtifactFilterTest.php b/src/test/php/PDepend/Source/AST/ArtifactFilter/CollectionArtifactFilterTest.php index cf59613797..d256ecf39d 100644 --- a/src/test/php/PDepend/Source/AST/ArtifactFilter/CollectionArtifactFilterTest.php +++ b/src/test/php/PDepend/Source/AST/ArtifactFilter/CollectionArtifactFilterTest.php @@ -79,7 +79,8 @@ public function testAcceptsCallsNestedFilterWhenSet() { $class = new ASTClass(__CLASS__); - $filter = $this->getMock('\\PDepend\\Source\\AST\\ASTArtifactList\\ArtifactFilter'); + $filter = $this->getMockBuilder('\\PDepend\\Source\\AST\\ASTArtifactList\\ArtifactFilter') + ->getMock(); $filter->expects($this->once()) ->method('accept') ->with($this->equalTo($class)); diff --git a/src/test/php/PDepend/Source/ASTVisitor/DefaultListenerTest.php b/src/test/php/PDepend/Source/ASTVisitor/DefaultListenerTest.php index c9c81b874c..bfc2d9a432 100644 --- a/src/test/php/PDepend/Source/ASTVisitor/DefaultListenerTest.php +++ b/src/test/php/PDepend/Source/ASTVisitor/DefaultListenerTest.php @@ -220,11 +220,15 @@ public function testListenerCallsStartNodeEndNodeForMethod() */ public function testListenerCallsStartVisitNodeForPassedParameterInstance() { - $listener = $this->getMock('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitListener', array('startVisitNode')); + $listener = $this->getMockBuilder('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitListener') + ->setMethods(array('startVisitNode')) + ->getMock(); $listener->expects($this->once()) ->method('startVisitNode'); - $parameter = $this->getMock('PDepend\\Source\\AST\\ASTParameter', array(), array(null), '', false); + $parameter = $this->getMockBuilder('PDepend\\Source\\AST\\ASTParameter') + ->disableOriginalConstructor() + ->getMock(); $listener->startVisitParameter($parameter); } @@ -235,11 +239,15 @@ public function testListenerCallsStartVisitNodeForPassedParameterInstance() */ public function testListenerCallsEndVisitNodeForPassedParameterInstance() { - $listener = $this->getMock('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitListener', array('endVisitNode')); + $listener = $this->getMockBuilder('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitListener') + ->setMethods(array('endVisitNode')) + ->getMock(); $listener->expects($this->once()) ->method('endVisitNode'); - $parameter = $this->getMock('PDepend\\Source\\AST\\ASTParameter', array(), array(null), '', false); + $parameter = $this->getMockBuilder('PDepend\\Source\\AST\\ASTParameter') + ->disableOriginalConstructor() + ->getMock(); $listener->endVisitParameter($parameter); } @@ -251,7 +259,9 @@ public function testListenerCallsEndVisitNodeForPassedParameterInstance() */ public function testListenerInvokesStartVisitNotForTrait() { - $listener = $this->getMock('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitListener', array('startVisitNode')); + $listener = $this->getMockBuilder('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitListener') + ->setMethods(array('startVisitNode')) + ->getMock(); $listener->expects($this->once()) ->method('startVisitNode'); @@ -266,7 +276,9 @@ public function testListenerInvokesStartVisitNotForTrait() */ public function testListenerInvokesEndVisitNotForTrait() { - $listener = $this->getMock('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitListener', array('endVisitNode')); + $listener = $this->getMockBuilder('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitListener') + ->setMethods(array('endVisitNode')) + ->getMock(); $listener->expects($this->once()) ->method('endVisitNode'); diff --git a/src/test/php/PDepend/Source/ASTVisitor/DefaultVisitorTest.php b/src/test/php/PDepend/Source/ASTVisitor/DefaultVisitorTest.php index 116c580bdd..4484c961bc 100644 --- a/src/test/php/PDepend/Source/ASTVisitor/DefaultVisitorTest.php +++ b/src/test/php/PDepend/Source/ASTVisitor/DefaultVisitorTest.php @@ -104,7 +104,9 @@ public function testVisitorVisitsFunctionParameter() { $namespaces = $this->parseCodeResourceForTest(); - $visitor = $this->getMock('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitor', array('visitParameter')); + $visitor = $this->getMockBuilder('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitor') + ->setMethods(array('visitParameter')) + ->getMock(); $visitor->expects($this->exactly(2)) ->method('visitParameter'); @@ -120,7 +122,9 @@ public function testVisitorVisitsMethodParameter() { $namespaces = $this->parseCodeResourceForTest(); - $visitor = $this->getMock('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitor', array('visitParameter')); + $visitor = $this->getMockBuilder('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitor') + ->setMethods(array('visitParameter')) + ->getMock(); $visitor->expects($this->exactly(3)) ->method('visitParameter'); @@ -136,11 +140,14 @@ public function testVisitorInvokesStartVisitParameterOnListener() { $namespaces = $this->parseCodeResourceForTest(); - $listener = $this->getMock('\\PDepend\\Source\\ASTVisitor\\ASTVisitListener'); + $listener = $this->getMockBuilder('\\PDepend\\Source\\ASTVisitor\\ASTVisitListener') + ->getMock(); $listener->expects($this->exactly(2)) ->method('startVisitParameter'); - $visitor = $this->getMock('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitor', array('getVisitListeners')); + $visitor = $this->getMockBuilder('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitor') + ->setMethods(array('getVisitListeners')) + ->getMock(); $visitor->addVisitListener($listener); $visitor->visitNamespace($namespaces[0]); @@ -155,11 +162,14 @@ public function testVisitorInvokesEndVisitParameterOnListener() { $namespaces = $this->parseCodeResourceForTest(); - $listener = $this->getMock('\\PDepend\\Source\\ASTVisitor\\ASTVisitListener'); + $listener = $this->getMockBuilder('\\PDepend\\Source\\ASTVisitor\\ASTVisitListener') + ->getMock(); $listener->expects($this->exactly(3)) ->method('endVisitParameter'); - $visitor = $this->getMock('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitor', array('getVisitListeners')); + $visitor = $this->getMockBuilder('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitor') + ->setMethods(array('getVisitListeners')) + ->getMock(); $visitor->addVisitListener($listener); $visitor->visitNamespace($namespaces[0]); @@ -174,11 +184,14 @@ public function testVisitorInvokesStartVisitInterfaceOnListener() { $namespaces = $this->parseCodeResourceForTest(); - $listener = $this->getMock('\\PDepend\\Source\\ASTVisitor\\ASTVisitListener'); + $listener = $this->getMockBuilder('\\PDepend\\Source\\ASTVisitor\\ASTVisitListener') + ->getMock(); $listener->expects($this->once()) ->method('startVisitInterface'); - $visitor = $this->getMock('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitor', array('getVisitListeners')); + $visitor = $this->getMockBuilder('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitor') + ->setMethods(array('getVisitListeners')) + ->getMock(); $visitor->addVisitListener($listener); $visitor->visitNamespace($namespaces[0]); @@ -193,11 +206,14 @@ public function testVisitorInvokesEndVisitInterfaceOnListener() { $namespaces = $this->parseCodeResourceForTest(); - $listener = $this->getMock('\\PDepend\\Source\\ASTVisitor\\ASTVisitListener'); + $listener = $this->getMockBuilder('\\PDepend\\Source\\ASTVisitor\\ASTVisitListener') + ->getMock(); $listener->expects($this->once()) ->method('endVisitInterface'); - $visitor = $this->getMock('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitor', array('getVisitListeners')); + $visitor = $this->getMockBuilder('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitor') + ->setMethods(array('getVisitListeners')) + ->getMock(); $visitor->addVisitListener($listener); $visitor->visitNamespace($namespaces[0]); @@ -212,11 +228,14 @@ public function testVisitorInvokesStartVisitPropertyOnListener() { $namespaces = $this->parseCodeResourceForTest(); - $listener = $this->getMock('\\PDepend\\Source\\ASTVisitor\\ASTVisitListener'); + $listener = $this->getMockBuilder('\\PDepend\\Source\\ASTVisitor\\ASTVisitListener') + ->getMock(); $listener->expects($this->once()) ->method('startVisitProperty'); - $visitor = $this->getMock('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitor', array('getVisitListeners')); + $visitor = $this->getMockBuilder('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitor') + ->setMethods(array('getVisitListeners')) + ->getMock(); $visitor->addVisitListener($listener); $visitor->visitNamespace($namespaces[0]); @@ -231,11 +250,14 @@ public function testVisitorInvokesEndVisitPropertyOnListener() { $namespaces = $this->parseCodeResourceForTest(); - $listener = $this->getMock('\\PDepend\\Source\\ASTVisitor\\ASTVisitListener'); + $listener = $this->getMockBuilder('\\PDepend\\Source\\ASTVisitor\\ASTVisitListener') + ->getMock(); $listener->expects($this->once()) ->method('endVisitProperty'); - $visitor = $this->getMock('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitor', array('getVisitListeners')); + $visitor = $this->getMockBuilder('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitor') + ->setMethods(array('getVisitListeners')) + ->getMock(); $visitor->addVisitListener($listener); $visitor->visitNamespace($namespaces[0]); @@ -255,7 +277,9 @@ public function testVisitorVisitsTrait() $namespace->addType(new ASTTrait('MyTraitTwo')) ->setCompilationUnit(new ASTCompilationUnit(__FILE__)); - $visitor = $this->getMock('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitor', array('visitTrait')); + $visitor = $this->getMockBuilder('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitor') + ->setMethods(array('visitTrait')) + ->getMock(); $visitor->expects($this->exactly(2)) ->method('visitTrait'); @@ -275,7 +299,9 @@ public function testVisitorInvokesAcceptOnTraitMethods() $trait->addMethod($method0 = new ASTMethod('m0')); $trait->addMethod($method1 = new ASTMethod('m1')); - $visitor = $this->getMock('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitor', array('visitMethod')); + $visitor = $this->getMockBuilder('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitor') + ->setMethods(array('visitMethod')) + ->getMock(); $visitor->expects($this->at(0)) ->method('visitMethod') ->with($this->equalTo($method0)); @@ -300,11 +326,14 @@ public function testVisitorInvokesStartTraitOnListener() $namespace = new ASTNamespace('MyPackage'); $namespace->addType($trait); - $listener = $this->getMock('\\PDepend\\Source\\ASTVisitor\\ASTVisitListener'); + $listener = $this->getMockBuilder('\\PDepend\\Source\\ASTVisitor\\ASTVisitListener') + ->getMock(); $listener->expects($this->once()) ->method('startVisitTrait'); - $visitor = $this->getMock('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitor', array('getVisitListeners')); + $visitor = $this->getMockBuilder('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitor') + ->setMethods(array('getVisitListeners')) + ->getMock(); $visitor->addVisitListener($listener); $visitor->visitNamespace($namespace); @@ -324,11 +353,14 @@ public function testVisitorInvokesEndTraitOnListener() $namespace = new ASTNamespace('MyPackage'); $namespace->addType($trait); - $listener = $this->getMock('\\PDepend\\Source\\ASTVisitor\\ASTVisitListener'); + $listener = $this->getMockBuilder('\\PDepend\\Source\\ASTVisitor\\ASTVisitListener') + ->getMock(); $listener->expects($this->once()) ->method('endVisitTrait'); - $visitor = $this->getMock('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitor', array('getVisitListeners')); + $visitor = $this->getMockBuilder('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitor') + ->setMethods(array('getVisitListeners')) + ->getMock(); $visitor->addVisitListener($listener); $visitor->visitNamespace($namespace); @@ -353,7 +385,10 @@ public function testGetVisitListenersReturnsIterator() public function testGetVisitListenersContainsAddedListener() { $visitor = $this->getMockForAbstractClass('\\PDepend\\Source\\ASTVisitor\\AbstractASTVisitor'); - $visitor->addVisitListener($this->getMock('\\PDepend\\Source\\ASTVisitor\\ASTVisitListener')); + + $listener = $this->getMockBuilder('\\PDepend\\Source\\ASTVisitor\\ASTVisitListener') + ->getMock(); + $visitor->addVisitListener($listener); $this->assertEquals(1, count($visitor->getVisitListeners())); } diff --git a/src/test/php/PDepend/Source/Builder/BuilderContext/GlobalBuilderContextTest.php b/src/test/php/PDepend/Source/Builder/BuilderContext/GlobalBuilderContextTest.php index 26d4627720..a9cabcdfe8 100644 --- a/src/test/php/PDepend/Source/Builder/BuilderContext/GlobalBuilderContextTest.php +++ b/src/test/php/PDepend/Source/Builder/BuilderContext/GlobalBuilderContextTest.php @@ -68,7 +68,8 @@ class GlobalBuilderContextTest extends AbstractTest */ public function testRegisterTraitCallsRestoreClassOnBuilder() { - $builder = $this->getMock('\\PDepend\\Source\\Builder\\Builder'); + $builder = $this->getMockBuilder('\\PDepend\\Source\\Builder\\Builder') + ->getMock(); $builder->expects($this->once()) ->method('restoreTrait') ->with($this->isInstanceOf('PDepend\\Source\\AST\\ASTTrait')); @@ -84,7 +85,8 @@ public function testRegisterTraitCallsRestoreClassOnBuilder() */ public function testRegisterClassCallsRestoreClassOnBuilder() { - $builder = $this->getMock('\\PDepend\\Source\\Builder\\Builder'); + $builder = $this->getMockBuilder('\\PDepend\\Source\\Builder\\Builder') + ->getMock(); $builder->expects($this->once()) ->method('restoreClass') ->with($this->isInstanceOf('PDepend\\Source\\AST\\ASTClass')); @@ -100,7 +102,8 @@ public function testRegisterClassCallsRestoreClassOnBuilder() */ public function testRegisterInterfaceCallsRestoreInterfaceOnBuilder() { - $builder = $this->getMock('\\PDepend\\Source\\Builder\\Builder'); + $builder = $this->getMockBuilder('\\PDepend\\Source\\Builder\\Builder') + ->getMock(); $builder->expects($this->once()) ->method('restoreInterface') ->with($this->isInstanceOf('PDepend\\Source\\AST\\ASTInterface')); @@ -116,7 +119,8 @@ public function testRegisterInterfaceCallsRestoreInterfaceOnBuilder() */ public function testRegisterFunctionCallsRestoreFunctionOnBuilder() { - $builder = $this->getMock('\\PDepend\\Source\\Builder\\Builder'); + $builder = $this->getMockBuilder('\\PDepend\\Source\\Builder\\Builder') + ->getMock(); $builder->expects($this->once()) ->method('restoreFunction') ->with($this->isInstanceOf('PDepend\\Source\\AST\\ASTFunction')); @@ -133,7 +137,8 @@ public function testRegisterFunctionCallsRestoreFunctionOnBuilder() */ public function testGetTraitDelegatesCallToWrappedBuilder() { - $builder = $this->getMock('\\PDepend\\Source\\Builder\\Builder'); + $builder = $this->getMockBuilder('\\PDepend\\Source\\Builder\\Builder') + ->getMock(); $builder->expects($this->once()) ->method('getTrait') ->with($this->equalTo(__CLASS__)); @@ -149,7 +154,8 @@ public function testGetTraitDelegatesCallToWrappedBuilder() */ public function testGetClassDelegatesCallToWrappedBuilder() { - $builder = $this->getMock('\\PDepend\\Source\\Builder\\Builder'); + $builder = $this->getMockBuilder('\\PDepend\\Source\\Builder\\Builder') + ->getMock(); $builder->expects($this->once()) ->method('getClass') ->with($this->equalTo(__CLASS__)); @@ -165,7 +171,8 @@ public function testGetClassDelegatesCallToWrappedBuilder() */ public function testGetClassOrInterfaceDelegatesCallToWrappedBuilder() { - $builder = $this->getMock('\\PDepend\\Source\\Builder\\Builder'); + $builder = $this->getMockBuilder('\\PDepend\\Source\\Builder\\Builder') + ->getMock(); $builder->expects($this->once()) ->method('getClassOrInterface') ->with($this->equalTo(__CLASS__)); diff --git a/src/test/php/PDepend/Source/Language/PHP/PHPBuilderTest.php b/src/test/php/PDepend/Source/Language/PHP/PHPBuilderTest.php index 5a0a8cc7b6..b1b6511197 100644 --- a/src/test/php/PDepend/Source/Language/PHP/PHPBuilderTest.php +++ b/src/test/php/PDepend/Source/Language/PHP/PHPBuilderTest.php @@ -139,11 +139,9 @@ public function testRestoreFunctionAddsFunctionToPackage() */ public function testRestoreFunctionUsesGetNamespaceNameMethod() { - $function = $this->getMock( - 'PDepend\\Source\\AST\\ASTFunction', - array(), - array(__FUNCTION__) - ); + $function = $this->getMockBuilder('PDepend\\Source\\AST\\ASTFunction') + ->setConstructorArgs(array(__FUNCTION__)) + ->getMock(); $function->expects($this->once()) ->method('getNamespaceName'); diff --git a/src/test/php/PDepend/Util/Coverage/CloverReportTest.php b/src/test/php/PDepend/Util/Coverage/CloverReportTest.php index d9df8ca1ed..20a600d23a 100644 --- a/src/test/php/PDepend/Util/Coverage/CloverReportTest.php +++ b/src/test/php/PDepend/Util/Coverage/CloverReportTest.php @@ -204,12 +204,16 @@ private function _createNamespacedCloverReport() */ private function createMethodMock($name, $startLine = 1, $endLine = 4) { - $file = $this->getMock('\\PDepend\\Source\\AST\\ASTCompilationUnit', array(), array(null)); + $file = $this->getMockBuilder('\\PDepend\\Source\\AST\\ASTCompilationUnit') + ->setConstructorArgs(array(null)) + ->getMock(); $file->expects($this->any()) ->method('getFileName') ->will($this->returnValue('/' . $name . '.php')); - $method = $this->getMock('\\PDepend\\Source\\AST\\ASTMethod', array(), array($name)); + $method = $this->getMockBuilder('\\PDepend\\Source\\AST\\ASTMethod') + ->setConstructorArgs(array($name)) + ->getMock(); $method->expects($this->once()) ->method('getCompilationUnit') ->will($this->returnValue($file));