2 phpunit --coverage-source /tmp BankAccountTest ../../Samples/BankAccount/BankAccountTest.php
5 $tempPath = dirname(__FILE__);
7 $_SERVER['argv'][1] = '--coverage-source';
8 $_SERVER['argv'][2] = $tempPath;
9 $_SERVER['argv'][3] = 'BankAccountTest';
10 $_SERVER['argv'][4] = '../Samples/BankAccount/BankAccountTest.php';
12 define('PHPUnit_MAIN_METHOD', '');
13 require_once dirname(dirname(dirname(__FILE__))) . '/TextUI/Command.php';
15 PHPUnit_TextUI_Command::main(FALSE);
17 print file_get_contents($tempPath . DIRECTORY_SEPARATOR . 'BankAccount.php.xml');
18 print file_get_contents($tempPath . DIRECTORY_SEPARATOR . 'BankAccountTest.php.xml');
22 $tempPath = dirname(__FILE__);
23 unlink($tempPath . DIRECTORY_SEPARATOR . 'BankAccount.php.xml');
24 unlink($tempPath . DIRECTORY_SEPARATOR . 'BankAccountTest.php.xml');
27 PHPUnit %s by Sebastian Bergmann.
33 OK (3 tests, 3 assertions)
35 Writing code coverage data to XML files, this may take a moment.
36 <?xml version="1.0" encoding="UTF-8"?>
37 <coveredFile fullPath="%s/BankAccount.php" shortenedPath="BankAccount.php" generated="%i" phpunit="%s">
38 <line lineNumber="1" executed="-3">
41 <line lineNumber="2" executed="-3">
44 <line lineNumber="3" executed="-3">
45 <body> * PHPUnit</body>
47 <line lineNumber="4" executed="-3">
50 <line lineNumber="5" executed="-3">
51 <body> * Copyright (c) 2002-2009, Sebastian Bergmann <sb@sebastian-bergmann.de>.</body>
53 <line lineNumber="6" executed="-3">
54 <body> * All rights reserved.</body>
56 <line lineNumber="7" executed="-3">
59 <line lineNumber="8" executed="-3">
60 <body> * Redistribution and use in source and binary forms, with or without</body>
62 <line lineNumber="9" executed="-3">
63 <body> * modification, are permitted provided that the following conditions</body>
65 <line lineNumber="10" executed="-3">
66 <body> * are met:</body>
68 <line lineNumber="11" executed="-3">
71 <line lineNumber="12" executed="-3">
72 <body> * * Redistributions of source code must retain the above copyright</body>
74 <line lineNumber="13" executed="-3">
75 <body> * notice, this list of conditions and the following disclaimer.</body>
77 <line lineNumber="14" executed="-3">
80 <line lineNumber="15" executed="-3">
81 <body> * * Redistributions in binary form must reproduce the above copyright</body>
83 <line lineNumber="16" executed="-3">
84 <body> * notice, this list of conditions and the following disclaimer in</body>
86 <line lineNumber="17" executed="-3">
87 <body> * the documentation and/or other materials provided with the</body>
89 <line lineNumber="18" executed="-3">
90 <body> * distribution.</body>
92 <line lineNumber="19" executed="-3">
95 <line lineNumber="20" executed="-3">
96 <body> * * Neither the name of Sebastian Bergmann nor the names of his</body>
98 <line lineNumber="21" executed="-3">
99 <body> * contributors may be used to endorse or promote products derived</body>
101 <line lineNumber="22" executed="-3">
102 <body> * from this software without specific prior written permission.</body>
104 <line lineNumber="23" executed="-3">
107 <line lineNumber="24" executed="-3">
108 <body> * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS</body>
110 <line lineNumber="25" executed="-3">
111 <body> * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT</body>
113 <line lineNumber="26" executed="-3">
114 <body> * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS</body>
116 <line lineNumber="27" executed="-3">
117 <body> * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE</body>
119 <line lineNumber="28" executed="-3">
120 <body> * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,</body>
122 <line lineNumber="29" executed="-3">
123 <body> * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,</body>
125 <line lineNumber="30" executed="-3">
126 <body> * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;</body>
128 <line lineNumber="31" executed="-3">
129 <body> * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER</body>
131 <line lineNumber="32" executed="-3">
132 <body> * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT</body>
134 <line lineNumber="33" executed="-3">
135 <body> * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN</body>
137 <line lineNumber="34" executed="-3">
138 <body> * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE</body>
140 <line lineNumber="35" executed="-3">
141 <body> * POSSIBILITY OF SUCH DAMAGE.</body>
143 <line lineNumber="36" executed="-3">
146 <line lineNumber="37" executed="-3">
147 <body> * @category Testing</body>
149 <line lineNumber="38" executed="-3">
150 <body> * @package PHPUnit</body>
152 <line lineNumber="39" executed="-3">
153 <body> * @author Sebastian Bergmann <sb@sebastian-bergmann.de></body>
155 <line lineNumber="40" executed="-3">
156 <body> * @copyright 2002-2009 Sebastian Bergmann <sb@sebastian-bergmann.de></body>
158 <line lineNumber="41" executed="-3">
159 <body> * @license http://www.opensource.org/licenses/bsd-license.php BSD License</body>
161 <line lineNumber="42" executed="-3">
162 <body> * @version SVN: $%s$</body>
164 <line lineNumber="43" executed="-3">
165 <body> * @link http://www.phpunit.de/</body>
167 <line lineNumber="44" executed="-3">
168 <body> * @since File available since Release 2.3.0</body>
170 <line lineNumber="45" executed="-3">
173 <line lineNumber="46" executed="-3">
176 <line lineNumber="47" executed="-3">
177 <body>class BankAccountException extends RuntimeException {}</body>
179 <line lineNumber="48" executed="-3">
182 <line lineNumber="49" executed="-3">
185 <line lineNumber="50" executed="-3">
186 <body> * A bank account.</body>
188 <line lineNumber="51" executed="-3">
191 <line lineNumber="52" executed="-3">
192 <body> * @category Testing</body>
194 <line lineNumber="53" executed="-3">
195 <body> * @package PHPUnit</body>
197 <line lineNumber="54" executed="-3">
198 <body> * @author Sebastian Bergmann <sb@sebastian-bergmann.de></body>
200 <line lineNumber="55" executed="-3">
201 <body> * @copyright 2002-2009 Sebastian Bergmann <sb@sebastian-bergmann.de></body>
203 <line lineNumber="56" executed="-3">
204 <body> * @license http://www.opensource.org/licenses/bsd-license.php BSD License</body>
206 <line lineNumber="57" executed="-3">
207 <body> * @version Release: %s</body>
209 <line lineNumber="58" executed="-3">
210 <body> * @link http://www.phpunit.de/</body>
212 <line lineNumber="59" executed="-3">
213 <body> * @since Class available since Release 2.3.0</body>
215 <line lineNumber="60" executed="-3">
218 <line lineNumber="61" executed="-3">
219 <body>class BankAccount</body>
221 <line lineNumber="62" executed="-3">
224 <line lineNumber="63" executed="-3">
227 <line lineNumber="64" executed="-3">
228 <body> * The bank account's balance.</body>
230 <line lineNumber="65" executed="-3">
233 <line lineNumber="66" executed="-3">
234 <body> * @var float</body>
236 <line lineNumber="67" executed="-3">
239 <line lineNumber="68" executed="-3">
240 <body> protected $balance = 0;</body>
242 <line lineNumber="69" executed="-3">
245 <line lineNumber="70" executed="-3">
248 <line lineNumber="71" executed="-3">
249 <body> * Returns the bank account's balance.</body>
251 <line lineNumber="72" executed="-3">
254 <line lineNumber="73" executed="-3">
255 <body> * @return float</body>
257 <line lineNumber="74" executed="-3">
260 <line lineNumber="75" executed="-3">
261 <body> public function getBalance()</body>
263 <line lineNumber="76" executed="-3">
266 <line lineNumber="77" executed="1">
267 <body> return $this->balance;</body>
269 <test name="testBalanceIsInitiallyZero" status="0" class="BankAccountTest" fullPath="%s/BankAccountTest.php" shortenedPath="/BankAccountTest.php" line="76"/>
272 <line lineNumber="78" executed="-2">
275 <line lineNumber="79" executed="-3">
278 <line lineNumber="80" executed="-3">
281 <line lineNumber="81" executed="-3">
282 <body> * Sets the bank account's balance.</body>
284 <line lineNumber="82" executed="-3">
287 <line lineNumber="83" executed="-3">
288 <body> * @param float $balance</body>
290 <line lineNumber="84" executed="-3">
291 <body> * @throws BankAccountException</body>
293 <line lineNumber="85" executed="-3">
296 <line lineNumber="86" executed="-3">
297 <body> protected function setBalance($balance)</body>
299 <line lineNumber="87" executed="-3">
302 <line lineNumber="88" executed="-1">
303 <body> if ($balance >= 0) {</body>
305 <line lineNumber="89" executed="-1">
306 <body> $this->balance = $balance;</body>
308 <line lineNumber="90" executed="-1">
309 <body> } else {</body>
311 <line lineNumber="91" executed="-1">
312 <body> throw new BankAccountException;</body>
314 <line lineNumber="92" executed="-3">
317 <line lineNumber="93" executed="-1">
320 <line lineNumber="94" executed="-3">
323 <line lineNumber="95" executed="-3">
326 <line lineNumber="96" executed="-3">
327 <body> * Deposits an amount of money to the bank account.</body>
329 <line lineNumber="97" executed="-3">
332 <line lineNumber="98" executed="-3">
333 <body> * @param float $balance</body>
335 <line lineNumber="99" executed="-3">
336 <body> * @throws BankAccountException</body>
338 <line lineNumber="100" executed="-3">
341 <line lineNumber="101" executed="-3">
342 <body> public function depositMoney($balance)</body>
344 <line lineNumber="102" executed="-3">
347 <line lineNumber="103" executed="1">
348 <body> $this->setBalance($this->getBalance() + $balance);</body>
350 <test name="testBalanceCannotBecomeNegative2" status="0" class="BankAccountTest" fullPath="%s/BankAccountTest.php" shortenedPath="/BankAccountTest.php" line="106"/>
353 <line lineNumber="104" executed="-3">
356 <line lineNumber="105" executed="-1">
357 <body> return $this->getBalance();</body>
359 <line lineNumber="106" executed="-2">
362 <line lineNumber="107" executed="-3">
365 <line lineNumber="108" executed="-3">
368 <line lineNumber="109" executed="-3">
369 <body> * Withdraws an amount of money from the bank account.</body>
371 <line lineNumber="110" executed="-3">
374 <line lineNumber="111" executed="-3">
375 <body> * @param float $balance</body>
377 <line lineNumber="112" executed="-3">
378 <body> * @throws BankAccountException</body>
380 <line lineNumber="113" executed="-3">
383 <line lineNumber="114" executed="-3">
384 <body> public function withdrawMoney($balance)</body>
386 <line lineNumber="115" executed="-3">
389 <line lineNumber="116" executed="1">
390 <body> $this->setBalance($this->getBalance() - $balance);</body>
392 <test name="testBalanceCannotBecomeNegative" status="0" class="BankAccountTest" fullPath="%s/BankAccountTest.php" shortenedPath="/BankAccountTest.php" line="86"/>
395 <line lineNumber="117" executed="-3">
398 <line lineNumber="118" executed="-1">
399 <body> return $this->getBalance();</body>
401 <line lineNumber="119" executed="-2">
404 <line lineNumber="120" executed="-3">
407 <line lineNumber="121" executed="-3">
411 <?xml version="1.0" encoding="UTF-8"?>
412 <testFile fullPath="%s/BankAccountTest.php" shortenedPath="BankAccountTest.php" generated="%i" phpunit="%s">
413 <line lineNumber="1">
414 <body><?php</body>
416 <line lineNumber="2">
419 <line lineNumber="3">
420 <body> * PHPUnit</body>
422 <line lineNumber="4">
425 <line lineNumber="5">
426 <body> * Copyright (c) 2002-2009, Sebastian Bergmann <sb@sebastian-bergmann.de>.</body>
428 <line lineNumber="6">
429 <body> * All rights reserved.</body>
431 <line lineNumber="7">
434 <line lineNumber="8">
435 <body> * Redistribution and use in source and binary forms, with or without</body>
437 <line lineNumber="9">
438 <body> * modification, are permitted provided that the following conditions</body>
440 <line lineNumber="10">
441 <body> * are met:</body>
443 <line lineNumber="11">
446 <line lineNumber="12">
447 <body> * * Redistributions of source code must retain the above copyright</body>
449 <line lineNumber="13">
450 <body> * notice, this list of conditions and the following disclaimer.</body>
452 <line lineNumber="14">
455 <line lineNumber="15">
456 <body> * * Redistributions in binary form must reproduce the above copyright</body>
458 <line lineNumber="16">
459 <body> * notice, this list of conditions and the following disclaimer in</body>
461 <line lineNumber="17">
462 <body> * the documentation and/or other materials provided with the</body>
464 <line lineNumber="18">
465 <body> * distribution.</body>
467 <line lineNumber="19">
470 <line lineNumber="20">
471 <body> * * Neither the name of Sebastian Bergmann nor the names of his</body>
473 <line lineNumber="21">
474 <body> * contributors may be used to endorse or promote products derived</body>
476 <line lineNumber="22">
477 <body> * from this software without specific prior written permission.</body>
479 <line lineNumber="23">
482 <line lineNumber="24">
483 <body> * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS</body>
485 <line lineNumber="25">
486 <body> * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT</body>
488 <line lineNumber="26">
489 <body> * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS</body>
491 <line lineNumber="27">
492 <body> * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE</body>
494 <line lineNumber="28">
495 <body> * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,</body>
497 <line lineNumber="29">
498 <body> * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,</body>
500 <line lineNumber="30">
501 <body> * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;</body>
503 <line lineNumber="31">
504 <body> * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER</body>
506 <line lineNumber="32">
507 <body> * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT</body>
509 <line lineNumber="33">
510 <body> * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN</body>
512 <line lineNumber="34">
513 <body> * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE</body>
515 <line lineNumber="35">
516 <body> * POSSIBILITY OF SUCH DAMAGE.</body>
518 <line lineNumber="36">
521 <line lineNumber="37">
522 <body> * @category Testing</body>
524 <line lineNumber="38">
525 <body> * @package PHPUnit</body>
527 <line lineNumber="39">
528 <body> * @author Sebastian Bergmann <sb@sebastian-bergmann.de></body>
530 <line lineNumber="40">
531 <body> * @copyright 2002-2009 Sebastian Bergmann <sb@sebastian-bergmann.de></body>
533 <line lineNumber="41">
534 <body> * @license http://www.opensource.org/licenses/bsd-license.php BSD License</body>
536 <line lineNumber="42">
537 <body> * @version SVN: $%s$</body>
539 <line lineNumber="43">
540 <body> * @link http://www.phpunit.de/</body>
542 <line lineNumber="44">
543 <body> * @since File available since Release 2.3.0</body>
545 <line lineNumber="45">
548 <line lineNumber="46">
551 <line lineNumber="47">
552 <body>require_once 'PHPUnit/Framework/TestCase.php';</body>
554 <line lineNumber="48">
555 <body>require_once 'BankAccount.php';</body>
557 <line lineNumber="49">
560 <line lineNumber="50">
563 <line lineNumber="51">
564 <body> * Tests for the BankAccount class.</body>
566 <line lineNumber="52">
569 <line lineNumber="53">
570 <body> * @category Testing</body>
572 <line lineNumber="54">
573 <body> * @package PHPUnit</body>
575 <line lineNumber="55">
576 <body> * @author Sebastian Bergmann <sb@sebastian-bergmann.de></body>
578 <line lineNumber="56">
579 <body> * @copyright 2002-2009 Sebastian Bergmann <sb@sebastian-bergmann.de></body>
581 <line lineNumber="57">
582 <body> * @license http://www.opensource.org/licenses/bsd-license.php BSD License</body>
584 <line lineNumber="58">
585 <body> * @version Release: %s</body>
587 <line lineNumber="59">
588 <body> * @link http://www.phpunit.de/</body>
590 <line lineNumber="60">
591 <body> * @since Class available since Release 2.3.0</body>
593 <line lineNumber="61">
596 <line lineNumber="62">
597 <body>class BankAccountTest extends PHPUnit_Framework_TestCase</body>
599 <line lineNumber="63">
602 <line lineNumber="64">
603 <body> protected $ba;</body>
605 <line lineNumber="65">
608 <line lineNumber="66">
609 <body> protected function setUp()</body>
611 <line lineNumber="67">
614 <line lineNumber="68">
615 <body> $this->ba = new BankAccount;</body>
617 <line lineNumber="69">
620 <line lineNumber="70">
623 <line lineNumber="71">
626 <line lineNumber="72">
627 <body> * @covers BankAccount::getBalance</body>
629 <line lineNumber="73">
630 <body> * @group balanceIsInitiallyZero</body>
632 <line lineNumber="74">
633 <body> * @group specification</body>
635 <line lineNumber="75">
638 <line lineNumber="76">
639 <body> public function testBalanceIsInitiallyZero()</body>
641 <coveredFile fullPath="%s/BankAccountTest.php" shortenedPath="BankAccount.php">
642 <coveredLine>77</coveredLine>
646 <line lineNumber="77">
649 <line lineNumber="78">
650 <body> $this->assertEquals(0, $this->ba->getBalance());</body>
652 <line lineNumber="79">
655 <line lineNumber="80">
658 <line lineNumber="81">
661 <line lineNumber="82">
662 <body> * @covers BankAccount::withdrawMoney</body>
664 <line lineNumber="83">
665 <body> * @group balanceCannotBecomeNegative</body>
667 <line lineNumber="84">
668 <body> * @group specification</body>
670 <line lineNumber="85">
673 <line lineNumber="86">
674 <body> public function testBalanceCannotBecomeNegative()</body>
676 <coveredFile fullPath="%s/BankAccountTest.php" shortenedPath="BankAccount.php">
677 <coveredLine>116</coveredLine>
681 <line lineNumber="87">
684 <line lineNumber="88">
687 <line lineNumber="89">
688 <body> $this->ba->withdrawMoney(1);</body>
690 <line lineNumber="90">
693 <line lineNumber="91">
696 <line lineNumber="92">
697 <body> catch (BankAccountException $e) {</body>
699 <line lineNumber="93">
700 <body> $this->assertEquals(0, $this->ba->getBalance());</body>
702 <line lineNumber="94">
705 <line lineNumber="95">
706 <body> return;</body>
708 <line lineNumber="96">
711 <line lineNumber="97">
714 <line lineNumber="98">
715 <body> $this->fail();</body>
717 <line lineNumber="99">
720 <line lineNumber="100">
723 <line lineNumber="101">
726 <line lineNumber="102">
727 <body> * @covers BankAccount::depositMoney</body>
729 <line lineNumber="103">
730 <body> * @group balanceCannotBecomeNegative</body>
732 <line lineNumber="104">
733 <body> * @group specification</body>
735 <line lineNumber="105">
738 <line lineNumber="106">
739 <body> public function testBalanceCannotBecomeNegative2()</body>
741 <coveredFile fullPath="%s/BankAccountTest.php" shortenedPath="BankAccount.php">
742 <coveredLine>103</coveredLine>
746 <line lineNumber="107">
749 <line lineNumber="108">
752 <line lineNumber="109">
753 <body> $this->ba->depositMoney(-1);</body>
755 <line lineNumber="110">
758 <line lineNumber="111">
761 <line lineNumber="112">
762 <body> catch (BankAccountException $e) {</body>
764 <line lineNumber="113">
765 <body> $this->assertEquals(0, $this->ba->getBalance());</body>
767 <line lineNumber="114">
770 <line lineNumber="115">
771 <body> return;</body>
773 <line lineNumber="116">
776 <line lineNumber="117">
779 <line lineNumber="118">
780 <body> $this->fail();</body>
782 <line lineNumber="119">
785 <line lineNumber="120">
788 <line lineNumber="121">
791 <line lineNumber="122">
792 <body> * @covers BankAccount::getBalance</body>
794 <line lineNumber="123">
795 <body> * @covers BankAccount::depositMoney</body>
797 <line lineNumber="124">
798 <body> * @covers BankAccount::withdrawMoney</body>
800 <line lineNumber="125">
801 <body> * @group balanceCannotBecomeNegative</body>
803 <line lineNumber="126">
806 <line lineNumber="127">
809 <line lineNumber="128">
810 <body> public function testDepositWithdrawMoney()</body>
812 <line lineNumber="129">
815 <line lineNumber="130">
816 <body> $this->assertEquals(0, $this->ba->getBalance());</body>
818 <line lineNumber="131">
819 <body> $this->ba->depositMoney(1);</body>
821 <line lineNumber="132">
822 <body> $this->assertEquals(1, $this->ba->getBalance());</body>
824 <line lineNumber="133">
825 <body> $this->ba->withdrawMoney(1);</body>
827 <line lineNumber="134">
828 <body> $this->assertEquals(0, $this->ba->getBalance());</body>
830 <line lineNumber="135">
833 <line lineNumber="136">
836 <line lineNumber="137">
839 <line lineNumber="138">