Skip to content

Commit 7da6fe5

Browse files
Refactor.
1 parent 0212177 commit 7da6fe5

File tree

3 files changed

+126
-100
lines changed

3 files changed

+126
-100
lines changed

Tests/PHP/CodeCoverageTest.php

Lines changed: 4 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
);
5555
}
5656

57+
require_once TEST_FILES_PATH . '../TestCase.php';
58+
5759
require_once TEST_FILES_PATH . 'BankAccount.php';
5860
require_once TEST_FILES_PATH . 'BankAccountTest.php';
5961

@@ -70,7 +72,7 @@
7072
* @link http://github.com/sebastianbergmann/php-code-coverage
7173
* @since Class available since Release 1.0.0
7274
*/
73-
class PHP_CodeCoverageTest extends PHPUnit_Framework_TestCase
75+
class PHP_CodeCoverageTest extends PHP_CodeCoverage_TestCase
7476
{
7577
/**
7678
* @covers PHP_CodeCoverage::__construct
@@ -104,7 +106,7 @@ public function testConstructor2()
104106
*/
105107
public function testCollect()
106108
{
107-
$coverage = new PHP_CodeCoverage($this->setUpStub());
109+
$coverage = new PHP_CodeCoverage($this->setUpXdebugStub());
108110

109111
$coverage->start(
110112
new BankAccountTest('testBalanceIsInitiallyZero'), TRUE
@@ -194,103 +196,5 @@ public function testCollect()
194196

195197
return $coverage;
196198
}
197-
198-
/**
199-
* @covers PHP_CodeCoverage::getSummary
200-
* @depends testCollect
201-
*/
202-
public function testSummary(PHP_CodeCoverage $coverage)
203-
{
204-
$this->assertEquals(
205-
array(
206-
'/usr/local/src/code-coverage/Tests/_files/BankAccount.php' => array(
207-
8 => array(
208-
0 => 'BankAccountTest::testBalanceIsInitiallyZero',
209-
1 => 'BankAccountTest::testDepositWithdrawMoney'
210-
),
211-
9 => -2,
212-
13 => -1,
213-
14 => -1,
214-
15 => -1,
215-
16 => -1,
216-
18 => -1,
217-
22 => array(
218-
0 => 'BankAccountTest::testBalanceCannotBecomeNegative2',
219-
1 => 'BankAccountTest::testDepositWithdrawMoney'
220-
),
221-
24 => array(
222-
0 => 'BankAccountTest::testDepositWithdrawMoney'
223-
),
224-
25 => -2,
225-
29 => array(
226-
0 => 'BankAccountTest::testBalanceCannotBecomeNegative',
227-
1 => 'BankAccountTest::testDepositWithdrawMoney'
228-
),
229-
31 => array(
230-
0 => 'BankAccountTest::testDepositWithdrawMoney'
231-
),
232-
32 => -2
233-
)
234-
),
235-
$coverage->getSummary()
236-
);
237-
}
238-
239-
protected function setUpStub()
240-
{
241-
$stub = $this->getMock('PHP_CodeCoverage_Driver_Xdebug');
242-
$stub->expects($this->any())
243-
->method('stop')
244-
->will($this->onConsecutiveCalls(
245-
array(
246-
TEST_FILES_PATH . 'BankAccount.php' => array(
247-
8 => 1,
248-
9 => -2,
249-
13 => -1,
250-
14 => -1,
251-
15 => -1,
252-
16 => -1,
253-
18 => -1,
254-
22 => -1,
255-
24 => -1,
256-
25 => -2,
257-
29 => -1,
258-
31 => -1,
259-
32 => -2
260-
)
261-
),
262-
array(
263-
TEST_FILES_PATH . 'BankAccount.php' => array(
264-
8 => 1,
265-
13 => 1,
266-
16 => 1,
267-
29 => 1,
268-
)
269-
),
270-
array(
271-
TEST_FILES_PATH . 'BankAccount.php' => array(
272-
8 => 1,
273-
13 => 1,
274-
16 => 1,
275-
22 => 1,
276-
)
277-
),
278-
array(
279-
TEST_FILES_PATH . 'BankAccount.php' => array(
280-
8 => 1,
281-
13 => 1,
282-
14 => 1,
283-
15 => 1,
284-
18 => 1,
285-
22 => 1,
286-
24 => 1,
287-
29 => 1,
288-
31 => 1,
289-
)
290-
)
291-
));
292-
293-
return $stub;
294-
}
295199
}
296200
?>

Tests/TestCase.php

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?php
2+
/**
3+
* PHP_CodeCoverage
4+
*
5+
* Copyright (c) 2009, Sebastian Bergmann <[email protected]>.
6+
* All rights reserved.
7+
*
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions
10+
* are met:
11+
*
12+
* * Redistributions of source code must retain the above copyright
13+
* notice, this list of conditions and the following disclaimer.
14+
*
15+
* * Redistributions in binary form must reproduce the above copyright
16+
* notice, this list of conditions and the following disclaimer in
17+
* the documentation and/or other materials provided with the
18+
* distribution.
19+
*
20+
* * Neither the name of Sebastian Bergmann nor the names of his
21+
* contributors may be used to endorse or promote products derived
22+
* from this software without specific prior written permission.
23+
*
24+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34+
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35+
* POSSIBILITY OF SUCH DAMAGE.
36+
*
37+
* @category PHP
38+
* @package CodeCoverage
39+
* @subpackage Tests
40+
* @author Sebastian Bergmann <[email protected]>
41+
* @copyright 2009 Sebastian Bergmann <[email protected]>
42+
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
43+
* @link http://github.com/sebastianbergmann/php-code-coverage
44+
* @since File available since Release 1.0.0
45+
*/
46+
47+
/**
48+
* Abstract base class for test case classes.
49+
*
50+
* @category PHP
51+
* @package CodeCoverage
52+
* @subpackage Tests
53+
* @author Sebastian Bergmann <[email protected]>
54+
* @copyright 2009 Sebastian Bergmann <[email protected]>
55+
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
56+
* @version Release: @package_version@
57+
* @link http://github.com/sebastianbergmann/php-code-coverage
58+
* @since Class available since Release 1.0.0
59+
*/
60+
abstract class PHP_CodeCoverage_TestCase extends PHPUnit_Framework_TestCase
61+
{
62+
protected function setUpXdebugStub()
63+
{
64+
$stub = $this->getMock('PHP_CodeCoverage_Driver_Xdebug');
65+
$stub->expects($this->any())
66+
->method('stop')
67+
->will($this->onConsecutiveCalls(
68+
array(
69+
TEST_FILES_PATH . 'BankAccount.php' => array(
70+
8 => 1,
71+
9 => -2,
72+
13 => -1,
73+
14 => -1,
74+
15 => -1,
75+
16 => -1,
76+
18 => -1,
77+
22 => -1,
78+
24 => -1,
79+
25 => -2,
80+
29 => -1,
81+
31 => -1,
82+
32 => -2
83+
)
84+
),
85+
array(
86+
TEST_FILES_PATH . 'BankAccount.php' => array(
87+
8 => 1,
88+
13 => 1,
89+
16 => 1,
90+
29 => 1,
91+
)
92+
),
93+
array(
94+
TEST_FILES_PATH . 'BankAccount.php' => array(
95+
8 => 1,
96+
13 => 1,
97+
16 => 1,
98+
22 => 1,
99+
)
100+
),
101+
array(
102+
TEST_FILES_PATH . 'BankAccount.php' => array(
103+
8 => 1,
104+
13 => 1,
105+
14 => 1,
106+
15 => 1,
107+
18 => 1,
108+
22 => 1,
109+
24 => 1,
110+
29 => 1,
111+
31 => 1,
112+
)
113+
)
114+
));
115+
116+
return $stub;
117+
}
118+
}
119+
?>

package.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@
9393
<tasks:replace from="@package_version@" to="version" type="package-info" />
9494
</file>
9595
</dir>
96+
<file baseinstalldir="/" name="TestCase.php" role="test">
97+
<tasks:replace from="@package_version@" to="version" type="package-info" />
98+
</file>
9699
</dir>
97100
</dir>
98101
</contents>

0 commit comments

Comments
 (0)