OSDN Git Service

DocParser: return empty string instead of false
authorscribu <mail@scribu.net>
Thu, 1 Aug 2013 20:45:01 +0000 (23:45 +0300)
committerscribu <mail@scribu.net>
Thu, 1 Aug 2013 20:45:01 +0000 (23:45 +0300)
php/WP_CLI/DocParser.php
tests/test-doc-parser.php

index ebd9a52..e146833 100644 (file)
@@ -20,7 +20,7 @@ class DocParser {
 
        function get_shortdesc() {
                if ( !preg_match( '|^([^@][^\n]+)\n*|', $this->docComment, $matches ) )
-                       return false;
+                       return '';
 
                return $matches[1];
        }
@@ -33,12 +33,12 @@ class DocParser {
                if ( preg_match( '|^@' . $name . '\s+([a-z-_]+)|m', $this->docComment, $matches ) )
                        return $matches[1];
 
-               return false;
+               return '';
        }
 
        function get_synopsis() {
                if ( !preg_match( '|^@synopsis\s+(.+)|m', $this->docComment, $matches ) )
-                       return false;
+                       return '';
 
                return $matches[1];
        }
index 2026b3a..4138481 100644 (file)
@@ -4,6 +4,15 @@ use WP_CLI\DocParser;
 
 class DocParserTests extends PHPUnit_Framework_TestCase {
 
+       function test_empty() {
+               $doc = new DocParser( '' );
+
+               $this->assertEquals( '', $doc->get_shortdesc() );
+               $this->assertEquals( '', $doc->get_longdesc() );
+               $this->assertEquals( '', $doc->get_synopsis() );
+               $this->assertEquals( '', $doc->get_tag('alias') );
+       }
+
        function test_only_tags() {
                $doc = new DocParser( <<<EOB
 /**
@@ -12,10 +21,10 @@ class DocParserTests extends PHPUnit_Framework_TestCase {
 EOB
                );
 
-               $this->assertFalse( $doc->get_shortdesc() );
-               $this->assertFalse( $doc->get_longdesc() );
-               $this->assertFalse( $doc->get_synopsis() );
-               $this->assertFalse( $doc->get_tag('foo') );
+               $this->assertEquals( '', $doc->get_shortdesc() );
+               $this->assertEquals( '', $doc->get_longdesc() );
+               $this->assertEquals( '', $doc->get_synopsis() );
+               $this->assertEquals( '', $doc->get_tag('foo') );
                $this->assertEquals( 'rock-on', $doc->get_tag('alias') );
        }
 
@@ -29,8 +38,8 @@ EOB
                );
 
                $this->assertEquals( 'Rock and roll!', $doc->get_shortdesc() );
-               $this->assertFalse( $doc->get_longdesc() );
-               $this->assertFalse( $doc->get_synopsis() );
+               $this->assertEquals( '', $doc->get_longdesc() );
+               $this->assertEquals( '', $doc->get_synopsis() );
                $this->assertEquals( 'rock-on', $doc->get_tag('alias') );
        }