Permalink
Browse files

Basic prompting ref #13

  • Loading branch information...
1 parent 78e60cb commit 4f779358ceee1ed7817b6cc11902268745fdce22 @davedevelopment committed Oct 31, 2012
Showing with 359 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +3 −0 composer.json
  3. +211 −0 composer.lock
  4. +26 −0 phpunit.xml.dist
  5. +63 −0 src/Phpmig/Migration/Migration.php
  6. +55 −0 tests/Phpmig/Test/Migration/MigrationTest.php
View
@@ -1 +1,2 @@
/packages/
+vendor
View
@@ -20,6 +20,9 @@
"symfony/config": "2.*",
"symfony/class-loader": "2.*"
},
+ "require-dev": {
+ "mockery/mockery": "*@dev"
+ },
"autoload": {
"psr-0": {
"Phpmig": "src/"
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
+<phpunit
+ backupGlobals = "false"
+ backupStaticAttributes = "false"
+ colors = "true"
+ convertErrorsToExceptions = "true"
+ convertNoticesToExceptions = "true"
+ convertWarningsToExceptions = "true"
+ processIsolation = "false"
+ stopOnFailure = "false"
+ syntaxCheck = "false"
+ bootstrap = "vendor/autoload.php" >
+
+ <testsuites>
+ <testsuite name="phpmig Test Suite">
+ <directory>tests/</directory>
+ </testsuite>
+ </testsuites>
+
+ <listeners>
+ <listener class="\Mockery\Adapter\Phpunit\TestListener" file="vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/TestListener.php"></listener>
+ </listeners>
+
+</phpunit>
@@ -6,6 +6,7 @@
namespace Phpmig\Migration;
use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Helper\DialogHelper;
/**
* This file is part of phpmig
@@ -156,6 +157,68 @@ public function setOutput(OutputInterface $output)
$this->output = $output;
return $this;
}
+
+ /**
+ * Ask for input
+ *
+ * @param string $question
+ * @param mixed $default
+ * @return string The users answer
+ */
+ public function ask($question, $default = null)
+ {
+ $this->getDialogHelper()->ask($this->getOutput(), $question, $default);
+ }
+
+ /**
+ * Ask for confirmation
+ *
+ * @param string $question
+ * @param mixed $default
+ * @return string The users answer
+ */
+ public function confirm($question, $default = true)
+ {
+ $this->getDialogHelper()->askConfirmation($this->getOutput(), $question, $default);
+ }
+
+ /**
+ * Ask for hidden answer (e.g. ******)
+ *
+ * @param string $question
+ * @param boolean $fallback - whether to allow non-hidden if unavailable
+ * @return string The users answer
+ */
+ public function askForHiddenResponse($question, $fallback = true)
+ {
+ $this->getDialogHelper()->askHiddenResponse($this->getOutput(), $question, $fallback);
+ }
+
+ /**
+ * Get Dialog Helper
+ *
+ * @return DialogHelper
+ */
+ public function getDialogHelper()
+ {
+ if ($this->dialogHelper) {
+ return $this->dialogHelper;
+ }
+
+ return $this->dialogHelper = new DialogHelper();
+ }
+
+ /**
+ * Set Dialog Helper
+ *
+ * @param DialogHelper $dialogHelper
+ * @return Migration
+ */
+ public function setDialogHelper(DialogHelper $dialogHelper)
+ {
+ $this->dialogHelper = $dialogHelper;
+ return $this;
+ }
}
@@ -0,0 +1,55 @@
+<?php
+
+namespace Phpmig\Test\Migration;
+
+use Mockery as m;
+use Phpmig\Migration\Migration;
+
+class MigrationTest extends \PHPUnit_Framework_Testcase
+{
+ public function setup()
+ {
+ $this->output = m::mock("Symfony\Component\Console\Output\OutputInterface")->shouldIgnoreMissing();
+ $this->dialogHelper = m::mock("Symfony\Component\Console\Helper\DialogHelper")->shouldIgnoreMissing();
+ $this->object = new Migration(1);
+ $this->object->setOutput($this->output);
+ $this->object->setDialogHelper($this->dialogHelper);
+ }
+
+
+ /**
+ * @test
+ */
+ public function shouldAskForInput()
+ {
+ $this->dialogHelper->shouldReceive("ask")
+ ->with($this->output, $question = "Wat?", $default = "huh?")
+ ->once();
+
+ $this->object->ask($question, $default);
+ }
+
+ /**
+ * @test
+ */
+ public function shouldAskForConfirmation()
+ {
+ $this->dialogHelper->shouldReceive("askConfirmation")
+ ->with($this->output, $question = "Wat?", $default = true)
+ ->once();
+
+ $this->object->confirm($question, $default);
+ }
+
+ /**
+ * @test
+ */
+ public function shouldAskForHiddenResponse()
+ {
+ $this->dialogHelper->shouldReceive("askHiddenResponse")
+ ->with($this->output, $question = "Wat?", $default = true)
+ ->once();
+
+ $this->object->askForHiddenResponse($question, $default);
+ }
+}

0 comments on commit 4f77935

Please sign in to comment.