|
12 | 12 | use cloak\value\Coverage; |
13 | 13 | use cloak\spec\result\FixtureCoverageResult; |
14 | 14 | use cloak\result\CoverageResult; |
15 | | -use cloak\result\LineCountResult; |
16 | | -use cloak\result\CodeCoverageResult; |
17 | | -use Prophecy\Prophet; |
18 | | - |
| 15 | +use cloak\analyzer\result\LineResult; |
| 16 | +use cloak\result\collection\LineResultCollection; |
19 | 17 |
|
20 | 18 | describe(CoverageResult::class, function() { |
21 | 19 | describe('#getLineCount', function() { |
22 | 20 | beforeEach(function() { |
23 | | - $this->prophet = new Prophet(); |
24 | | - |
25 | | - $lineResult = $this->prophet->prophesize(LineCountResult::class); |
26 | | - $lineResult->getLineCount()->willReturn(10); |
27 | | - |
28 | | - $this->result = new FixtureCoverageResult( $lineResult->reveal() ); |
| 21 | + $this->lines = new LineResultCollection([ |
| 22 | + new LineResult(5, LineResult::EXECUTED), |
| 23 | + new LineResult(6, LineResult::EXECUTED) |
| 24 | + ]); |
| 25 | + $this->result = new FixtureCoverageResult( $this->lines ); |
29 | 26 | }); |
30 | | - it('delegate to LineResultCollectionInterface#getLineCount', function() { |
31 | | - expect($this->result->getLineCount())->toBe(10); |
| 27 | + it('returns the line count', function() { |
| 28 | + expect($this->result->getLineCount())->toBe(2); |
32 | 29 | }); |
33 | 30 | }); |
34 | | - |
35 | 31 | describe('#getDeadLineCount', function() { |
36 | 32 | beforeEach(function() { |
37 | | - $this->prophet = new Prophet(); |
38 | | - |
39 | | - $lineResult = $this->prophet->prophesize(LineCountResult::class); |
40 | | - $lineResult->getDeadLineCount()->willReturn(10); |
41 | | - |
42 | | - $this->result = new FixtureCoverageResult( $lineResult->reveal() ); |
| 33 | + $this->lines = new LineResultCollection([ |
| 34 | + new LineResult(5, LineResult::DEAD), |
| 35 | + new LineResult(6, LineResult::EXECUTED) |
| 36 | + ]); |
| 37 | + $this->result = new FixtureCoverageResult( $this->lines ); |
43 | 38 | }); |
44 | | - it('delegate to LineResultCollectionInterface#getDeadLineCount', function() { |
45 | | - expect($this->result->getDeadLineCount())->toBe(10); |
| 39 | + it('returns the deat line count', function() { |
| 40 | + expect($this->result->getDeadLineCount())->toBe(1); |
46 | 41 | }); |
47 | 42 | }); |
48 | | - |
49 | 43 | describe('#getUnusedLineCount', function() { |
50 | 44 | beforeEach(function() { |
51 | | - $this->prophet = new Prophet(); |
52 | | - |
53 | | - $lineResult = $this->prophet->prophesize(LineCountResult::class); |
54 | | - $lineResult->getUnusedLineCount()->willReturn(10); |
55 | | - |
56 | | - $this->result = new FixtureCoverageResult( $lineResult->reveal() ); |
| 45 | + $this->lines = new LineResultCollection([ |
| 46 | + new LineResult(5, LineResult::DEAD), |
| 47 | + new LineResult(6, LineResult::UNUSED) |
| 48 | + ]); |
| 49 | + $this->result = new FixtureCoverageResult( $this->lines ); |
57 | 50 | }); |
58 | | - it('delegate to LineResultCollectionInterface#getUnusedLineCount', function() { |
59 | | - expect($this->result->getUnusedLineCount())->toBe(10); |
| 51 | + it('returns the unused line count', function() { |
| 52 | + expect($this->result->getUnusedLineCount())->toBe(1); |
60 | 53 | }); |
61 | 54 | }); |
62 | | - |
63 | 55 | describe('#getExecutedLineCount', function() { |
64 | 56 | beforeEach(function() { |
65 | | - $this->prophet = new Prophet(); |
66 | | - |
67 | | - $lineResult = $this->prophet->prophesize(LineCountResult::class); |
68 | | - $lineResult->getExecutedLineCount()->willReturn(10); |
69 | | - |
70 | | - $this->result = new FixtureCoverageResult( $lineResult->reveal() ); |
| 57 | + $this->lines = new LineResultCollection([ |
| 58 | + new LineResult(5, LineResult::DEAD), |
| 59 | + new LineResult(6, LineResult::EXECUTED) |
| 60 | + ]); |
| 61 | + $this->result = new FixtureCoverageResult( $this->lines ); |
71 | 62 | }); |
72 | | - it('delegate to LineResultCollectionInterface#getExecutedLineCount', function() { |
73 | | - expect($this->result->getExecutedLineCount())->toBe(10); |
| 63 | + it('returns the executed line count', function() { |
| 64 | + expect($this->result->getExecutedLineCount())->toBe(1); |
74 | 65 | }); |
75 | 66 | }); |
76 | 67 |
|
77 | 68 | describe('#getCodeCoverage', function() { |
78 | 69 | beforeEach(function() { |
79 | | - $this->prophet = new Prophet(); |
80 | | - |
81 | | - $lineResult = $this->prophet->prophesize(CodeCoverageResult::class); |
82 | | - $lineResult->getCodeCoverage()->willReturn(100); |
83 | | - |
84 | | - $this->result = new FixtureCoverageResult( $lineResult->reveal() ); |
| 70 | + $this->lines = new LineResultCollection([ |
| 71 | + new LineResult(5, LineResult::DEAD), |
| 72 | + new LineResult(6, LineResult::EXECUTED) |
| 73 | + ]); |
| 74 | + $this->result = new FixtureCoverageResult( $this->lines ); |
85 | 75 | }); |
86 | | - it('delegate to LineResultCollectionInterface#getCodeCoverage', function() { |
87 | | - expect($this->result->getCodeCoverage())->toBe(100); |
| 76 | + it('returns the code coverage value', function() { |
| 77 | + expect($this->result->getCodeCoverage()->value())->toBe(100.0); |
88 | 78 | }); |
89 | 79 | }); |
90 | 80 |
|
91 | 81 | describe('#isCoverageLessThan', function() { |
92 | | - beforeEach(function() { |
93 | | - $this->prophet = new Prophet(); |
94 | | - $this->coverage = new Coverage(51); |
95 | | - |
96 | | - $lineResult = $this->prophet->prophesize(CodeCoverageResult::class); |
97 | | - $lineResult->isCoverageLessThan($this->coverage)->willReturn(true); |
98 | | - |
99 | | - $this->result = new FixtureCoverageResult( $lineResult->reveal() ); |
100 | | - }); |
101 | | - it('delegate to LineResultCollectionInterface#isCoverageLessThan', function() { |
102 | | - $result = $this->result->isCoverageLessThan($this->coverage); |
103 | | - expect($result)->toBeTrue(); |
| 82 | + context('when coverage < 51', function () { |
| 83 | + beforeEach(function() { |
| 84 | + $this->coverage = new Coverage(51); |
| 85 | + $this->lines = new LineResultCollection([ |
| 86 | + new LineResult(5, LineResult::UNUSED), |
| 87 | + new LineResult(6, LineResult::EXECUTED) |
| 88 | + ]); |
| 89 | + $this->result = new FixtureCoverageResult( $this->lines ); |
| 90 | + }); |
| 91 | + it('returns true', function() { |
| 92 | + $result = $this->result->isCoverageLessThan($this->coverage); |
| 93 | + expect($result)->toBeTrue(); |
| 94 | + }); |
104 | 95 | }); |
105 | 96 | }); |
106 | 97 |
|
107 | 98 | describe('#isCoverageGreaterEqual', function() { |
108 | | - beforeEach(function() { |
109 | | - $this->prophet = new Prophet(); |
110 | | - $this->coverage = new Coverage(51); |
111 | | - |
112 | | - $lineResult = $this->prophet->prophesize(CodeCoverageResult::class); |
113 | | - $lineResult->isCoverageGreaterEqual($this->coverage) |
114 | | - ->willReturn(false); |
115 | | - |
116 | | - $this->result = new FixtureCoverageResult( $lineResult->reveal() ); |
117 | | - }); |
118 | | - it('delegate to LineResultCollectionInterface#isCoverageGreaterEqual', function() { |
119 | | - $result = $this->result->isCoverageGreaterEqual($this->coverage); |
120 | | - expect($result)->toBeFalse(); |
| 99 | + context('when coverage < 51', function () { |
| 100 | + beforeEach(function() { |
| 101 | + $this->coverage = new Coverage(51); |
| 102 | + $this->lines = new LineResultCollection([ |
| 103 | + new LineResult(5, LineResult::UNUSED), |
| 104 | + new LineResult(6, LineResult::EXECUTED) |
| 105 | + ]); |
| 106 | + $this->result = new FixtureCoverageResult( $this->lines ); |
| 107 | + }); |
| 108 | + it('returns false', function() { |
| 109 | + $result = $this->result->isCoverageGreaterEqual($this->coverage); |
| 110 | + expect($result)->toBeFalse(); |
| 111 | + }); |
121 | 112 | }); |
122 | 113 | }); |
123 | 114 |
|
|
0 commit comments