OSDN Git Service

add tests for SynopsisParser
authorscribu <mail@scribu.net>
Mon, 11 Feb 2013 17:14:07 +0000 (19:14 +0200)
committerscribu <mail@scribu.net>
Mon, 11 Feb 2013 19:23:56 +0000 (21:23 +0200)
phpunit.xml.dist
tests/bootstrap.php
tests/test-synopsis.php [new file with mode: 0644]

index 917a7d5..529dae0 100644 (file)
@@ -5,6 +5,7 @@
        <testsuites>
                <testsuite>
                        <directory prefix="spec-" suffix=".php">tests/</directory>
+                       <directory prefix="test-" suffix=".php">tests/</directory>
                </testsuite>
        </testsuites>
 </phpunit>
index 4e82b7f..c24b946 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 
+require_once getcwd() . '/vendor/autoload.php';
 require_once getcwd() . '/php/utils.php';
 
 require_once __DIR__ . '/abstract-spec.php';
diff --git a/tests/test-synopsis.php b/tests/test-synopsis.php
new file mode 100644 (file)
index 0000000..59f4771
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+
+use WP_CLI\SynopsisParser;
+
+class SynopsisParserTest extends PHPUnit_Framework_TestCase {
+
+       function testPositional() {
+               $r = SynopsisParser::parse( '<foo> [<bar>]' );
+
+               $this->assertEquals( 2, count( $r['positional'] ) );
+               $this->assertFalse( $r['positional'][0]['optional'] );
+               $this->assertTrue( $r['positional'][1]['optional'] );
+       }
+
+       function testFlag() {
+               $r = SynopsisParser::parse( '--foo' );
+               $this->assertEquals( 0, count( $r['flag'] ) ); // flags can't be mandatory
+
+               $r = SynopsisParser::parse( '[--foo]' );
+               $this->assertEquals( 1, count( $r['flag'] ) );
+       }
+
+       function testGeneric() {
+               $r = SynopsisParser::parse( '--<field>=<value>' );
+
+               $this->assertEquals( 1, count( $r['generic'] ) );
+       }
+
+       function testAssoc() {
+               $r = SynopsisParser::parse( '--foo=<value> [--bar=<value>]' );
+
+               $this->assertEquals( 2, count( $r['assoc'] ) );
+               $this->assertFalse( $r['assoc'][0]['optional'] );
+               $this->assertTrue( $r['assoc'][1]['optional'] );
+       }
+}
+