Skip to content

Commit

Permalink
Fixed PHPUnit warnings
Browse files Browse the repository at this point in the history
Changed all uses of getMock() to getMockBuilder().
  • Loading branch information
KacerCZ committed Nov 19, 2017
1 parent 5951ca8 commit 7bdbcbc
Show file tree
Hide file tree
Showing 34 changed files with 379 additions and 353 deletions.
16 changes: 13 additions & 3 deletions src/test/php/PDepend/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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__)));
Expand Down
9 changes: 6 additions & 3 deletions src/test/php/PDepend/Input/IteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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__)));
Expand All @@ -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__));
Expand All @@ -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__));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand All @@ -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));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/test/php/PDepend/Metrics/AnalyzerIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
Expand Down
3 changes: 2 additions & 1 deletion src/test/php/PDepend/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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__);
Expand Down
17 changes: 13 additions & 4 deletions src/test/php/PDepend/Report/Dependencies/XmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand Down
14 changes: 7 additions & 7 deletions src/test/php/PDepend/Report/Jdepend/ChartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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));
Expand Down
15 changes: 10 additions & 5 deletions src/test/php/PDepend/Report/Overview/PyramidTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
10 changes: 8 additions & 2 deletions src/test/php/PDepend/Report/Summary/XmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
5 changes: 4 additions & 1 deletion src/test/php/PDepend/Source/AST/ASTClassReferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Loading

0 comments on commit 7bdbcbc

Please sign in to comment.