OSDN Git Service

add test case
authorscribu <mail@scribu.net>
Thu, 7 Feb 2013 22:19:34 +0000 (00:19 +0200)
committerscribu <mail@scribu.net>
Thu, 7 Feb 2013 22:19:34 +0000 (00:19 +0200)
tests/abstract-spec.php
tests/spec-core.php

index e49239d..6a40f9b 100644 (file)
@@ -15,9 +15,13 @@ abstract class WP_CLI_Spec extends PHPUnit_Extensions_Story_TestCase {
                exec( "mysql -u$dbuser -p$dbpass -e '$sql'" );
        }
 
-       protected function setUp() {
+       protected function tearDown() {
+               $dbname = self::$db_settings['dbname'];
+               $this->run_sql( "DROP DATABASE IF EXISTS $dbname" );
+       }
+
+       private function create_db() {
                $dbname = self::$db_settings['dbname'];
-               $this->run_sql( "DROP DATABASE $dbname" );
                $this->run_sql( "CREATE DATABASE $dbname" );
        }
 
@@ -28,6 +32,11 @@ abstract class WP_CLI_Spec extends PHPUnit_Extensions_Story_TestCase {
                        }
                        break;
 
+                       case 'database': {
+                               $this->create_db();
+                       }
+                       break;
+
                        case 'wp files': {
                                $world['runner']->download_wordpress_files();
                        }
@@ -39,6 +48,7 @@ abstract class WP_CLI_Spec extends PHPUnit_Extensions_Story_TestCase {
                        break;
 
                        case 'wp install': {
+                               $this->create_db();
                                $world['runner']->download_wordpress_files();
                                $world['runner']->create_config( self::$db_settings );
                                $world['runner']->run_install();
index adb4c57..0824a40 100644 (file)
@@ -31,11 +31,27 @@ class CoreCommandSpec extends WP_CLI_Spec {
        }
 
        /** @scenario */
+       public function dbDoesntExist() {
+               $this
+                       ->given( 'empty dir' )
+                       ->and( 'wp files' )
+                       ->and( 'wp config' )
+
+                       ->when( 'invoking', 'wp' )
+                       ->then( 'return code should be', 1 )
+                       ->and( 'output should be', "Error: Can't connect to the database." )
+
+                       ->when( 'invoking', 'db create' )
+                       ->then( 'return code should be', 0 );
+       }
+
+       /** @scenario */
        public function dbTablesNotInstalled() {
                $this
                        ->given( 'empty dir' )
                        ->and( 'wp files' )
                        ->and( 'wp config' )
+                       ->and( 'database' )
 
                        ->when( 'invoking', 'core is-installed' )
                        ->then( 'return code should be', 1 )
@@ -47,7 +63,7 @@ class CoreCommandSpec extends WP_CLI_Spec {
                        ->then( 'return code should be', 0 )
 
                        ->when( 'invoking', 'post list --ids' )
-                       ->then( 'output should be', 1 );
+                       ->then( 'output should be', "1" );
        }
 
        /** @scenario */