<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Windchest &#187; simpletest</title>
	<atom:link href="http://blog.windchest.jp/tag/simpletest/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.windchest.jp</link>
	<description>らいどんによるプログラミングメモ</description>
	<lastBuildDate>Thu, 12 Jan 2012 07:34:23 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Simpletestにおけるテスト説明の文字化け解消</title>
		<link>http://blog.windchest.jp/programming/27.html</link>
		<comments>http://blog.windchest.jp/programming/27.html#comments</comments>
		<pubDate>Sun, 21 Feb 2010 15:05:21 +0000</pubDate>
		<dc:creator>ryde</dc:creator>
				<category><![CDATA[プログラミング]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[simpletest]]></category>
		<category><![CDATA[開発ツール]]></category>

		<guid isPermaLink="false">http://blog.windchest.jp/?p=27</guid>
		<description><![CDATA[SimpletestでHtmlReporter()メソッドを利用するとhtmlでの出力が可能になります。 コンストラクタでテストの説明を設定することが出来ますが、そのままだと文字化けが発生します。 文字化けの原因 上記の [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.simpletest.org/" target="_blank">Simpletest</a>でHtmlReporter()メソッドを利用するとhtmlでの出力が可能になります。</p>
<p>コンストラクタでテストの説明を設定することが出来ますが、そのままだと文字化けが発生します。</p>
<pre><span id="more-27"></span>
</pre>
<h5>文字化けの原因</h5>
<pre class="brush: php; title: ; notranslate">function __construct(){
    $this-&gt;UnitTestCase(&quot;Twitterクラスのユニットテスト&quot;);
}
</pre>
<p>上記のように設定すれば良いかと思いきや、このまま表示させると下記のように文字化けが発生します。  <a href="http://blog.windchest.jp/wp-content/uploads/2010/02/1.png"><img src="http://blog.windchest.jp/wp-content/uploads/2010/02/1-300x55.png" alt="文字化け" title="1" width="300" height="55" class="alignnone size-medium wp-image-29" /></a></p>
<p>念のためHTMLのソースを確認してみると</p>
<pre class="brush: php; title: ; notranslate">&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=ISO-8859-1&quot;&gt;;</pre>
<p>となっており、Simpletestのソースを確認してみるとrepoter.phpの30行目付近に</p>
<pre class="brush: php; title: ; notranslate">function HtmlReporter($character_set = 'ISO-8859-1') {
    $this-&gt;SimpleReporter();
    $this-&gt;_character_set = $character_set;
}
</pre>
<p>と書いてあります。</p>
<p>つまり、<strong>Simpletestのデフォルトでの表示文字コードはISO-8859-1</strong>ということになります。 それで日本語だと文字化けしてしまうわけです。</p>
<h5>解決方法</h5>
<pre>そこで、下記のように定義します。
<pre class="brush: php; title: ; notranslate">$test-&gt;run(new HtmlReporter(&quot;UTF-8&quot;));</pre>
<p>すると、htmlのcharsetが書き代わり、文字コードの設定をすることが出来ます。その結果、</p>
<p><a href="http://blog.windchest.jp/wp-content/uploads/2010/02/2.png"><img src="http://blog.windchest.jp/wp-content/uploads/2010/02/2-300x80.png" alt="日本語表示OK" title="2" width="300" height="80" class="alignnone size-medium wp-image-30" /></a></p>
<p>上記のように日本語で表示されるようになります。</p>
<p>テスト環境:<br />
Simpletestのバージョン:1.01<br />
PHPのバージョン:5.2.6</p>
<p><script type="text/javascript"><!--
google_ad_client = "ca-pub-6190376244558257";
/* windchest_page */
google_ad_slot = "5817002634";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.windchest.jp/programming/27.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: blog.windchest.jp @ 2012-02-06 23:31:55 -->
