<?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"
	>

<channel>
	<title>Kingdom of Roi</title>
	<atom:link href="http://roysimkes.net/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://roysimkes.net/blog</link>
	<description>Yet Another Land in Kingdom of Roi</description>
	<pubDate>Thu, 13 Nov 2008 15:59:46 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
	<language>en</language>
			<item>
		<title>Writing You Own PHPUnit Listener</title>
		<link>http://roysimkes.net/blog/2008/11/writing-you-own-phpunit-listener/</link>
		<comments>http://roysimkes.net/blog/2008/11/writing-you-own-phpunit-listener/#comments</comments>
		<pubDate>Thu, 13 Nov 2008 15:53:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Parkyeri]]></category>

		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://roysimkes.net/blog/?p=53</guid>
		<description><![CDATA[Well, in the company, Parkyeri, we have restarted to a crusade to cover all the code lines we had by writing unit tests.
As a PHP Developer, I&#8217;m taking the part where I have to write PHPUnit, the xUnit family which is developed for the PHP language. I had used it in the first version for [...]]]></description>
			<content:encoded><![CDATA[<p>Well, in the company, <a href="http://www.parkyeri.com" target="_blank">Parkyeri</a>, we have restarted to a crusade to cover all the code lines we had by writing unit tests.</p>
<p>As a <a href="http://www.php.net" target="_blank">PHP</a> Developer, I&#8217;m taking the part where I have to write <a href="http://www.phpunit.de" target="_blank">PHPUnit</a>, the xUnit family which is developed for the PHP language. I had used it in the first version for a while, but I had seen that it had reached to the <strong>3rd</strong> version. As I&#8217;m someone who likes to use the latest things and demos, I tried the latest version and migrated all the first version unit tests to the latest version, which was surprisingly, very easy. You just have to change some class inheritance, delete some constructors, and you are nearly done.</p>
<p>The next part is to run the tests you have written, the best way, of course, is to use the <a href="http://www.phpunit.de/manual/3.3/en/phpunit-book.html#textui" target="_blank">CLI for PHPUnit</a>. But as the Debian repositories does not include phpunit3, I can&#8217;t use CLI and I have to use something else.</p>
<p>So this is where we start to have trouble. I was thinking to show them on the browser but problems insisted. I will mention on them later. Let&#8217;s first create a testcase and then create a file to run my testcase. My testcase file is named <strong>ParkyeriTest.php</strong>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="php php" style="font-family:monospace;">&nbsp;
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;PHPUnit/Framework/TestCase.php&quot;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> ParkyeriTest <span style="color: #000000; font-weight: bold;">extends</span> PHPUnit_Framework_TestCase <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">function</span> testMe<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span>;
                <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assertEquals</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">function</span> testMeToo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span>;
                <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assertEquals</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>This will be our testcase. There is one test which fails and there is one which does not. The file will be called <strong>AllTests.php</strong>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//Add the testcase you have created</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="">'ParkyeriTest.php'</span><span style="color: #009900;">&#41;</span>;
<span style="color: #666666; font-style: italic;">//Don't miss to add TestSuite as we will instanciate it..</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="">'PHPUnit/Framework/TestSuite.php'</span><span style="color: #009900;">&#41;</span>;
<span style="color: #666666; font-style: italic;">//And of course your own listener</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="">'myListener.php'</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000088;">$suite</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PHPUnit_Framework_TestSuite<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>; <span style="color: #666666; font-style: italic;">//Create the instances</span>
<span style="color: #000088;">$mLis</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> myListener<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PHPUnit_Framework_TestResult<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>; 
<span style="color: #000088;">$suite</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addTestSuite</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ParkyeriTest&quot;</span><span style="color: #009900;">&#41;</span>; <span style="color: #666666; font-style: italic;">//Add your test case to the test suite</span>
<span style="color: #000088;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addListener</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mLis</span><span style="color: #009900;">&#41;</span>; <span style="color: #666666; font-style: italic;">//Define your listener which the test result will use to give output</span>
<span style="color: #000088;">$suite</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">run</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span>; <span style="color: #666666; font-style: italic;">//And of course run this tests</span>
<span style="color: #666666; font-style: italic;">//That's all buddies....</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>So you see that I have included <strong>my test case file</strong> and some <strong>PHPUnit files</strong>. I have created a <strong>TestSuite</strong> which will hold my <strong>TestCase</strong> and which will run it.</p>
<p>You see I have created a class named <strong>myListener</strong>. This class <strong>implements</strong> <strong>PHPUnit_Framework_TestListener</strong> and <strong>extends PHPUnit_Util_Printer</strong>. It implements TestListener because as a listener he has some jobs to do and this interface defines them, which are most basically things like addError(), addFailure() or startTest(). You will see them in the code block below. Let&#8217;s continue what we have done once we have instanciated our listener. We create another object <strong>PHPUnit_Framework_TestResult which holds the results</strong> of the test results. Also it allows you to listen the current process of the tests. I won&#8217;t mention the details of the TestResult, you can find them in <a href="http://www.phpunit.de/manual/3.3/en/phpunit-book.html#api.testresult" target="_blank">PHPUnit Documentation</a>.</p>
<p>And the rest is to add a listener to your results and then run the test suite. While the test suite ruins, you will se the output of your listener, as the execution progress. Now our listener&#8217;s file name is <strong>myListener.php</strong>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
</pre></td><td class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">require_once</span> <span style="">'PHPUnit/Framework.php'</span>;
<span style="color: #b1b100;">require_once</span> <span style="">'PHPUnit/Util/Filter.php'</span>;
<span style="color: #b1b100;">require_once</span> <span style="">'PHPUnit/Util/Printer.php'</span>;
<span style="color: #b1b100;">require_once</span> <span style="">'PHPUnit/Util/Test.php'</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">//This part may confuse you. The only thing is, PHPUnit also contains a covered code part</span>
<span style="color: #666666; font-style: italic;">//This line tells the PHPUnit to exclude it from code coverage things.</span>
<span style="color: #666666; font-style: italic;">//At least that's what I understood :)</span>
PHPUnit_Util_Filter<span style="color: #339933;">::</span><span style="color: #004000;">addFileToFilter</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">__FILE__</span><span style="color: #339933;">,</span> <span style="">'PHPUNIT'</span><span style="color: #009900;">&#41;</span>;
<span style="color: #0000ff; font-style: italic;">/**
 *
 * The class is defined. It inherites methods and attributes from PHPUnit_Util_Printer
 *  and alsoimplements PHPUnit_Framework_TestListener.
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> myListener <span style="color: #000000; font-weight: bold;">extends</span> PHPUnit_Util_Printer implements PHPUnit_Framework_TestListener <span style="color: #009900;">&#123;</span>
    protected <span style="color: #000088;">$currentTestSuiteName</span> <span style="color: #339933;">=</span> <span style="">''</span>;
    protected <span style="color: #000088;">$currentTestName</span> <span style="color: #339933;">=</span> <span style="">''</span>;
    protected <span style="color: #000088;">$currentTestPass</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">TRUE</span>;
    <span style="color: #0000ff; font-style: italic;">/**
     * Triggered when an error occurs on the test case
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> addError<span style="color: #009900;">&#40;</span>PHPUnit_Framework_Test <span style="color: #000088;">$test</span><span style="color: #339933;">,</span> Exception <span style="color: #000088;">$e</span><span style="color: #339933;">,</span> <span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">writeCase</span><span style="color: #009900;">&#40;</span>
          <span style="">'error'</span><span style="color: #339933;">,</span>
          <span style="color: #000088;">$time</span><span style="color: #339933;">,</span>
          <span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#41;</span>;
&nbsp;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">currentTestPass</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">FALSE</span>;
    <span style="color: #009900;">&#125;</span>
    <span style="color: #0000ff; font-style: italic;">/**
     * Triggered when one of the unit tests fails.
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> addFailure<span style="color: #009900;">&#40;</span>PHPUnit_Framework_Test <span style="color: #000088;">$test</span><span style="color: #339933;">,</span> PHPUnit_Framework_AssertionFailedError <span style="color: #000088;">$e</span><span style="color: #339933;">,</span> <span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">writeCase</span><span style="color: #009900;">&#40;</span>
          <span style="">'fail'</span><span style="color: #339933;">,</span>
          <span style="color: #000088;">$time</span><span style="color: #339933;">,</span>
          <span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#41;</span>;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">currentTestPass</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">FALSE</span>;
    <span style="color: #009900;">&#125;</span>
    <span style="color: #0000ff; font-style: italic;">/**
     * Triggered when an incomplete test is encountered. 
     * You have to define the unit test as incomplete to trigger this.
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> addIncompleteTest<span style="color: #009900;">&#40;</span>PHPUnit_Framework_Test <span style="color: #000088;">$test</span><span style="color: #339933;">,</span> Exception <span style="color: #000088;">$e</span><span style="color: #339933;">,</span> <span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">writeCase</span><span style="color: #009900;">&#40;</span><span style="">'error'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$time</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="">'Incomplete Test'</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">currentTestPass</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">FALSE</span>;
    <span style="color: #009900;">&#125;</span>
    <span style="color: #0000ff; font-style: italic;">/**
     * Triggered when an incomplete test is encountered. 
     * You have to define the unit test as to be skipped to trigger this.
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> addSkippedTest<span style="color: #009900;">&#40;</span>PHPUnit_Framework_Test <span style="color: #000088;">$test</span><span style="color: #339933;">,</span> Exception <span style="color: #000088;">$e</span><span style="color: #339933;">,</span> <span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">writeCase</span><span style="color: #009900;">&#40;</span><span style="">'error'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$time</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="">'Skipped Test'</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">currentTestPass</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">FALSE</span>;
    <span style="color: #009900;">&#125;</span>
    <span style="color: #0000ff; font-style: italic;">/**
     * Triggered when a testsuite is started
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> startTestSuite<span style="color: #009900;">&#40;</span>PHPUnit_Framework_TestSuite <span style="color: #000088;">$suite</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">currentTestSuiteName</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$suite</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">currentTestName</span>      <span style="color: #339933;">=</span> <span style="">''</span>;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Started Suite: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">currentTestSuiteName</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; (&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$suite</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; tests)<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
    <span style="color: #0000ff; font-style: italic;">/**
     * Triggered when a test suite ends.
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> endTestSuite<span style="color: #009900;">&#40;</span>PHPUnit_Framework_TestSuite <span style="color: #000088;">$suite</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">currentTestSuiteName</span> <span style="color: #339933;">=</span> <span style="">''</span>;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">currentTestName</span>      <span style="color: #339933;">=</span> <span style="">''</span>;
    <span style="color: #009900;">&#125;</span>
    <span style="color: #0000ff; font-style: italic;">/**
     * Triggered when a testcase starts
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> startTest<span style="color: #009900;">&#40;</span>PHPUnit_Framework_Test <span style="color: #000088;">$test</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">currentTestName</span> <span style="color: #339933;">=</span> PHPUnit_Util_Test<span style="color: #339933;">::</span><span style="color: #004000;">describe</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$test</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">currentTestPass</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">TRUE</span>;
    <span style="color: #009900;">&#125;</span>
    <span style="color: #0000ff; font-style: italic;">/**
     * Triggered when a testcase ends
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> endTest<span style="color: #009900;">&#40;</span>PHPUnit_Framework_Test <span style="color: #000088;">$test</span><span style="color: #339933;">,</span> <span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">currentTestPass</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">writeCase</span><span style="color: #009900;">&#40;</span><span style="">'pass'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #0000ff; font-style: italic;">/**
     * I used this function to give output and not writing everything again and again.
     */</span>
    protected <span style="color: #000000; font-weight: bold;">function</span> writeCase<span style="color: #009900;">&#40;</span><span style="color: #000088;">$status</span><span style="color: #339933;">,</span> <span style="color: #000088;">$time</span><span style="color: #339933;">,</span> <span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
        <span style="color: #000088;">$m</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Test: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">currentTestName</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; - Status: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$status</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; - Time: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$time</span> <span style="color: #339933;">.</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span> ? <span style="color: #0000ff;">&quot; - Message: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$message</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">write</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$m</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>I would have loved to add some PHPDoc, but I did not have much time.</p>
<p>What we have here is; we basically implement, I mean, create some functions that must be created in order to be used as a listener. Once you define this functions, you will decide what you will do with the current result. Basically, let&#8217;s take addFailure() as an example. This function is called whenever a test fails. Then you write what you want to do on that function and it&#8217;s done. You see that I have used another function writeCase(), which basically prints something on the screen by using, <strong>PHPUnit_Util_Printer</strong>&#8217;s write() method. That&#8217;s why we have extended that class, because we had to give an output.</p>
<p>You may find additional listeners in the PHPUnit&#8217;s core of course. Something which will give you an xml output or a json output in <strong>root/PHPUnit/Util/Log</strong> folder.</p>
<p>Don&#8217;t forget to check out <a href="http://www.phpunit.de/manual/3.3/en/phpunit-book.html" target="_blank">PHPUnit&#8217;s Manual</a> and <a href="http://parthpatil.com/2008/05/14/formatting-phpunit-test-results-as-html-table/" target="_blank">here</a> for how to use PHPUnit_Util_Log_XML.</p>
<p>I have used PHPUnit_Util_Log_JSON as a base to my listener class by the way. You may want to check that one too. It had also implemented a complicated stack trace, but I didn&#8217;t need it a lot, as I show which test on which test suite I&#8217;m currently running and it&#8217;s not that hard to find the problem <img src='http://roysimkes.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://roysimkes.net/blog/2008/11/writing-you-own-phpunit-listener/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Netbeans 6.5 and PHP Support</title>
		<link>http://roysimkes.net/blog/2008/11/netbeans-65-and-php-support/</link>
		<comments>http://roysimkes.net/blog/2008/11/netbeans-65-and-php-support/#comments</comments>
		<pubDate>Mon, 10 Nov 2008 17:14:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[IDEs]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://roysimkes.net/blog/?p=50</guid>
		<description><![CDATA[Well, a new feature has been added to Netbeans from now on. With the new release of 6.5, PHP support has been added and now we have an IDE which fully support code complete (including your own classes, methods, functions and variables), PHPDoc abilities(showing doc for your own classes) and, of course, debugger features. It&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Well, a new feature has been added to <a href="http://www.netbeans.org" target="_blank">Netbeans</a> from now on. With the new <a href="http://www.netbeans.org/community/releases/65/" target="_blank">release of 6.5</a>, PHP support has been added and now we have an IDE which fully support code complete (including your own classes, methods, functions and variables), <a href="http://www.phpdoc.org/" target="_blank">PHPDoc</a> abilities(showing doc for your own classes) and, of course, debugger features. It&#8217;s in the RC2 but final release is coming on a week or two.</p>
<p>Netbeans is using <a href="http://xdebug.org/" target="_blank">XDebug</a>, for debugging. All you have to do is add xdebug extension to your php.ini and set some xdebug property like debug port, debug host and alike. There is a good tutorial <a href="http://www.netbeans.org/kb/docs/php/debugging.html" target="_blank">here</a> on the Netbeans wiki page. You can also use that link for a good debug tutorial.</p>
<p>Debugging is quite powerful and easy with Netbeans now. Even there are some missing things. You have to setup a debug profile from properties to be able to debug a url, that&#8217;s annoying. But it&#8217;s on the improvement list as I had learned. Also sometimes breakpoints does not work, even though that I&#8217;m sure that that part of the code is used but not opened as in active editor pane. But it does open closed documents if you use step by step debugging. There is also a javascript debugger, which is installed as a <a href="http://www.getfirefox.com" target="_blank">Firefox</a> plugin. But I did not yet tried that.</p>
<p>Above from debugging feature of Netbeans Xdebug is also great at showing you errors. As a virgin of XDebug I really felt good when I saw the call stack for the current error. Xdebug replaces current error handler of <a href="http://www.php.net" target="_blank">PHP</a> and shows call stack with error.</p>
<p>I guess it will be great. It&#8217;s really lightweight too if you just install PHP and not the rest, it&#8217;s only 24 MB. And code completion is also very useful and successful. The only IDE with support of custom class code completion was <a href="http://www.eclipse.org/pdt/" target="_blank">PDT</a> and of course <a href="http://www.zend.com/en/products/studio/" target="_blank">Zend Studio</a> 6.x (also the lower versions were also supporting that.) which both are basically built on the same code base.</p>
<p>I guess from now on PHP Editor wars will be really great! As PHP grows and becomes more powerful, tools you use to develop it becomes far more powerful. It&#8217;s sad to see that C# had a built in debugger in Visual Studio for years even though it was younger than PHP. But I guess you need to have money to develop these kind of tools. At least we have a one now! And not just a <a href="http://en.wikipedia.org/wiki/Black_Screen_of_Death" target="_blank">black screen</a> debugger and profiler but a GUI with powerful features.</p>
<p>By the way, Fedora is coming too..<br />
<script id="fedora-banner" src="http://fedoraproject.org/static/js/release-counter-ext.js?lang=en" type="text/javascript"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://roysimkes.net/blog/2008/11/netbeans-65-and-php-support/feed/</wfw:commentRss>
		</item>
		<item>
		<title>PHP Namespace Issue</title>
		<link>http://roysimkes.net/blog/2008/11/php-namespace-issue/</link>
		<comments>http://roysimkes.net/blog/2008/11/php-namespace-issue/#comments</comments>
		<pubDate>Mon, 10 Nov 2008 14:05:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Off Topic]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://roysimkes.net/blog/?p=49</guid>
		<description><![CDATA[First of all, I&#8217;m not against it. I do not understand why it does really matter what the namespace separator is.
What kind of difference will it create to use &#8220;/&#8221;, &#8220;\&#8221;, &#8220;:::&#8221;, &#8220;;;;&#8221;, &#8220;{{}}&#8221; or whatever. Well of course that I do not like to use a namespace like &#8220;thisisnamespaceseperator&#8221;. It must be easy to [...]]]></description>
			<content:encoded><![CDATA[<p>First of all, I&#8217;m not against it. I <strong>do not understand</strong> why it does really matter what the namespace separator is.</p>
<p>What kind of difference will it create to use &#8220;/&#8221;, &#8220;\&#8221;, &#8220;:::&#8221;, &#8220;;;;&#8221;, &#8220;{{}}&#8221; or whatever. Well of course that I do not like to use a namespace like &#8220;thisisnamespaceseperator&#8221;. It must be <strong>easy to use</strong>, and when you look at it, you should see that some things are separated. <strong>Why</strong> there are so <strong>much discussion</strong> about it that I do not understand.</p>
<p><strong>Any of them is ok</strong> for me. I can use &#8220;:::&#8221; or &#8220;\&#8221;, what&#8217;s the real matter about it, I <strong>do not</strong> honestly <strong>understand</strong>. I do not think there is <em>huge</em> difference with My:::Class:::Bar() and My\Class\Bar().</p>
<p>Perhaps that because I&#8217;m a rookie, I also do not understand why someone will think to use a new language just because of one decision. I <strong>respect everyone&#8217;s idea</strong> and if it does not look good to you, then you should be using something else. I <strong>hate Python&#8217;s code look</strong>. A programmig language without <strong>{</strong> and <strong>}</strong> <strong>does not look good</strong> to <strong>me</strong>. But I think that if I go over <strong>my prejudice</strong>, I will like it.</p>
<p>I love to write <strong>PHP</strong>. I even love how it&#8217;s written <em>php</em>, with two lines down and one lineup. I love the freedom of being able to write <strong>both OOP and functional</strong> application, I love the <strong>syntax of PHP</strong>, I enjoy <strong>helping people</strong> about PHP, I enjoy joining to seminars, conferences and <strong>community activities</strong>. That&#8217;s the <strong>real power of the PHP</strong>. <strong>Ruby</strong> has also a community but they are <strong>arrogant</strong>, they are doing with the <strong>ruby way</strong> and they feel special. Just like using <strong>Mac instead of a PC</strong>. You don&#8217;t like how the &#8220;\&#8221; looks like, don&#8217;t worry you <strong>will get used to</strong> it.</p>
<p>I don&#8217;t want to say that this namespace seperator is the <strong>php way</strong> of doing things. Because there isn&#8217;t actually such a way. <strong>Eveything is possible</strong> and can be done with PHP (even not much approved). I do not truly know how the php&#8217;s source code is written, so if the separator causes a lot of trouble, <strong>maybe &#8220;\&#8221; is not the best of choice</strong>, maybe people are right that this won&#8217;t be an issue for the current release but you are <strong>ruining the maintainability</strong> of the code with these. <strong>Maybe</strong> they are <strong>right</strong>. But that&#8217;s a <strong>balance</strong> issue more than anything. If you have so much <strong>performance problem</strong>, that <strong>write</strong> your code on <strong>assembly</strong> and you will get the <strong>best performace</strong> you can have.</p>
<p>I hope that this issue will be forgotten with the new release, but I don&#8217;t think so. Some people may even <a href="http://www.suspekt.org/2008/10/31/php-got-forked/" target="_blank">fork</a> PHP and create <strong>a new</strong> language <strong>myPHP</strong>. I hope that won&#8217;t be the case. The <strong>decision is made</strong>, and your <em>whining</em> may not change this. What we should do, is to <strong>respect the decision</strong> and <strong>keep trying to improve PHP</strong> and if we really <strong>really</strong> want to <strong>change</strong> this, try to <strong>influence</strong> the decision for <strong>PHP 6</strong> with <strong>facts</strong>. Do not talk about <strong>speculations</strong> but <strong>actual facts</strong>. I used this and that happened, if we had used this this would be better and else. But I think this can&#8217;t happen till new release.</p>
]]></content:encoded>
			<wfw:commentRss>http://roysimkes.net/blog/2008/11/php-namespace-issue/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Even Garanti make mistakes</title>
		<link>http://roysimkes.net/blog/2008/11/even-garanti-make-mistakes/</link>
		<comments>http://roysimkes.net/blog/2008/11/even-garanti-make-mistakes/#comments</comments>
		<pubDate>Fri, 07 Nov 2008 12:13:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Off Topic]]></category>

		<guid isPermaLink="false">http://roysimkes.net/blog/?p=48</guid>
		<description><![CDATA[
Today I have witnessed a problem at Garanti&#8217;s website. It looks like even Garanti can mess things up sometimes.
As you may know there is a financial crysis in the world and stocks and foreign currencies changes a lot. But who would have known that USD and EUR might change this much 
]]></description>
			<content:encoded><![CDATA[<p><a href="http://roysimkes.net/blog/garanti.JPG"><img class="alignleft" src="http://roysimkes.net/blog/garanti.JPG" alt="Bug on Garanti Website" width="359" height="196" /></a></p>
<p>Today I have witnessed a problem at <a href="http://www.garanti.com.tr">Garanti</a>&#8217;s website. It looks like even Garanti can mess things up sometimes.</p>
<p>As you may know there is a financial <a href="http://www.ea.com/crysis/" target="_blank">crysis</a> in the world and stocks and foreign currencies changes a lot. But who would have known that USD and EUR might change this much <img src='http://roysimkes.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://roysimkes.net/blog/2008/11/even-garanti-make-mistakes/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to SVN Diff Ignoring white spaces</title>
		<link>http://roysimkes.net/blog/2008/10/how-to-svn-diff-ignoring-white-spaces/</link>
		<comments>http://roysimkes.net/blog/2008/10/how-to-svn-diff-ignoring-white-spaces/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 11:15:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Off Topic]]></category>

		<category><![CDATA[Parkyeri]]></category>

		<guid isPermaLink="false">http://roysimkes.net/blog/?p=47</guid>
		<description><![CDATA[That&#8217;s some of the things I started to encounter a lot about this thing. A diff without whitespaces. It creates a big confusion to understand and review the patch. So I searched a bit. I had used it once a time, but was forgeting a lot. That&#8217;s a post a to remember it anyway  [...]]]></description>
			<content:encoded><![CDATA[<p>That&#8217;s some of the things I started to encounter a lot about this thing. A diff without whitespaces. It creates a big confusion to understand and review the patch. So I searched a bit. I had used it once a time, but was forgeting a lot. That&#8217;s a post a to remember it anyway <img src='http://roysimkes.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>By using an external diff tool you can take a whitespace ignored diff by using:</p>
<p><strong>svn diff &#8211;diff-cmd diff -x -uwBEb</strong></p>
<p>There is a double &#8220;-&#8221; before diff-cmd but it looks like as a one I don&#8217;t know why.</p>
<p>This command will use the unix system&#8217;s diff command with arguments -uwBeb which has something to do white ignoring all type of white spaces.</p>
<p>Well during my research I have found out even the external diff programs were available to use, in the <a href="http://subversion.tigris.org/" target="_blank">Subversion</a>&#8217;s core libraries this option was available. This enhancement <a href="http://subversion.tigris.org/issues/show_bug.cgi?id=2121" target="_blank">had been checked in</a> some time ago and was intended to be added to 1.4.6 or something like that. <a href="http://subversion.tigris.org/svn_1.5_releasenotes.html" target="_blank">1.5</a> had came anyway but it seems that it doesn&#8217;t quite really works. At least I was not able to find something useful the <strong>-w</strong> was still ignored! But somehow I was able to take a whitespace ignored diff via <a href="http://tortoisesvn.net/" target="_blank">TortoiseSVN</a>. I&#8217;m not yet sure if this is an external ability it does use an svn diff&#8217;s core ability or not. I assume that it had something to do with merge and blame commands. Perhaps there is a trick I don&#8217;t know that by using these commands you can take a white space ignored diff</p>
]]></content:encoded>
			<wfw:commentRss>http://roysimkes.net/blog/2008/10/how-to-svn-diff-ignoring-white-spaces/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to Customize Magento Product Page</title>
		<link>http://roysimkes.net/blog/2008/09/how-to-customize-magento-product-page/</link>
		<comments>http://roysimkes.net/blog/2008/09/how-to-customize-magento-product-page/#comments</comments>
		<pubDate>Tue, 16 Sep 2008 13:03:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Magento]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Parkyeri]]></category>

		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://roysimkes.net/blog/?p=42</guid>
		<description><![CDATA[I&#8217;m back with another tutorial about Magento. I&#8217;m not the best man you can find about Magento. But I&#8217;m trying to learn something from forums. The best you learn something is when you can explain it to someone else. So this is for that!
As I had mentioned in my previous post Magento is an open [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m back with another tutorial about Magento. I&#8217;m not the best man you can find about <a href="http://www.magentocommerce.com/boards/viewthread/3698/P0/" target="_blank">Magento</a>. But I&#8217;m trying to learn something from <a href="http://www.magentocommerce.com/boards" target="_blank">forums</a>. The best you learn something is when you can explain it to someone else. So this is for that!</p>
<p>As I had mentioned in <a href="http://roysimkes.net/blog/2008/09/using-custom-php-codes-on-magento/" target="_blank">my previous post</a> Magento is an open source ecommerce application made with <a href="http://www.php.net" target="_blank">PHP</a> and <a href="http://framework.zend.com" target="_blank">Zend Framework</a>. Company behind it is very dedicated to this project and works a lot about it. But the missing part is the tutorials I guess. There isn&#8217;t enough entry in their <a href="http://www.magentocommerce.com/wiki/" target="_blank">wiki</a> and if you want to learn something, you have find it out yourself. So let&#8217;s begin!</p>
<p>This tutorial will cover basics about how you can find your way in the magento code and get to the right place and how you can change a product&#8217;s page design by changing the place of the images from left to right.</p>
<p>I tried this on Magento version 1.1.3 and it worked. Check <a href="http://www.magentocommerce.com/download">here</a> for the latest version.</p>
<p>First of all we have to understand which part of the code does show the product&#8217;s detail page. You can guess of course. But don&#8217;t do it and open the Magento folder. Navigate to <strong>/app/code/core/Mage/</strong>. Then you will see.</p>
<p>No I mean it, really! Go and look on that folder! So your best bet will be the <strong>Catalog</strong> folder. So is mine. So I enter the folder and look for things which can suit me. Well As I&#8217;m a bit familiar with Magento and I know that they have mostly separated the logic and design. So there must be somewhere where this binding must have been done. So the people who has read the previous post and people who are familiar with Unix systems, they must have noticed the <strong>etc/</strong>. Yes this is the folder you are looking for. In it, there is the configuration file: <strong>config.xml</strong>. Not that hard to find I guess. Now the real problem is to find out, what is related with what?</p>
<p>config.xml is a huge file and if you don&#8217;t know what you are looking for you are in a bit of troube but don&#8217;t be afraid. Let&#8217;s cover the details a bit and make an understanding. In my previous post I had entered some information about modules&#8217; configuration files. But it was a small file and let&#8217;s say I knew what I had to write. So let&#8217;s look under the hood. For people who does not want to see how the engine works, the file you are looking for is <strong>/app/design/frontend/default/default/layout/catalog.xml</strong>. (Maybe instead of looking to code I should have checked folders better <img src='http://roysimkes.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>There is a version info, ok. There is an admin part, which does not mean a lot to you nor to me. Maybe it&#8217;s something fatal but it doesn&#8217;t mean a lot for us (Nothing more than a newbie I&#8217;m). So the next part I&#8217;m more comfortable, as I understand what it belongs to. Well first of all, we know that this part is <strong>global</strong>. It will be used for all the parts where this module is being used. And the next part is <strong>models. </strong>This is about database fields. You can see that, below the models, there is the definition of a <strong>resourceModel</strong> to a <strong>class</strong>. This means the class defined in this config, will use that resourceModel. But what is this model? Next part is this. You see that the name of the resourceModel (catalog_resource_eav_mysql4 for me) starts now and a lot things is defined. Classes (let&#8217;s say the database&#8217;s driver folder) and database tables related to this resourceModel are listed here. It basically says that, this attribute comes from this table. You can be shocked by the count but open your <a href="http://www.phpmyadmin.net" target="_blank">phpmyadmin</a> and you will see that there are <strong>192</strong> tables in it. Ouch! The only important part is that (if you don&#8217;t want to change the core aspects of course), if you are stuck which table is what, you can always look to these configuration files and find out which table is related to which module. A bit confusing but better than nothing.</p>
<p>Forget about the database and let&#8217;s keep going on the config file. Passing to models we come to the resources part. I guess this is about what connections will be used for querying and other things. You see that in <strong>catalog_read</strong>, there is a connection value and this is <strong>core_read</strong>. You may guess that it defines which connection this database drivers will use, comes from here. You are right, probably. But I&#8217;m not sure, and it doesn&#8217;t look I need this part to change the place of the picture, so I move on.</p>
<p>And now comes the block part. This isn&#8217;t new and I&#8217;m happy to see something that I know from my previous experience. In CMS pages, this part of the configuration had helped me to get to the layout so this might be the part where the output is given. So I get to the <strong>/app/code/core/Mage/Catalog/Block/</strong> there are some parts about products but this is the backend part as I see. There isn&#8217;t any meaningful htmls in files which are in that folder. So I had a hope that I had found it, but it seems that this is not the case yet. So I move on.</p>
<p>Now a part that I do not even have slightest idea comes and I pass. The next part is <strong>adminhtml</strong>. I mean HTML! This can be it! There are some definitions about some things but I do not get it. There is a folder <strong>/app/design/adminhtml/default/default/</strong> in the file system. And these bindings refer to the <strong>template</strong> folder. I assume there are some language additions and some other tweaks about admin pages. But again, I&#8217;m not sure.</p>
<p>Finally I have reached the <strong>frontend</strong> part. I&#8217;m now sure that this is the part I&#8217;m looking, as there are language definitions, per_page_values and <strong>layout</strong>! There are some things which still I do not get what are they for, but I see the <strong>catalog.xml. </strong>And this my best bet! I open the file and I see: <strong>Default layout, loads most of the pages! </strong>Yes I found it!</p>
<p>Below that part, there are things which are not much useful to me, things like url rewrites and some more configuration values. You can alter the general layout of Magento by changing these options by the way (As this module is about catalogs, the general view of catalogs of course, not the payment part!).</p>
<p>catalog.xml is a file familiar to me. From my previous post I knew there was something about blocks defining somewhere and this is it! There are blocks here and I follow the comments and finds <strong>Product View</strong>.</p>
<p><strong>&lt;block type=&#8221;catalog/product_view&#8221; name=&#8221;product.info&#8221; template=&#8221;catalog/product/view.phtml&#8221;&gt;</strong></p>
<p>This was the part I was looking for all the time. You see the template part?. It refers to <strong>/app/design/frontend/default/default/template/catalog/product/view.phtml</strong>. So I go there open the file and yes htmls!!! <strong>product-img-box</strong> line is very meaningful what I&#8217;m looking for and it has a css class. I make a file search between files and I find <strong>/skin/frontend/default/default/css/boxes.css</strong>. The product-img-box is defined in it and I change the <strong>float:left;</strong> to <strong>float:right;</strong>.</p>
<p>I open <a href="http://www.getfirefox.com" target="_blank">my web browser</a>, open a product page and see that images are at right and not at left. You may have been more lucky if you just looked with <a href="http://getfirebug.com/" target="_blank">firebug</a> and saw the css and changed to it. But you wouldn&#8217;t had gained the insight you would have gained with this.</p>
<p>I hope that this was helpful. I&#8217;m not an expert on Magento. This <a href="http://www.magentocommerce.com/wiki/how_to_create_a_featured_product#step_4_extend_mage_catalog_block_category_view" target="_blank">article</a> on Magento wiki helped me to figure out something. My previous post&#8217;s references were also valid. Do not forget to keep watching <a href="http://www.magentocommerce.com/wiki" target="_blank">Magento Wiki</a> and <a href="http://www.magentocommerce.com/boards/" target="_blank">Magento Forums</a> for best resources about Magento.</p>
]]></content:encoded>
			<wfw:commentRss>http://roysimkes.net/blog/2008/09/how-to-customize-magento-product-page/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Now I look different!</title>
		<link>http://roysimkes.net/blog/2008/09/now-i-look-different/</link>
		<comments>http://roysimkes.net/blog/2008/09/now-i-look-different/#comments</comments>
		<pubDate>Mon, 15 Sep 2008 13:22:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Off Topic]]></category>

		<category><![CDATA[myLife.show()]]></category>

		<guid isPermaLink="false">http://roysimkes.net/blog/?p=41</guid>
		<description><![CDATA[Well, I was loving my old template but something was missing and I figured out that, even the black background was great, I still love it, it was not that easy to read on white/gray textes over black backgrounds. It was kind of boring after a while.
So I had decided to find a new template [...]]]></description>
			<content:encoded><![CDATA[<p>Well, I was loving my old template but something was missing and I figured out that, even the black background was great, I still love it, it was not that easy to read on white/gray textes over black backgrounds. It was kind of boring after a while.</p>
<p>So I had decided to find a new template to my site and I found this one! Still with black backgrounds but it&#8217;s easier to read, and lots bold textes are not disappeared!</p>
<p>I hope that it looks better, at least it&#8217;s something different now.</p>
]]></content:encoded>
			<wfw:commentRss>http://roysimkes.net/blog/2008/09/now-i-look-different/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using Custom PHP Codes on Magento</title>
		<link>http://roysimkes.net/blog/2008/09/using-custom-php-codes-on-magento/</link>
		<comments>http://roysimkes.net/blog/2008/09/using-custom-php-codes-on-magento/#comments</comments>
		<pubDate>Fri, 05 Sep 2008 16:22:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Magento]]></category>

		<category><![CDATA[Parkyeri]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Web - Internet]]></category>

		<guid isPermaLink="false">http://roysimkes.net/blog/?p=40</guid>
		<description><![CDATA[Magento is one of the newest and awarded ecommerce application right now. And I seem to have a project launched nowadays about it.
Above the ecommerce part like adding/modifying products, it also has a built-in CMS. It looks quite useful. Not very powerful though.  It just evaluates html code and not php. In most of the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.magentocommerce.com">Magento</a> is one of the newest and awarded ecommerce application right now. And I seem to have a project launched nowadays about it.</p>
<p>Above the ecommerce part like adding/modifying products, it also has a <strong>built-in CMS</strong>. It looks quite useful. Not very powerful though.  It just evaluates html code and<strong> not php</strong>. In most of the time this is prefered by the way. Because of security risks and things like that. But there are also cases which you want to do if you are importing something to magento or if you are just wanting to do in a quick and dirty way!</p>
<p>Well, the workarounds you find are not quite good. Simply they just take the CMS code, <strong>write it to a temporary file and include it</strong>, or writing a bit <strong>complicated parser</strong> inspired from joomla/mambo. Check out <a href="http://www.magentocommerce.com/boards/viewthread/3698/P0/">here</a> for the details of the workaround. The tutorial I&#8217;m putting here is from there to, however I will also try to write solutions to <strong>problems</strong> that I have encountered (mostly because of <strong>magento versions</strong>).</p>
<p>This tutorial is working for magento version 1.1.3. You can download the latest version from <a href="http://www.magentocommerce.com/download">here</a>.</p>
<p>Now open up your favorite php/xml/html editor. While it will open up, also open your magento installation folder. Magento has a lots of folders for lots of things, which I do not know why. The <strong>code part is in app/</strong> directory as you may guess. In the app folder you will find the <strong>etc/ where there are configurations</strong> for magento generally. Our PHP Code will be <strong>a module</strong> to the Magento, so we have to go modules directory and create a new xml file, named according to your module. The syntax is like: Parkyeri_customPHP. The first part till underscore means the name of the module, int this case <strong>Parkyeri. </strong>The second part indicates the component of the module. So you may have different components in one module, in this case <strong>customPHP,</strong> If we are talking about custom codded PHP pages, so in this module named Parkyeri, there can be different pages like: About, Contact, Jobs. And these are all different components, doing different things. If we were trying to create the <strong>About</strong> page then we had to use something like <strong>Parkyeri_About</strong>. You can add all of them in the same xml file.</p>
<p>Open up <strong>/app/etc/modules/</strong> and create a file named <strong>Parkyeri.xml</strong> (the name of the module) and add these lines to file:</p>
<div class="codeblock"><code> <span style="color: #0000bb;">&lt;?xml version</span><span style="color: #007700;">=</span><span style="color: #dd0000;">&#8220;1.0&#8243;</span><span style="color: #0000bb;">?&gt;<br />
</span><span style="color: #007700;">&lt;</span><span style="color: #0000bb;">config</span><span style="color: #007700;">&gt;<br />
&lt;</span><span style="color: #0000bb;">modules</span><span style="color: #007700;">&gt;<br />
&lt;</span><span style="color: #0000bb;">Parkyeri_customPHP</span><span style="color: #007700;">&gt;<br />
&lt;</span><span style="color: #0000bb;">active</span><span style="color: #007700;">&gt;</span><span style="color: #0000bb;">true</span><span style="color: #007700;">&lt;/</span><span style="color: #0000bb;">active</span><span style="color: #007700;">&gt;<br />
&lt;</span><span style="color: #0000bb;">codePool</span><span style="color: #007700;">&gt;</span><span style="color: #0000bb;">local</span><span style="color: #007700;">&lt;/</span><span style="color: #0000bb;">codePool</span><span style="color: #007700;">&gt;<br />
&lt;/</span><span style="color: #0000bb;">Parkyeri_customPHP</span><span style="color: #007700;">&gt;<br />
&lt;/</span><span style="color: #0000bb;">modules</span><span style="color: #007700;">&gt;<br />
&lt;/</span><span style="color: #0000bb;">config</span><span style="color: #007700;">&gt;</span> </code></div>
<p>But what this means? You declare a new module named Parkyeri to the global site by naming the file Parkyeri.xml. Then you define in the module config file that, this module has a component named customPHP. You say that this component is active and the system can find it in the <strong>app/code/local</strong> directory by looking at the codepool</p>
<p>As you get it now we pass to the next stage. Now open up <strong>app/code/local/Parkyeri/customPHP/etc/ </strong>and create a file named <strong>config.xml </strong>(the default configuration file name for every module.) and add these lines in it.</p>
<div class="codeblock"><code> <span style="color: #0000bb;">&lt;?xml version</span><span style="color: #007700;">=</span><span style="color: #dd0000;">&#8220;1.0&#8243;</span><span style="color: #0000bb;">?&gt;<br />
</span><span style="color: #007700;">&lt;</span><span style="color: #0000bb;">config</span><span style="color: #007700;">&gt;<br />
&lt;global&gt;<br />
&lt;</span><span style="color: #0000bb;">blocks</span><span style="color: #007700;">&gt;<br />
&lt;</span><span style="color: #0000bb;">parkyeri_customphp</span><span style="color: #007700;">&gt;<br />
&lt;class&gt;</span><span style="color: #0000bb;">Parkyeri_customPHP_Block</span><span style="color: #007700;">&lt;/class&gt;<br />
&lt;/</span><span style="color: #0000bb;">parkyeri_customphp</span><span style="color: #007700;">&gt;<br />
&lt;/</span><span style="color: #0000bb;">blocks</span><span style="color: #007700;">&gt;<br />
&lt;/global&gt;<br />
&lt;/</span><span style="color: #0000bb;">config</span><span style="color: #007700;">&gt;</span> </code></div>
<p>What does it mean? This is more of a mapping file than a configuration file. What you are doing here is to <strong>map</strong> (you may also think <strong>bind</strong>) a class named <strong>Parkyeri_customPHP_Block</strong> to a block called <strong>parkyeri_customphp</strong>. So whenever a block of type parkyeri_customphp will be called, this block will look out for the class you defined in this configuration/mapping/binding file. But also you are defining the location of the component files that you want to call. In most of the cases, you want to call a component&#8217;s block from a module. So when calling you will say that I want a component named <strong>customPHP</strong>, and a block named <strong>test</strong> and this component is under the module <strong>Parkyeri</strong>. We move on&#8230;</p>
<p>Now the fun part, open up <strong>app/code/local/Parkyeri/customPHP/Block</strong> and create a file named <strong>Test.php</strong> and add these lines in it:</p>
<div class="codeblock"><code> <span style="color: #0000bb;">&lt;?php</p>
<p></span><span style="color: #007700;">class </span><span style="color: #0000bb;">Parkyeri_customPHP_Block_Test </span><span style="color: #007700;">extends </span><span style="color: #0000bb;">Mage_Core_Block_Abstract<br />
{<br />
</span><span style="color: #007700;">protected function </span><span style="color: #0000bb;">_toHtml</span><span style="color: #007700;">()<br />
</span><span style="color: #0000bb;">{<br />
</span><span style="color: #ff8000;">// put here your custom PHP code with output in $html;<br />
// use arguments like $this-&gt;getMyParam1() , $this-&gt;getAnotherParam()</span></code></div>
<div class="codeblock"><code><span style="color: #ff8000;"> </span></code><code><span style="color: #0000bb;">$html = &#8220;Hello&#8221; . $this-&gt;getWorld()</span><span style="color: #007700;">;</span></code></div>
<div class="codeblock"><code><span style="color: #007700;">return </span><span style="color: #0000bb;">$html</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">}<br />
}</span> </code></div>
<p>So, we have finally reached the part which you are most comfortable, writing code! You will write down all the code you want to evaluate in this file. The <strong>_toHtml()</strong> method is called when you call it in the cms part. A magical function just like toString(). As you may remark the name of the class, is conventional according to the location of the class. That was how the previous configuration knew where to look when mapping.</p>
<p>And the final part is to embed it in the CMS, this is easy part. But the part where you get dissapointed most. Add this to page you want to show your custom php code:</p>
<p><strong>{{block type=&#8221;parkyeri_customphp/test&#8221; world=&#8221;World&#8221;}}</strong></p>
<p>So, it&#8217;s obvious isn&#8217;t it? In this code part, you say that, you want to put a <strong>block</strong> here. The type of this block is <strong>parkyeri_customphp/test</strong>. So actually you want a block named <strong>test</strong> under the <strong>customphp</strong> component which also a part of <strong>parkyeri</strong> module.  But you may be curious of the rest, on what I mean by saying, <strong>world</strong>. I&#8217;m sending a parameter to the class. Remember the code where there was <strong>$this-&gt;getWorld()</strong>. This world is that world!. So the code will print out &#8220;Hello World&#8221; (without an exclamation).<br />
So this was it! Did it worked? No I didn&#8217;t did it? The real reason that it did not worked, is because, you did not <strong>refresh</strong> the <strong>caching system</strong>!! Yes, it&#8217;s that simple! It gave me a lots of headache though, hope it won&#8217;t to you. You can disable the caching from <strong>System -&gt; Cache Management</strong> by the way.  Better then refreshing every time <img src='http://roysimkes.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
If you are stuck on somewhere you should really check out <a href="http://www.magentocommerce.com/boards" target="_blank">magento forums</a>. There are really helpful people out there from real developers, ceos and community experts.</p>
]]></content:encoded>
			<wfw:commentRss>http://roysimkes.net/blog/2008/09/using-custom-php-codes-on-magento/feed/</wfw:commentRss>
		</item>
		<item>
		<title>MySQL Full Text Search instead of LIKE</title>
		<link>http://roysimkes.net/blog/2008/09/mysql-fts-instead-like/</link>
		<comments>http://roysimkes.net/blog/2008/09/mysql-fts-instead-like/#comments</comments>
		<pubDate>Wed, 03 Sep 2008 13:27:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://roysimkes.net/blog/?p=39</guid>
		<description><![CDATA[There are lots of information in the internet which you can find about full text search syntax of MySQL. A good tutorial is of course in the MySQL&#8217;s Documentation.The other informations you find are coming from there generally.
But something is missing. How can I make regular expression search using full text search engine! As the [...]]]></description>
			<content:encoded><![CDATA[<p>There are lots of information in the internet which you can find about full text search syntax of MySQL. A good tutorial is of course in the <a href="http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html" target="_blank">MySQL&#8217;s Documentation</a>.The other informations you find are coming from there generally.</p>
<p>But something is missing. How can I make regular expression search using full text search engine! As the rich web interface things and other WEB 2.0 called web sites are increasing the usage of javascript and JSON is also increasing. Most of AJAX requests are now returning JSON datas and they are formatted in the javascript.</p>
<p>Well as the usage of json is increased, I also thing that some people, like me, are started to keep data as json in their databases. Of course that I do not mean that instead of keeping database rows, keep json text files.</p>
<p>Well but as this is the thing, I&#8217;m a bit confused how to filter this data. How do you get a row with something like this in it&#8217;s json data: &#8220;foo&#8221;:&#8221;bar&#8221;.</p>
<p>Many will think that that&#8217;s possible like this:</p>
<p>SELECT * FROM foo WHERE bar LIKE &#8216;%&#8221;foo&#8221;:&#8221;bar&#8221;%&#8217;;</p>
<p>Of course that this is a solution, and it will return to you the data you want! But what about performance. You may increase this performance! This is not a linear performance increase though. When you will start to deal with then thousands of rows, the search will be slower and slower. At least this was what I was thinkinh.</p>
<p>Well I tried to do my own benchmark tests which you can think that they were pathetic, with my phpmyadmin and mysql 5 on my local server. My test data was a table with 2500+ plus rows and the results returning were 500+. And you know that, the execution times didn&#8217;t changed a lot. They were approximately the same. The field which I was looking had a fulltext index of course, maybe this had affected a lot. Maybe someone else will. This maybe because of the pattern I was looking for. As I was looking for json formatted data, instead of json formatting, if I had just searched &#8216;%bar%&#8217; things would be different.</p>
<p>Any ideas?</p>
]]></content:encoded>
			<wfw:commentRss>http://roysimkes.net/blog/2008/09/mysql-fts-instead-like/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Still Going on Boop</title>
		<link>http://roysimkes.net/blog/2008/09/still-going-on-boop/</link>
		<comments>http://roysimkes.net/blog/2008/09/still-going-on-boop/#comments</comments>
		<pubDate>Mon, 01 Sep 2008 15:52:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Boop]]></category>

		<category><![CDATA[OS]]></category>

		<guid isPermaLink="false">http://roysimkes.net/blog/?p=37</guid>
		<description><![CDATA[I don&#8217;t know why but I&#8217;m still working on this project of mine Boop. I guess I will change it&#8217;s name from boop to Boo Project! It sounds better.
Well but of course you expect of me to what have I done. I have setup an svn server. First it was just a local copy but [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know why but I&#8217;m still working on this project of mine Boop. I guess I will change it&#8217;s name from boop to Boo Project! It sounds better.</p>
<p>Well but of course you expect of me to what have I done. I have setup an svn server. First it was just a local copy but now it&#8217;s worldwide open. And another thing is that I have setup a trac too. A good project management tool which is integrated with svn. It has lots of &#8220;hacks&#8221;, but I did not yet installed any of them. It seems enough for me, for now.</p>
<p>To install a svn server and put trac on it all you need is a debian installed computer and http://trac.edgewall.org/wiki/TracOnDebianSarge link. It&#8217;s really really helpful. I had to install 4 or 5 times svn and trac and what I learned is, you can just copy paste everything and then from trac-admin run resync command, everything goes back from the point where you have taken the backup. You have to copy paste to previous directories of course.</p>
<p>Wiki thing is good and it forces me to write down what I think about and what I will do about. I hope some of my friends will start working on it soon or I won&#8217;t be successful enough to finish it. But thanks tou tickets, I know what I will do.</p>
<p>Well I was hoping to put a demo link, and the site&#8217;s link is this but I guess it&#8217;s not ready yet. Even it&#8217;s doing much of what it&#8217;s intended for, it&#8217;s still not enough.</p>
<p>But keep waiting.</p>
]]></content:encoded>
			<wfw:commentRss>http://roysimkes.net/blog/2008/09/still-going-on-boop/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
