OSDN Git Service

add a few unit tests for DocParser
authorscribu <mail@scribu.net>
Thu, 1 Aug 2013 20:08:40 +0000 (23:08 +0300)
committerscribu <mail@scribu.net>
Thu, 1 Aug 2013 20:08:40 +0000 (23:08 +0300)
php/WP_CLI/DocParser.php
tests/test-doc-parser.php [new file with mode: 0644]

index c5bfb16..f830285 100644 (file)
@@ -17,6 +17,10 @@ class DocParser {
                return $matches[1];
        }
 
+       function get_longdesc() {
+               return false;
+       }
+
        function get_tag( $name ) {
                if ( preg_match( '/@' . $name . '\s+([a-z-_]+)/', $this->docComment, $matches ) )
                        return $matches[1];
diff --git a/tests/test-doc-parser.php b/tests/test-doc-parser.php
new file mode 100644 (file)
index 0000000..2026b3a
--- /dev/null
@@ -0,0 +1,75 @@
+<?php
+
+use WP_CLI\DocParser;
+
+class DocParserTests extends PHPUnit_Framework_TestCase {
+
+       function test_only_tags() {
+               $doc = new DocParser( <<<EOB
+/**
+ * @alias rock-on
+ */
+EOB
+               );
+
+               $this->assertFalse( $doc->get_shortdesc() );
+               $this->assertFalse( $doc->get_longdesc() );
+               $this->assertFalse( $doc->get_synopsis() );
+               $this->assertFalse( $doc->get_tag('foo') );
+               $this->assertEquals( 'rock-on', $doc->get_tag('alias') );
+       }
+
+       function test_no_longdesc() {
+               $doc = new DocParser( <<<EOB
+/**
+ * Rock and roll!
+ * @alias rock-on
+ */
+EOB
+               );
+
+               $this->assertEquals( 'Rock and roll!', $doc->get_shortdesc() );
+               $this->assertFalse( $doc->get_longdesc() );
+               $this->assertFalse( $doc->get_synopsis() );
+               $this->assertEquals( 'rock-on', $doc->get_tag('alias') );
+       }
+
+       function test_complete() {
+               $doc = new DocParser( <<<EOB
+/**
+ * Rock and roll!
+ *
+ * ## OPTIONS
+ *
+ * --volume=<number>
+ * : Sets the volume.
+ *
+ * ## EXAMPLES
+ *
+ * wp rock-on --volume=11
+ *
+ * @synopsis [--volume=<number>]
+ * @alias rock-on
+ */
+EOB
+               );
+
+               $this->assertEquals( 'Rock and roll!', $doc->get_shortdesc() );
+               $this->assertEquals( '[--volume=<number>]', $doc->get_synopsis() );
+               $this->assertEquals( 'rock-on', $doc->get_tag('alias') );
+
+               $longdesc = <<<EOB
+## OPTIONS
+
+--volume=<number>
+: Sets the volume.
+
+## EXAMPLES
+
+wp rock-on --volume=11
+EOB
+               ;
+               $this->assertEquals( $longdesc, $doc->get_longdesc() );
+       }
+}
+