<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://trans.onionmixer.net/wiki/index.php?action=history&amp;feed=atom&amp;title=PHPUnitManual%3A12.1</id>
	<title>PHPUnitManual:12.1 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://trans.onionmixer.net/wiki/index.php?action=history&amp;feed=atom&amp;title=PHPUnitManual%3A12.1"/>
	<link rel="alternate" type="text/html" href="https://trans.onionmixer.net/wiki/index.php?title=PHPUnitManual:12.1&amp;action=history"/>
	<updated>2026-05-02T09:43:38Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.3</generator>
	<entry>
		<id>https://trans.onionmixer.net/wiki/index.php?title=PHPUnitManual:12.1&amp;diff=3420&amp;oldid=prev</id>
		<title>Onionmixer: wiki문법 수정</title>
		<link rel="alternate" type="text/html" href="https://trans.onionmixer.net/wiki/index.php?title=PHPUnitManual:12.1&amp;diff=3420&amp;oldid=prev"/>
		<updated>2013-07-03T03:34:36Z</updated>

		<summary type="html">&lt;p&gt;wiki문법 수정&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 03:34, 3 July 2013&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l140&quot;&gt;Line 140:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 140:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;이제 두번째 규약에 관한 테스트도 통과하게 되었습니다.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;이제 두번째 규약에 관한 테스트도 통과하게 되었습니다.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&quot;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;php&lt;/del&gt;&quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&quot;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;text&lt;/ins&gt;&quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;phpunit BankAccountTest&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;phpunit BankAccountTest&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;PHPUnit 3.7.0 by Sebastian Bergmann.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;PHPUnit 3.7.0 by Sebastian Bergmann.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Onionmixer</name></author>
	</entry>
	<entry>
		<id>https://trans.onionmixer.net/wiki/index.php?title=PHPUnitManual:12.1&amp;diff=3419&amp;oldid=prev</id>
		<title>Onionmixer: PHPUnit 12.1 은행 구좌에 대한 예제 페이지 추가</title>
		<link rel="alternate" type="text/html" href="https://trans.onionmixer.net/wiki/index.php?title=PHPUnitManual:12.1&amp;diff=3419&amp;oldid=prev"/>
		<updated>2013-07-03T03:33:45Z</updated>

		<summary type="html">&lt;p&gt;PHPUnit 12.1 은행 구좌에 대한 예제 페이지 추가&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;;12.1 은행 구좌에 대한 예제&lt;br /&gt;
&lt;br /&gt;
이 절에서는 은행 구좌를 표현하는 클래스를 예로 소개합니다. 예금 잔고의 조회, 설정, 입금과 출금 등의 메소드를 가지는 BankAccount 클래스는 다음 2가지 제약을 만족시켜야 합니다.&lt;br /&gt;
&lt;br /&gt;
* 예금 잔고의 초기값은 0 이어야만 한다.&lt;br /&gt;
* 예금 잔고가 0 이하로 되서는 안 된다.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
먼저 BankAccount 클래스의 테스트를 작성한 뒤에, 실제 코드를 작성하도록 합시다. 위의 두 제약을 테스트 작성의 기준으로 삼아, 이 기준에 따라 예12.1 &amp;quot;BankAccount 클래스의 테스트&amp;quot; 에 있는 것처럼 테스트 메소드의 이름을 붙입니다.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
예12.1 BankAccount 클래스의 테스트&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
require_once &amp;#039;BankAccount.php&amp;#039;;&lt;br /&gt;
 &lt;br /&gt;
class BankAccountTest extends PHPUnit_Framework_TestCase&lt;br /&gt;
{&lt;br /&gt;
    protected $ba;&lt;br /&gt;
 &lt;br /&gt;
    protected function setUp()&lt;br /&gt;
    {&lt;br /&gt;
        $this-&amp;gt;ba = new BankAccount;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public function testBalanceIsInitiallyZero()&lt;br /&gt;
    {&lt;br /&gt;
        $this-&amp;gt;assertEquals(0, $this-&amp;gt;ba-&amp;gt;getBalance());&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public function testBalanceCannotBecomeNegative()&lt;br /&gt;
    {&lt;br /&gt;
        try {&lt;br /&gt;
            $this-&amp;gt;ba-&amp;gt;withdrawMoney(1);&lt;br /&gt;
        }&lt;br /&gt;
 &lt;br /&gt;
        catch (BankAccountException $e) {&lt;br /&gt;
            $this-&amp;gt;assertEquals(0, $this-&amp;gt;ba-&amp;gt;getBalance());&lt;br /&gt;
 &lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
 &lt;br /&gt;
        $this-&amp;gt;fail();&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public function testBalanceCannotBecomeNegative2()&lt;br /&gt;
    {&lt;br /&gt;
        try {&lt;br /&gt;
            $this-&amp;gt;ba-&amp;gt;depositMoney(-1);&lt;br /&gt;
        }&lt;br /&gt;
 &lt;br /&gt;
        catch (BankAccountException $e) {&lt;br /&gt;
            $this-&amp;gt;assertEquals(0, $this-&amp;gt;ba-&amp;gt;getBalance());&lt;br /&gt;
 &lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
 &lt;br /&gt;
        $this-&amp;gt;fail();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
그리고, 첫번째 테스트인 testBalanceIsInitiallyZero() 를 통과할 수 있도록 필요 최소한의 코드를 작성해 봅시다. 필요한 것은 BankAccount 클래스의 getBalance() 메소드를 예12.2 &amp;quot;테스트 testBalanceIsInitiallyZero() 를 통과하기 위해 필요한 코드&amp;quot; 에 나온 것처럼 구현하는 것입니다.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
예12.2 테스트 testBalanceIsInitiallyZero() 를 통과하기 위해 필요한 코드&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
class BankAccount&lt;br /&gt;
{&lt;br /&gt;
    protected $balance = 0;&lt;br /&gt;
 &lt;br /&gt;
    public function getBalance()&lt;br /&gt;
    {&lt;br /&gt;
        return $this-&amp;gt;balance;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
이걸로 첫번째 테스트는 통과하지만, 두번째 테스트에서 실패할 것입니다. 그 이유는, 테스트 메소드 안에서 호출하는 메소드가 아직 구현되지 않았기 때문입니다.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
phpunit BankAccountTest&lt;br /&gt;
PHPUnit 3.7.0 by Sebastian Bergmann.&lt;br /&gt;
&lt;br /&gt;
.&lt;br /&gt;
Fatal error: Call to undefined method BankAccount::withdrawMoney()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
두번째 규약의 테스트를 통과하기 위해서는, withdrawMoney(), depositMoney(), 그리고 setBalance() 메소드들을 예12.3 &amp;quot;완전한 BankAccount 클래스&amp;quot; 에 나온 것처럼 구현해야만 합니다. 이 메소드들은, 규약에 어긋나는 인수를 넘겨 받은 경우, BankAccountException 를 발생시키도록 구현되어 있습니다.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
예12.3 완전한 BankAccount 클래스&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
class BankAccount&lt;br /&gt;
{&lt;br /&gt;
    protected $balance = 0;&lt;br /&gt;
 &lt;br /&gt;
    public function getBalance()&lt;br /&gt;
    {&lt;br /&gt;
        return $this-&amp;gt;balance;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    protected function setBalance($balance)&lt;br /&gt;
    {&lt;br /&gt;
        if ($balance &amp;gt;= 0) {&lt;br /&gt;
            $this-&amp;gt;balance = $balance;&lt;br /&gt;
        } else {&lt;br /&gt;
            throw new BankAccountException;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public function depositMoney($balance)&lt;br /&gt;
    {&lt;br /&gt;
        $this-&amp;gt;setBalance($this-&amp;gt;getBalance() + $balance);&lt;br /&gt;
 &lt;br /&gt;
        return $this-&amp;gt;getBalance();&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public function withdrawMoney($balance)&lt;br /&gt;
    {&lt;br /&gt;
        $this-&amp;gt;setBalance($this-&amp;gt;getBalance() - $balance);&lt;br /&gt;
 &lt;br /&gt;
        return $this-&amp;gt;getBalance();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
이제 두번째 규약에 관한 테스트도 통과하게 되었습니다.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
phpunit BankAccountTest&lt;br /&gt;
PHPUnit 3.7.0 by Sebastian Bergmann.&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
Time: 0 seconds&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OK (3 tests, 3 assertions)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
다른 방법으로는, PHPUnit_Framework_Assert 클래스가 제공하는 정적 검증 메소드를 사용하여, 코드 안에서 &amp;quot;규약에 의한 설계&amp;quot; 방식의 검증을 작성하는 것입니다. 예12.4 &amp;quot;&amp;quot;규약에 의한 설계&amp;quot; 검증을 사용한 BankAccount 클래스&amp;quot;가 그 예입니다. 예에 나온 검증 중 하나라도 실패할 경우, 예외 PHPUnit_Framework_AssertionFailedError 가 발생합니다. 이 방식을 사용하여 조건 체크 코드를 줄일 수 있기 때문에 코드의 가독성이 좋아집니다. 단, 프로그램을 실행할 때에도 PHPUnit 이 필요합니다.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
예12.4 &amp;quot;규약에 의한 설계&amp;quot; 검증을 사용한 BankAccount 클래스&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
class BankAccount&lt;br /&gt;
{&lt;br /&gt;
    private $balance = 0;&lt;br /&gt;
 &lt;br /&gt;
    public function getBalance()&lt;br /&gt;
    {&lt;br /&gt;
        return $this-&amp;gt;balance;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    protected function setBalance($balance)&lt;br /&gt;
    {&lt;br /&gt;
        PHPUnit_Framework_Assert::assertTrue($balance &amp;gt;= 0);&lt;br /&gt;
 &lt;br /&gt;
        $this-&amp;gt;balance = $balance;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public function depositMoney($amount)&lt;br /&gt;
    {&lt;br /&gt;
        PHPUnit_Framework_Assert::assertTrue($amount &amp;gt;= 0);&lt;br /&gt;
 &lt;br /&gt;
        $this-&amp;gt;setBalance($this-&amp;gt;getBalance() + $amount);&lt;br /&gt;
 &lt;br /&gt;
        return $this-&amp;gt;getBalance();&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    public function withdrawMoney($amount)&lt;br /&gt;
    {&lt;br /&gt;
        PHPUnit_Framework_Assert::assertTrue($amount &amp;gt;= 0);&lt;br /&gt;
        PHPUnit_Framework_Assert::assertTrue($this-&amp;gt;balance &amp;gt;= $amount);&lt;br /&gt;
 &lt;br /&gt;
        $this-&amp;gt;setBalance($this-&amp;gt;getBalance() - $amount);&lt;br /&gt;
 &lt;br /&gt;
        return $this-&amp;gt;getBalance();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
규약을 만족시키기 위한 조건을 테스트 안에 포함시켜서 &amp;quot;규약에 의한 설계&amp;quot; 방식으로 BankAccount 클래스를 프로그래밍했습니다. 다음으로, Test-First Programming 의 개념에 따라, 테스트를 통과하기 위해 필요한 코드를 작성했습니다. 여기에는 한가지 빠진 사항이 있는데, setBalance(), depositMoney(), 그리고 withdrawMoney() 에 올바른 값을 지정한 경우, 정상 작동하는지는 확인하는 테스트를 작성하는 것입니다. 테스트를 빠짐없이 작성하기 위해서는, 작성한 테스트가 적절한 것인지, 충분한지를 조사하기 위한 테스트가 필요합니다. 다음 장에서는 이를 위한 &amp;quot;code-coverage 해석&amp;quot; 을 설명하겠습니다.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:PHPUnitManual]]&lt;/div&gt;</summary>
		<author><name>Onionmixer</name></author>
	</entry>
</feed>