Skip to content

Commit

Permalink
Merge pull request #475 from phpmetrics/phpunit-compatibility
Browse files Browse the repository at this point in the history
Updates test for phpunit compatibility
  • Loading branch information
Halleck45 authored Mar 24, 2022
2 parents ac7b10d + 027719c commit b410ac5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
27 changes: 21 additions & 6 deletions tests/Violation/Class_/BlobTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Test\Hal\Violation\Class_;

use Hal\Metric\ClassMetric;
Expand All @@ -15,12 +16,26 @@ class BlobTest extends \PHPUnit\Framework\TestCase
*/
public function testGlobIsFound($expected, $nbMethodsPublic, $lcom, $nbExternals)
{
$prophet = $this->prophesize('Hal\Metric\ClassMetric');
$prophet->get('nbMethodsPublic')->willReturn($nbMethodsPublic);
$prophet->get('lcom')->willReturn($lcom);
$prophet->get('externals')->willReturn(array_pad([], $nbExternals, ''));
$prophet->get('violations')->willReturn(new Violations());
$class = $prophet->reveal();
$class = $this->getMockBuilder(ClassMetric::class)->disableOriginalConstructor()->getMock();

$violations = new Violations();
$class->method('get')->willReturnCallback(function ($param) use (
$violations,
$nbMethodsPublic,
$lcom,
$nbExternals
) {
switch ($param) {
case 'nbMethodsPublic':
return $nbMethodsPublic;
case 'lcom':
return $lcom;
case 'externals':
return array_pad([], $nbExternals, '');
case 'violations':
return $violations;
}
});

$object = new Blob();
$object->apply($class);
Expand Down
18 changes: 8 additions & 10 deletions tests/Violation/Package/StableDependenciesPrincipleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ class StableDependenciesPrincipleTest extends TestCase
{
public function testItIgnoresNonPackageMetrics()
{
$metric = $this->prophesize(Metric::class);

$metric = $this->getMockBuilder(Metric::class)->getMock();
$metric->expects($this->never())->method('get');
$object = new StableDependenciesPrinciple();

$object->apply($metric->reveal());

$metric->get('violations')->shouldNotHaveBeenCalled();
$object->apply($metric);
}

/**
Expand All @@ -36,14 +34,14 @@ public function testItAddsViolationsIfOneDependentPackageIsMoreUnstableOrAsUnsta
$expectedViolationCount
) {
$violations = new Violations();
$metric = $this->prophesize(PackageMetric::class);
$metric->getInstability()->willReturn($packageInstability);
$metric->getDependentInstabilities()->willReturn($dependentInstabilities);
$metric->get('violations')->willReturn($violations);
$metric = $this->getMockBuilder(PackageMetric::class)->disableOriginalConstructor()->getMock();
$metric->method('getInstability')->willReturn($packageInstability);
$metric->method('getDependentInstabilities')->willReturn($dependentInstabilities);
$metric->method('get')->willReturn($violations);

$object = new StableDependenciesPrinciple();

$object->apply($metric->reveal());
$object->apply($metric);

$this->assertSame($expectedViolationCount, $violations->count());
}
Expand Down

0 comments on commit b410ac5

Please sign in to comment.