Skip to content

Commit b410ac5

Browse files
authored
Merge pull request #475 from phpmetrics/phpunit-compatibility
Updates test for phpunit compatibility
2 parents ac7b10d + 027719c commit b410ac5

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

tests/Violation/Class_/BlobTest.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Test\Hal\Violation\Class_;
34

45
use Hal\Metric\ClassMetric;
@@ -15,12 +16,26 @@ class BlobTest extends \PHPUnit\Framework\TestCase
1516
*/
1617
public function testGlobIsFound($expected, $nbMethodsPublic, $lcom, $nbExternals)
1718
{
18-
$prophet = $this->prophesize('Hal\Metric\ClassMetric');
19-
$prophet->get('nbMethodsPublic')->willReturn($nbMethodsPublic);
20-
$prophet->get('lcom')->willReturn($lcom);
21-
$prophet->get('externals')->willReturn(array_pad([], $nbExternals, ''));
22-
$prophet->get('violations')->willReturn(new Violations());
23-
$class = $prophet->reveal();
19+
$class = $this->getMockBuilder(ClassMetric::class)->disableOriginalConstructor()->getMock();
20+
21+
$violations = new Violations();
22+
$class->method('get')->willReturnCallback(function ($param) use (
23+
$violations,
24+
$nbMethodsPublic,
25+
$lcom,
26+
$nbExternals
27+
) {
28+
switch ($param) {
29+
case 'nbMethodsPublic':
30+
return $nbMethodsPublic;
31+
case 'lcom':
32+
return $lcom;
33+
case 'externals':
34+
return array_pad([], $nbExternals, '');
35+
case 'violations':
36+
return $violations;
37+
}
38+
});
2439

2540
$object = new Blob();
2641
$object->apply($class);

tests/Violation/Package/StableDependenciesPrincipleTest.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ class StableDependenciesPrincipleTest extends TestCase
1515
{
1616
public function testItIgnoresNonPackageMetrics()
1717
{
18-
$metric = $this->prophesize(Metric::class);
19-
18+
$metric = $this->getMockBuilder(Metric::class)->getMock();
19+
$metric->expects($this->never())->method('get');
2020
$object = new StableDependenciesPrinciple();
2121

22-
$object->apply($metric->reveal());
23-
24-
$metric->get('violations')->shouldNotHaveBeenCalled();
22+
$object->apply($metric);
2523
}
2624

2725
/**
@@ -36,14 +34,14 @@ public function testItAddsViolationsIfOneDependentPackageIsMoreUnstableOrAsUnsta
3634
$expectedViolationCount
3735
) {
3836
$violations = new Violations();
39-
$metric = $this->prophesize(PackageMetric::class);
40-
$metric->getInstability()->willReturn($packageInstability);
41-
$metric->getDependentInstabilities()->willReturn($dependentInstabilities);
42-
$metric->get('violations')->willReturn($violations);
37+
$metric = $this->getMockBuilder(PackageMetric::class)->disableOriginalConstructor()->getMock();
38+
$metric->method('getInstability')->willReturn($packageInstability);
39+
$metric->method('getDependentInstabilities')->willReturn($dependentInstabilities);
40+
$metric->method('get')->willReturn($violations);
4341

4442
$object = new StableDependenciesPrinciple();
4543

46-
$object->apply($metric->reveal());
44+
$object->apply($metric);
4745

4846
$this->assertSame($expectedViolationCount, $violations->count());
4947
}

0 commit comments

Comments
 (0)