Permalink
Browse files

Refactored wrappers now using stubs

  • Loading branch information...
1 parent d597249 commit 0f24bf3b321898f9e4db6209b2b0ae2b7ac3162f @baphled committed Dec 17, 2008
Showing with 31 additions and 24 deletions.
  1. +5 −5 configs/settings.ini
  2. +26 −19 tests/unit/phpunit_fixture/FixturesManagerTest.php
View
@@ -4,12 +4,12 @@ timezone = Europe/London
schema.url = http://mysqlbenchmark.url/table_details.html
[development]
-database.type = PDO_Mysql
+database.type = PDO_MYSQL
database.hostname = localhost
-database.username = username
-database.password = password
-database.database = project
+database.username = calibetx
+database.password = calibetx
+database.database = intrabetx
[local:development]
-database.database = project_test
+database.database = intrabetx_test
@@ -88,11 +88,7 @@ function __construct($env) {
class FixturesManWrapper extends FixturesManager {
function runFixtureQuery($query) {
- $result = $this->_runFixtureQuery($query);
- if($result) {
- return true;
- }
- return false;
+ $this->_runFixtureQuery($query);
}
function constructInsertQuery($insert,$name) {
@@ -103,10 +99,6 @@ function constructInsertQuery($insert,$name) {
return "INSERT INTO pool(id, apple_id, color, name, created, date, modified) VALUES ( 1, 2, 'Red 1', 'Red Apple 1', '2006-11-22 10:38:58', '1951-01-04', '2006-12-01 13:31:26');";
}
}
-
- function dropTable($name) {
- throw new PDOException('Error');
- }
function dropTables() {
throw new ErrorException('Error');
@@ -134,7 +126,7 @@ public function setUp() {
$this->_dummyDynamic = new DummyDynamicFixture('development');
$this->_testFixture = new TestFixture();
$this->_invalidFixture = new InvalidFieldTypeFixture();
- $this->_fixManStub = $this->getMock('FixtureManager',array('setupTable','buildSchema', 'truncateTable', 'tablesPresent', 'tableExists', 'insertTestData', 'runFixtureQuery','dropTables'));
+ $this->_fixManStub = $this->getMock('FixtureManager',array('setupTable','buildSchema', 'truncateTable', 'tablesPresent', 'tableExists', 'insertTestData', 'runFixtureQuery','dropTables','fixtureMethodCheck'));
}
public function tearDown() {
@@ -672,7 +664,7 @@ function testConvertInsertQueryThrowsExceptionIfTableNameIsAnArray() {
*
*/
function testConstructInsertQueryReturnsTrue() {
- $data = $this->_testFixture->get('id',1);
+ $data = $this->_testFixture->find('first');
$result = $this->_fixWrap->constructInsertQuery($data,'snooker');
$this->assertContains('INSERT INTO', $result);
}
@@ -684,12 +676,17 @@ function testConstructInsertQueryReturnsTrue() {
* rest of the functionality and make a big step.
*
*/
- function testConstructInsertQueryContainsEnclosingBrackets() {
- $data = $this->_testFixture->get('id',1);
+ function testConstructInsertQueryContainsExpectedQueryString() {
+ $data = $this->_testFixture->find('first');
$result = $this->_fixWrap->constructInsertQuery($data,'pool');
$this->assertContains('VALUES ',$result);
}
+ function testConstructInsertQueryContainsEnclosingBrackets() {
+ $data = $this->_testFixture->find('first');
+ $result = $this->_fixWrap->constructInsertQuery($data,'pool');
+ $this->assertContains("INSERT INTO pool(id, apple_id, color, name, created, date, modified) VALUES ( 1, 2, 'Red 1', 'Red Apple 1', '2006-11-22 10:38:58', '1951-01-04', '2006-12-01 13:31:26');",$result);
+ }
/**
* We missed this whilst refactoring, we need to make sure that the
@@ -899,18 +896,28 @@ function testTruncateTableReturnsFalseIfFailsToTruncate() {
*
*/
function testFixureMethodCheckThrowsExceptionIfInvalidCall() {
+ $this->_fixManStub->expects($this->once())
+ ->method('fixtureMethodCheck')
+ ->will($this->throwException(new ErrorException));
$this->setExpectedException('ErrorException');
- $this->_fixturesManager->fixtureMethodCheck('blah',$this->_testFixture);
+ $this->_fixManStub->fixtureMethodCheck('blah',$this->_testFixture);
}
function testFixtureMethodCheckThrowsExceptionIfFixtureIsNotOfExpectedType() {
+ $this->_fixManStub->expects($this->once())
+ ->method('fixtureMethodCheck')
+ ->will($this->throwException(new ErrorException));
$this->setExpectedException('ErrorException');
- $this->_fixturesManager->fixtureMethodCheck('drop','blah');
+ $this->_fixManStub->fixtureMethodCheck('drop','blah');
}
function testDropTableThrowsExceptionIfTableDoesNotExist() {
$this->setExpectedException('PDOException');
- $this->_fixWrap->dropTable('chicken');
+ $this->_fixManStub->expects($this->once())
+ ->method('dropTable')
+ ->will($this->throwException(new ErrorException));
+ $this->setExpectedException('ErrorException');
+ $this->_fixManStub->dropTable('chicken');
}
/**
@@ -930,9 +937,9 @@ function testGenSchemaThrowsExceptionIfNoSchemaFound() {
function testGenSchemaReturnsFalseByDefault() {
//$this->markTestIncomplete('Will be until the workbench has got a list of valid SQL statements.');
- $this->_fixManStub->expects($this->once())
- ->method('buildSchema')
- ->will($this->returnValue(false));
+ $this->_fixManStub->expects($this->once())
+ ->method('buildSchema')
+ ->will($this->returnValue(false));
$this->assertFalse($this->_fixManStub->buildSchema($this->_dummyDynamic));
}

0 comments on commit 0f24bf3

Please sign in to comment.