Skip to content

Commit

Permalink
Making tests use dataProviders instead of repeated test methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Aug 23, 2010
1 parent 527446a commit b1c41e5
Showing 1 changed file with 31 additions and 80 deletions.
111 changes: 31 additions & 80 deletions cake/tests/cases/libs/xml.test.php
Expand Up @@ -57,33 +57,28 @@ function testBuild() {
}

/**
* testBuildInvalidData
*
* @expectedException Exception
* return void
*/
function testBuildInvalidData() {
Xml::build(false);
}

/**
* testBuildEmptyData
* data provider function for testBuildInvalidData
*
* @expectedException Exception
* return void
* @return void
*/
function testBuildEmptyData() {
Xml::build('');
public static function invalidDataProvider() {
return array(
array(null),
array(false),
array(''),
array('<tag>')
);
}

/**
* testBuildInvalidTag
* testBuildInvalidData
*
* @dataProvider invalidDataProvider
* @expectedException Exception
* return void
*/
function testBuildInvalidTag() {
Xml::build('<tag>');
function testBuildInvalidData($value) {
Xml::build($value);
}

/**
Expand Down Expand Up @@ -160,49 +155,20 @@ function testFromArray() {
}

/**
* testFromArrayFail method
* data provider for fromArray() failures
*
* @access public
* @return void
*/
function testFromArrayFail() {
try {
Xml::fromArray(false);
$this->fail('No exception thrown');
} catch (Exception $e) {
$this->assertTrue(true);
}

try {
Xml::fromArray(array());
$this->fail('No exception thrown');
} catch (Exception $e) {
$this->assertTrue(true);
}

try {
Xml::fromArray(array('numeric key as root'));
$this->fail('No exception thrown');
} catch (Exception $e) {
$this->assertTrue(true);
}

try {
Xml::fromArray(array('item1' => '', 'item2' => ''));
$this->fail('No exception thrown');
} catch (Exception $e) {
$this->assertTrue(true);
}

try {
Xml::fromArray(array('items' => array('item1', 'item2')));
$this->fail('No exception thrown');
} catch (Exception $e) {
$this->assertTrue(true);
}

try {
$xml = array(
public static function invalidArrayDataProvider() {
return array(
array(''),
array(null),
array(false),
array(array()),
array('numeric key as root'),
array('item1' => '', 'item2' => ''),
array('items' => array('item1', 'item2')),
array(array(
'tags' => array(
'tag' => array(
array(
Expand All @@ -212,34 +178,19 @@ function testFromArrayFail() {
)
)
)
);
Xml::fromArray($xml);
$this->fail('No exception thrown');
} catch (Exception $e) {
$this->assertEqual($e->getMessage(), __('Invalid array'));
}

}

/**
* testToArrayInvalidObject
*
* @expectedException Exception
* @return void
*/
function testToArrayInvalidObject() {
$obj = new DateTime();
Xml::toArray($obj);
)),
array(new DateTime())
);
}

/**
* testToArrayNoObject
* testFromArrayFail method
*
* @dataProvider invalidArrayDataProvider
* @expectedException Exception
* @return void
*/
function testToArrayNoObject() {
Xml::toArray(array());
function testFromArrayFail($value) {
Xml::fromArray($value);
}

/**
Expand Down

0 comments on commit b1c41e5

Please sign in to comment.