<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Subversion hook php framework</title>
	<atom:link href="http://www.devhands.com/2010/01/subversion-hook-php-framework-in/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.devhands.com/2010/01/subversion-hook-php-framework-in/</link>
	<description>Inspired by consistent circumstances</description>
	<lastBuildDate>Tue, 17 Aug 2010 10:08:38 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
	<item>
		<title>By: Adam</title>
		<link>http://www.devhands.com/2010/01/subversion-hook-php-framework-in/comment-page-1/#comment-10869</link>
		<dc:creator>Adam</dc:creator>
		<pubDate>Mon, 22 Mar 2010 00:48:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.devhands.com/?p=422#comment-10869</guid>
		<description>Thanks for the reply Aleksandr... I&#039;m looking forward to the updates! You&#039;re right about using php_check_syntax() and that was the way I had initially developed the test, but I quickly found out that the function was removed in php 5.0.5. The php manual says to use &quot;php -l ...&quot; instead, so the extra grunt work was needed =\

There was one other change I had to make to CommitTests.php because of our environment. &quot;svnlook&quot; is not part of the user&#039;s path... so the change adds a path to svnlook:
public static $SVNLOOK = &quot;/usr/local/subversion/bin/svnlook&quot;;

then each command would use the variable, i.e.:
$cmd = self::$SVNLOOK.&quot; log -t &#039;{$this-&gt;_transaction}&#039; &#039;{$this-&gt;_repository}&#039;&quot;;

Maybe the $SVNLOOK variable could just default to &quot;svnlook&quot; without the path, then the full path could be added only if needed...? Just an idea.

Thanks again for sharing and updating... it&#039;s much appreciated!
Adam</description>
		<content:encoded><![CDATA[<p>Thanks for the reply Aleksandr&#8230; I&#8217;m looking forward to the updates! You&#8217;re right about using php_check_syntax() and that was the way I had initially developed the test, but I quickly found out that the function was removed in php 5.0.5. The php manual says to use &#8220;php -l &#8230;&#8221; instead, so the extra grunt work was needed =\</p>
<p>There was one other change I had to make to CommitTests.php because of our environment. &#8220;svnlook&#8221; is not part of the user&#8217;s path&#8230; so the change adds a path to svnlook:<br />
public static $SVNLOOK = &#8220;/usr/local/subversion/bin/svnlook&#8221;;</p>
<p>then each command would use the variable, i.e.:<br />
$cmd = self::$SVNLOOK.&#8221; log -t &#8216;{$this-&gt;_transaction}&#8217; &#8216;{$this-&gt;_repository}&#8217;&#8221;;</p>
<p>Maybe the $SVNLOOK variable could just default to &#8220;svnlook&#8221; without the path, then the full path could be added only if needed&#8230;? Just an idea.</p>
<p>Thanks again for sharing and updating&#8230; it&#8217;s much appreciated!<br />
Adam</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aleksandr Tsertkov</title>
		<link>http://www.devhands.com/2010/01/subversion-hook-php-framework-in/comment-page-1/#comment-10737</link>
		<dc:creator>Aleksandr Tsertkov</dc:creator>
		<pubDate>Mon, 15 Mar 2010 16:43:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.devhands.com/?p=422#comment-10737</guid>
		<description>Np Adam, thanks for your comment. I am going to update class soon with more tests and probably add post-commit and other hooks support, but than it&#039;s not (pre)CommitTest imho, but something more.

Btw for checking php files for syntax errors (lint) you could use php_check_syntax() function which would make lint cross-platform and more universal (no need to hardcode php binary path).</description>
		<content:encoded><![CDATA[<p>Np Adam, thanks for your comment. I am going to update class soon with more tests and probably add post-commit and other hooks support, but than it&#8217;s not (pre)CommitTest imho, but something more.</p>
<p>Btw for checking php files for syntax errors (lint) you could use php_check_syntax() function which would make lint cross-platform and more universal (no need to hardcode php binary path).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam</title>
		<link>http://www.devhands.com/2010/01/subversion-hook-php-framework-in/comment-page-1/#comment-10578</link>
		<dc:creator>Adam</dc:creator>
		<pubDate>Tue, 09 Mar 2010 06:49:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.devhands.com/?p=422#comment-10578</guid>
		<description>Thanks so much, this works great! Following your example, it was very easy to edit your tests and add my own. I added a test that verifies PHP syntax is correct before committing (for certain file extensions only), and also added some logic that will copy the committed files to a specific location for further testing (only if all other tests pass. I wanted to run this copy action in the postcommit hook, but the CommitTests class doesn&#039;t seem to work properly in the postcommit hook. Specifically, it doesn&#039;t seem to know what files were committed).

Here&#039;s the method to check syntax:

***********************

class CommitTests
{

    [...snip...]

    //path to php binary
    public static $PHP = &quot;/usr/local/php-cgi/bin/php&quot;;

    /**
     * Tests if the committed files pass PHP syntax checking
     *
     * @param string $msg error messages placeholder
     * @param array $filetypes array of file types which should be tested
     * @return bool
     */
    protected function _testPHPSyntax(&amp;$msg, array $filetypes=array()){
    	$result = true;
        $files = $this-&gt;_getChangedFiles($filetypes);
        
        $tempDir = sys_get_temp_dir();
        foreach ($files as $file =&gt; $extension) {
			$content = $this-&gt;_getFileContent($file);
			
			$tempfile = tempnam($tempDir, &quot;stax_&quot;);
			file_put_contents($tempfile, $content);
			$tempfile = realpath($tempfile); //sort out the formatting of the filename

			$output = shell_exec(self::$PHP.&#039; -l &quot;&#039;.$tempfile.&#039;&quot;&#039;);
			
			//try to find a parse error text and chop it off
			$syntaxErrorMsg = preg_replace(&quot;/Errors parsing.*$/&quot;, &quot;&quot;, $output, -1, $count);
            if ($count &gt; 0) { //found errors
                $result = false;
                $syntaxErrorMsg = str_replace($tempfile,$file,$syntaxErrorMsg); //replace temp filename with real filename
                $msg .= &quot;\t[$file] PHP Syntax error in file. Message: $syntaxErrorMsg\n&quot;;
            }
            
            unlink($tempfile);
        }

        return $result;
    }
    
    [...snip...]
}

***********************

And run it with:

new CommitTests($argv[1], $argv[2], array(
    &#039;PHPSyntax&#039;=&gt;array(array(&#039;php&#039;)), //array contains file extensions to check
    ....etc....
));

***********************

Thanks so much for sharing! This framework saved me a lot of time.
Adam</description>
		<content:encoded><![CDATA[<p>Thanks so much, this works great! Following your example, it was very easy to edit your tests and add my own. I added a test that verifies PHP syntax is correct before committing (for certain file extensions only), and also added some logic that will copy the committed files to a specific location for further testing (only if all other tests pass. I wanted to run this copy action in the postcommit hook, but the CommitTests class doesn&#8217;t seem to work properly in the postcommit hook. Specifically, it doesn&#8217;t seem to know what files were committed).</p>
<p>Here&#8217;s the method to check syntax:</p>
<p>***********************</p>
<p>class CommitTests<br />
{</p>
<p>    [...snip...]</p>
<p>    //path to php binary<br />
    public static $PHP = &#8220;/usr/local/php-cgi/bin/php&#8221;;</p>
<p>    /**<br />
     * Tests if the committed files pass PHP syntax checking<br />
     *<br />
     * @param string $msg error messages placeholder<br />
     * @param array $filetypes array of file types which should be tested<br />
     * @return bool<br />
     */<br />
    protected function _testPHPSyntax(&amp;$msg, array $filetypes=array()){<br />
    	$result = true;<br />
        $files = $this-&gt;_getChangedFiles($filetypes);</p>
<p>        $tempDir = sys_get_temp_dir();<br />
        foreach ($files as $file =&gt; $extension) {<br />
			$content = $this-&gt;_getFileContent($file);</p>
<p>			$tempfile = tempnam($tempDir, &#8220;stax_&#8221;);<br />
			file_put_contents($tempfile, $content);<br />
			$tempfile = realpath($tempfile); //sort out the formatting of the filename</p>
<p>			$output = shell_exec(self::$PHP.&#8217; -l &#8220;&#8216;.$tempfile.&#8217;&#8221;&#8216;);</p>
<p>			//try to find a parse error text and chop it off<br />
			$syntaxErrorMsg = preg_replace(&#8220;/Errors parsing.*$/&#8221;, &#8220;&#8221;, $output, -1, $count);<br />
            if ($count &gt; 0) { //found errors<br />
                $result = false;<br />
                $syntaxErrorMsg = str_replace($tempfile,$file,$syntaxErrorMsg); //replace temp filename with real filename<br />
                $msg .= &#8220;\t[$file] PHP Syntax error in file. Message: $syntaxErrorMsg\n&#8221;;<br />
            }</p>
<p>            unlink($tempfile);<br />
        }</p>
<p>        return $result;<br />
    }</p>
<p>    [...snip...]<br />
}</p>
<p>***********************</p>
<p>And run it with:</p>
<p>new CommitTests($argv[1], $argv[2], array(<br />
    &#8216;PHPSyntax&#8217;=&gt;array(array(&#8216;php&#8217;)), //array contains file extensions to check<br />
    &#8230;.etc&#8230;.<br />
));</p>
<p>***********************</p>
<p>Thanks so much for sharing! This framework saved me a lot of time.<br />
Adam</p>
]]></content:encoded>
	</item>
</channel>
</rss>
