Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Basic prompting ref #13

  • Loading branch information...
commit 4f779358ceee1ed7817b6cc11902268745fdce22 1 parent 78e60cb
@davedevelopment authored
View
1  .gitignore
@@ -1 +1,2 @@
/packages/
+vendor
View
3  composer.json
@@ -20,6 +20,9 @@
"symfony/config": "2.*",
"symfony/class-loader": "2.*"
},
+ "require-dev": {
+ "mockery/mockery": "*@dev"
+ },
"autoload": {
"psr-0": {
"Phpmig": "src/"
View
211 composer.lock
@@ -0,0 +1,211 @@
+{
+ "hash": "1c02ee79127ddedc853373ca32a59def",
+ "packages": [
+ {
+ "name": "symfony/class-loader",
+ "version": "v2.1.3",
+ "target-dir": "Symfony/Component/ClassLoader",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/ClassLoader",
+ "reference": "v2.1.3"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://github.com/symfony/ClassLoader/zipball/v2.1.3",
+ "reference": "v2.1.3",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "require-dev": {
+ "symfony/finder": "2.1.*"
+ },
+ "time": "2012-10-27 08:59:21",
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.1-dev"
+ }
+ },
+ "installation-source": "dist",
+ "autoload": {
+ "psr-0": {
+ "Symfony\\Component\\ClassLoader": ""
+ }
+ },
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "http://symfony.com/contributors"
+ }
+ ],
+ "description": "Symfony ClassLoader Component",
+ "homepage": "http://symfony.com"
+ },
+ {
+ "name": "symfony/config",
+ "version": "v2.1.3",
+ "target-dir": "Symfony/Component/Config",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/Config",
+ "reference": "v2.1.3"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://github.com/symfony/Config/zipball/v2.1.3",
+ "reference": "v2.1.3",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "time": "2012-10-20 00:10:30",
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.1-dev"
+ }
+ },
+ "installation-source": "dist",
+ "autoload": {
+ "psr-0": {
+ "Symfony\\Component\\Config": ""
+ }
+ },
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "http://symfony.com/contributors"
+ }
+ ],
+ "description": "Symfony Config Component",
+ "homepage": "http://symfony.com"
+ },
+ {
+ "name": "symfony/console",
+ "version": "v2.1.3",
+ "target-dir": "Symfony/Component/Console",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/Console",
+ "reference": "v2.1.3"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://github.com/symfony/Console/zipball/v2.1.3",
+ "reference": "v2.1.3",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "time": "2012-10-22 07:37:12",
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.1-dev"
+ }
+ },
+ "installation-source": "dist",
+ "autoload": {
+ "psr-0": {
+ "Symfony\\Component\\Console": ""
+ }
+ },
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "http://symfony.com/contributors"
+ }
+ ],
+ "description": "Symfony Console Component",
+ "homepage": "http://symfony.com"
+ }
+ ],
+ "packages-dev": [
+ {
+ "name": "mockery/mockery",
+ "version": "dev-master",
+ "source": {
+ "type": "git",
+ "url": "git://github.com/padraic/mockery.git",
+ "reference": "b6adea3c241798c5afcbe2a2ac9294ce635a096f"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://github.com/padraic/mockery/zipball/b6adea3c241798c5afcbe2a2ac9294ce635a096f",
+ "reference": "b6adea3c241798c5afcbe2a2ac9294ce635a096f",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.2"
+ },
+ "suggest": {
+ "Hamcrest": "1.0.0"
+ },
+ "time": "1348513062",
+ "type": "library",
+ "installation-source": "source",
+ "autoload": {
+ "psr-0": {
+ "Mockery": "library/"
+ }
+ },
+ "license": [
+ "New BSD"
+ ],
+ "authors": [
+ {
+ "name": "Pádraic Brady",
+ "email": "padraic.brady@gmail.com",
+ "homepage": "http://blog.astrumfutura.com"
+ }
+ ],
+ "description": "Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a test double framework with a succint API capable of clearly defining all possible object operations and interactions using a human readable Domain Specific Language (DSL). Designed as a drop in alternative to PHPUnit's phpunit-mock-objects library, Mockery is easy to integrate with PHPUnit and can operate alongside phpunit-mock-objects without the World ending.",
+ "homepage": "http://github.com/padraic/mockery",
+ "keywords": [
+ "testing",
+ "library",
+ "BDD",
+ "TDD",
+ "test",
+ "mockery",
+ "mock",
+ "stub",
+ "test double",
+ "mock objects"
+ ]
+ }
+ ],
+ "aliases": [
+
+ ],
+ "minimum-stability": "stable",
+ "stability-flags": {
+ "mockery/mockery": 20
+ }
+}
View
26 phpunit.xml.dist
@@ -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>
View
63 src/Phpmig/Migration/Migration.php
@@ -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;
+ }
}
View
55 tests/Phpmig/Test/Migration/MigrationTest.php
@@ -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);
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.