Skip to content

Commit

Permalink
Adding more tests for generate().
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Aug 9, 2009
1 parent a275753 commit f70b97f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cake/console/libs/schema.php
Expand Up @@ -137,7 +137,7 @@ function generate() {
$snapshot = true;
$result = $this->in("Schema file exists.\n [O]verwrite\n [S]napshot\n [Q]uit\nWould you like to do?", array('o', 's', 'q'), 's');
if ($result === 'q') {
$this->_stop();
return $this->_stop();
}
if ($result === 'o') {
$snapshot = false;
Expand Down
43 changes: 43 additions & 0 deletions cake/tests/cases/console/libs/schema.test.php
Expand Up @@ -191,5 +191,48 @@ function testGenerateSnaphot() {

$this->Shell->generate();
}

/**
* test generate without a snapshot.
*
* @return void
**/
function testGenerateNoOverwrite() {
touch(TMP . 'schema.php');
$this->Shell->params['file'] = 'schema.php';
$this->Shell->args = array();

$this->Shell->setReturnValue('in', 'q');
$this->Shell->Schema =& new MockSchemaCakeSchema();
$this->Shell->Schema->path = TMP;
$this->Shell->Schema->expectNever('read');

$result = $this->Shell->generate();
unlink(TMP . 'schema.php');
}

/**
* test generate with overwriting of the schema files.
*
* @return void
**/
function testGenerateOverwrite() {
touch(TMP . 'schema.php');
$this->Shell->params['file'] = 'schema.php';
$this->Shell->args = array();

$this->Shell->setReturnValue('in', 'o');
$this->Shell->expectAt(1, 'out', array(new PatternExpectation('/Schema file:\s[a-z\.]+\sgenerated/')));
$this->Shell->Schema =& new MockSchemaCakeSchema();
$this->Shell->Schema->path = TMP;
$this->Shell->Schema->setReturnValue('read', array('schema data'));
$this->Shell->Schema->setReturnValue('write', true);

$this->Shell->Schema->expectOnce('read');
$this->Shell->Schema->expectOnce('write', array(array('schema data', 'file' => 'schema.php')));

$this->Shell->generate();
unlink(TMP . 'schema.php');
}
}
?>

0 comments on commit f70b97f

Please sign in to comment.