Refactoring expectError() calls to PHPUnit annotations

This commit is contained in:
Jelle Henkens 2011-09-10 17:23:28 +01:00
parent 8272705fee
commit 7ba2f90b2a
11 changed files with 104 additions and 37 deletions

View file

@ -111,10 +111,10 @@ class CacheTest extends CakeTestCase {
* *
* Test that the cache class doesn't cause fatal errors with a partial path * Test that the cache class doesn't cause fatal errors with a partial path
* *
* @expectedException PHPUnit_Framework_Error_Warning
* @return void * @return void
*/ */
public function testInvaidConfig() { public function testInvalidConfig() {
$this->expectError();
Cache::config('invalid', array( Cache::config('invalid', array(
'engine' => 'File', 'engine' => 'File',
'duration' => '+1 year', 'duration' => '+1 year',
@ -124,7 +124,6 @@ class CacheTest extends CakeTestCase {
'random' => 'wii' 'random' => 'wii'
)); ));
$read = Cache::read('Test', 'invalid'); $read = Cache::read('Test', 'invalid');
$this->assertEqual($read, null);
} }
/** /**

View file

@ -317,12 +317,12 @@ class FileEngineTest extends CakeTestCase {
/** /**
* check that FileEngine generates an error when a configured Path does not exist. * check that FileEngine generates an error when a configured Path does not exist.
* *
* @expectedException PHPUnit_Framework_Error_Warning
* @return void * @return void
*/ */
public function testErrorWhenPathDoesNotExist() { public function testErrorWhenPathDoesNotExist() {
$this->skipIf(is_dir(TMP . 'tests' . DS . 'file_failure'), 'Cannot run test directory exists.'); $this->skipIf(is_dir(TMP . 'tests' . DS . 'file_failure'), 'Cannot run test directory exists.');
$this->expectError();
Cache::config('failure', array( Cache::config('failure', array(
'engine' => 'File', 'engine' => 'File',
'path' => TMP . 'tests' . DS . 'file_failure' 'path' => TMP . 'tests' . DS . 'file_failure'

View file

@ -147,12 +147,19 @@ class ContainableBehaviorTest extends CakeTestCase {
/** /**
* testInvalidContainments method * testInvalidContainments method
* *
* @expectedException PHPUnit_Framework_Error_Warning
* @return void * @return void
*/ */
public function testInvalidContainments() { public function testInvalidContainments() {
$this->expectError();
$r = $this->__containments($this->Article, array('Comment', 'InvalidBinding')); $r = $this->__containments($this->Article, array('Comment', 'InvalidBinding'));
}
/**
* testInvalidContainments method with suppressing error notices
*
* @return void
*/
public function testInvalidContainmentsNoNotices() {
$this->Article->Behaviors->attach('Containable', array('notices' => false)); $this->Article->Behaviors->attach('Containable', array('notices' => false));
$r = $this->__containments($this->Article, array('Comment', 'InvalidBinding')); $r = $this->__containments($this->Article, array('Comment', 'InvalidBinding'));
} }
@ -226,8 +233,15 @@ class ContainableBehaviorTest extends CakeTestCase {
$r = $this->Article->find('all', array('contain' => array())); $r = $this->Article->find('all', array('contain' => array()));
$this->assertFalse(Set::matches('/User', $r)); $this->assertFalse(Set::matches('/User', $r));
$this->assertFalse(Set::matches('/Comment', $r)); $this->assertFalse(Set::matches('/Comment', $r));
}
$this->expectError(); /**
* testBeforeFindWithNonExistingBinding method
*
* @expectedException PHPUnit_Framework_Error_Warning
* @return void
*/
public function testBeforeFindWithNonExistingBinding() {
$r = $this->Article->find('all', array('contain' => array('Comment' => 'NonExistingBinding'))); $r = $this->Article->find('all', array('contain' => array('Comment' => 'NonExistingBinding')));
} }

View file

@ -2479,10 +2479,6 @@ class MysqlTest extends CakeTestCase {
$Schema = new CakeSchema(); $Schema = new CakeSchema();
$Schema->tables = array('table' => array(), 'anotherTable' => array()); $Schema->tables = array('table' => array(), 'anotherTable' => array());
$this->expectError();
$result = $this->Dbo->dropSchema(null);
$this->assertTrue($result === null);
$result = $this->Dbo->dropSchema($Schema, 'non_existing'); $result = $this->Dbo->dropSchema($Schema, 'non_existing');
$this->assertTrue(empty($result)); $this->assertTrue(empty($result));
@ -2490,6 +2486,16 @@ class MysqlTest extends CakeTestCase {
$this->assertPattern('/^\s*DROP TABLE IF EXISTS\s+' . $this->Dbo->fullTableName('table') . ';\s*$/s', $result); $this->assertPattern('/^\s*DROP TABLE IF EXISTS\s+' . $this->Dbo->fullTableName('table') . ';\s*$/s', $result);
} }
/**
* testDropSchemaNoSchema method
*
* @expectedException PHPUnit_Framework_Error
* @return void
*/
public function testDropSchemaNoSchema() {
$result = $this->Dbo->dropSchema(null);
}
/** /**
* testOrderParsing method * testOrderParsing method
* *
@ -2693,16 +2699,6 @@ class MysqlTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testBuildColumn2() { public function testBuildColumn2() {
$this->expectError();
$data = array(
'name' => 'testName',
'type' => 'varchar(255)',
'default',
'null' => true,
'key'
);
$this->Dbo->buildColumn($data);
$data = array( $data = array(
'name' => 'testName', 'name' => 'testName',
'type' => 'string', 'type' => 'string',
@ -2800,6 +2796,23 @@ class MysqlTest extends CakeTestCase {
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
} }
/**
* testBuildColumnBadType method
*
* @expectedException PHPUnit_Framework_Error
* @return void
*/
public function testBuildColumnBadType() {
$data = array(
'name' => 'testName',
'type' => 'varchar(255)',
'default',
'null' => true,
'key'
);
$this->Dbo->buildColumn($data);
}
/** /**
* test hasAny() * test hasAny()
* *

View file

@ -417,11 +417,18 @@ class ModelDeleteTest extends BaseModelTest {
$result = $TestModel->deleteAll(array('Article.user_id' => 999)); $result = $TestModel->deleteAll(array('Article.user_id' => 999));
$this->assertTrue($result, 'deleteAll returned false when all no records matched conditions. %s'); $this->assertTrue($result, 'deleteAll returned false when all no records matched conditions. %s');
}
$this->expectError(); /**
ob_start(); * testDeleteAllUnknownColumn method
*
* @expectedException PDOException
* @return void
*/
public function testDeleteAllUnknownColumn() {
$this->loadFixtures('Article');
$TestModel = new Article();
$result = $TestModel->deleteAll(array('Article.non_existent_field' => 999)); $result = $TestModel->deleteAll(array('Article.non_existent_field' => 999));
ob_get_clean();
$this->assertFalse($result, 'deleteAll returned true when find query generated sql error. %s'); $this->assertFalse($result, 'deleteAll returned true when find query generated sql error. %s');
} }

View file

@ -4943,8 +4943,17 @@ class ModelReadTest extends BaseModelTest {
$this->loadFixtures('Post'); $this->loadFixtures('Post');
$TestModel = new Post(); $TestModel = new Post();
$this->assertEqual(3, count($TestModel->find('all'))); $this->assertEqual(3, count($TestModel->find('all')));
}
$this->expectError(); /**
* testCallbackSourceChangeUnknownDatasource method
*
* @expectedException MissingDatasourceConfigException
* @return void
*/
public function testCallbackSourceChangeUnknownDatasource() {
$this->loadFixtures('Post');
$TestModel = new Post();
$this->assertFalse($TestModel->find('all', array('connection' => 'foo'))); $this->assertFalse($TestModel->find('all', array('connection' => 'foo')));
} }

View file

@ -643,6 +643,7 @@ class ModelValidationTest extends BaseModelTest {
* Test that missing validation methods trigger errors in development mode. * Test that missing validation methods trigger errors in development mode.
* Helps to make developement easier. * Helps to make developement easier.
* *
* @expectedException PHPUnit_Framework_Error
* @return void * @return void
*/ */
public function testMissingValidationErrorTriggering() { public function testMissingValidationErrorTriggering() {
@ -656,7 +657,6 @@ class ModelValidationTest extends BaseModelTest {
'required' => true 'required' => true
) )
); );
$this->expectError();
$TestModel->invalidFields(array('fieldList' => array('title'))); $TestModel->invalidFields(array('fieldList' => array('title')));
} }

View file

@ -2145,12 +2145,18 @@ class ModelWriteTest extends BaseModelTest {
$TestModel = new TheVoid(); $TestModel = new TheVoid();
$this->assertFalse($TestModel->exists()); $this->assertFalse($TestModel->exists());
}
/**
* testRecordExistsMissingTable method
*
* @expectedException PDOException
* @return void
*/
public function testRecordExistsMissingTable() {
$TestModel = new TheVoid();
$TestModel->id = 5; $TestModel->id = 5;
$this->expectError(); $TestModel->exists();
ob_start();
$this->assertFalse($TestModel->exists());
$output = ob_get_clean();
} }
/** /**

View file

@ -378,11 +378,17 @@ class HttpResponseTest extends CakeTestCase {
$r = $this->HttpResponse->decodeChunkedBody($encoded); $r = $this->HttpResponse->decodeChunkedBody($encoded);
$this->assertEquals($r['body'], $decoded); $this->assertEquals($r['body'], $decoded);
$this->assertEquals($r['header'], array('foo-header' => 'bar', 'cake' => 'PHP')); $this->assertEquals($r['header'], array('foo-header' => 'bar', 'cake' => 'PHP'));
}
/**
* testDecodeChunkedBodyError method
*
* @expectedException SocketException
* @return void
*/
public function testDecodeChunkedBodyError() {
$encoded = "19\r\nThis is a chunked message\r\nE\r\n\nThat is cool\n\r\n"; $encoded = "19\r\nThis is a chunked message\r\nE\r\n\nThat is cool\n\r\n";
$this->expectError();
$r = $this->HttpResponse->decodeChunkedBody($encoded); $r = $this->HttpResponse->decodeChunkedBody($encoded);
$this->assertEquals($r, false);
} }
/** /**

View file

@ -546,12 +546,18 @@ class HttpSocketTest extends CakeTestCase {
$request = array('method' => 'POST', 'uri' => 'http://www.cakephp.org/posts/add', 'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today')); $request = array('method' => 'POST', 'uri' => 'http://www.cakephp.org/posts/add', 'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today'));
$response = $this->Socket->request($request); $response = $this->Socket->request($request);
$this->assertEquals($this->Socket->request['body'], "name=HttpSocket-is-released&date=today"); $this->assertEquals($this->Socket->request['body'], "name=HttpSocket-is-released&date=today");
}
/**
* The "*" asterisk character is only allowed for the following methods: OPTIONS.
*
* @expectedException SocketException
* @return void
*/
public function testRequestNotAllowedUri() {
$this->Socket->reset();
$request = array('uri' => '*', 'method' => 'GET'); $request = array('uri' => '*', 'method' => 'GET');
$this->expectError();
$response = $this->Socket->request($request); $response = $this->Socket->request($request);
$this->assertFalse($response);
$this->assertFalse($this->Socket->response);
} }
/** /**
@ -1036,20 +1042,20 @@ class HttpSocketTest extends CakeTestCase {
/** /**
* testBadBuildRequestLine method * testBadBuildRequestLine method
* *
* @expectedException SocketException
* @return void * @return void
*/ */
public function testBadBuildRequestLine() { public function testBadBuildRequestLine() {
$this->expectError();
$r = $this->Socket->buildRequestLine('Foo'); $r = $this->Socket->buildRequestLine('Foo');
} }
/** /**
* testBadBuildRequestLine2 method * testBadBuildRequestLine2 method
* *
* @expectedException SocketException
* @return void * @return void
*/ */
public function testBadBuildRequestLine2() { public function testBadBuildRequestLine2() {
$this->expectError();
$r = $this->Socket->buildRequestLine("GET * HTTP/1.1\r\n"); $r = $this->Socket->buildRequestLine("GET * HTTP/1.1\r\n");
} }

View file

@ -144,10 +144,17 @@ class SecurityTest extends CakeTestCase {
$key = 'my_key'; $key = 'my_key';
$result = Security::cipher($txt, $key); $result = Security::cipher($txt, $key);
$this->assertEqual(Security::cipher($result, $key), $txt); $this->assertEqual(Security::cipher($result, $key), $txt);
}
/**
* testCipherEmptyKey method
*
* @expectedException PHPUnit_Framework_Error
* @return void
*/
public function testCipherEmptyKey() {
$txt = 'some_text'; $txt = 'some_text';
$key = ''; $key = '';
$this->expectError();
$result = Security::cipher($txt, $key); $result = Security::cipher($txt, $key);
} }
} }