Skip to content

Commit

Permalink
Refactoring expectError() calls to PHPUnit annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Jelle Henkens committed Sep 13, 2011
1 parent 8272705 commit 7ba2f90
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 37 deletions.
5 changes: 2 additions & 3 deletions lib/Cake/Test/Case/Cache/CacheTest.php
Expand Up @@ -111,10 +111,10 @@ public function testConfigWithLibAndPluginEngines() {
*
* Test that the cache class doesn't cause fatal errors with a partial path
*
* @expectedException PHPUnit_Framework_Error_Warning
* @return void
*/
public function testInvaidConfig() {
$this->expectError();
public function testInvalidConfig() {
Cache::config('invalid', array(
'engine' => 'File',
'duration' => '+1 year',
Expand All @@ -124,7 +124,6 @@ public function testInvaidConfig() {
'random' => 'wii'
));
$read = Cache::read('Test', 'invalid');
$this->assertEqual($read, null);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Test/Case/Cache/Engine/FileEngineTest.php
Expand Up @@ -317,12 +317,12 @@ public function testWriteQuotedString() {
/**
* check that FileEngine generates an error when a configured Path does not exist.
*
* @expectedException PHPUnit_Framework_Error_Warning
* @return void
*/
public function testErrorWhenPathDoesNotExist() {
$this->skipIf(is_dir(TMP . 'tests' . DS . 'file_failure'), 'Cannot run test directory exists.');

$this->expectError();
Cache::config('failure', array(
'engine' => 'File',
'path' => TMP . 'tests' . DS . 'file_failure'
Expand Down
18 changes: 16 additions & 2 deletions lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php
Expand Up @@ -147,12 +147,19 @@ public function testContainments() {
/**
* testInvalidContainments method
*
* @expectedException PHPUnit_Framework_Error_Warning
* @return void
*/
public function testInvalidContainments() {
$this->expectError();
$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));
$r = $this->__containments($this->Article, array('Comment', 'InvalidBinding'));
}
Expand Down Expand Up @@ -226,8 +233,15 @@ public function testBeforeFind() {
$r = $this->Article->find('all', array('contain' => array()));
$this->assertFalse(Set::matches('/User', $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')));
}

Expand Down
41 changes: 27 additions & 14 deletions lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php
Expand Up @@ -2479,17 +2479,23 @@ public function testSchema() {
$Schema = new CakeSchema();
$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');
$this->assertTrue(empty($result));

$result = $this->Dbo->dropSchema($Schema, 'table');
$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
*
Expand Down Expand Up @@ -2693,16 +2699,6 @@ public function testBuildIndex() {
* @return void
*/
public function testBuildColumn2() {
$this->expectError();
$data = array(
'name' => 'testName',
'type' => 'varchar(255)',
'default',
'null' => true,
'key'
);
$this->Dbo->buildColumn($data);

$data = array(
'name' => 'testName',
'type' => 'string',
Expand Down Expand Up @@ -2800,6 +2796,23 @@ public function testBuildColumn2() {
$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()
*
Expand Down
13 changes: 10 additions & 3 deletions lib/Cake/Test/Case/Model/ModelDeleteTest.php
Expand Up @@ -417,11 +417,18 @@ public function testDeleteAll() {

$result = $TestModel->deleteAll(array('Article.user_id' => 999));
$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));
ob_get_clean();
$this->assertFalse($result, 'deleteAll returned true when find query generated sql error. %s');
}

Expand Down
11 changes: 10 additions & 1 deletion lib/Cake/Test/Case/Model/ModelReadTest.php
Expand Up @@ -4943,8 +4943,17 @@ public function testCallbackSourceChange() {
$this->loadFixtures('Post');
$TestModel = new Post();
$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')));
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Test/Case/Model/ModelValidationTest.php
Expand Up @@ -643,6 +643,7 @@ public function testValidatesWithModelsAndSaveAll() {
* Test that missing validation methods trigger errors in development mode.
* Helps to make developement easier.
*
* @expectedException PHPUnit_Framework_Error
* @return void
*/
public function testMissingValidationErrorTriggering() {
Expand All @@ -656,7 +657,6 @@ public function testMissingValidationErrorTriggering() {
'required' => true
)
);
$this->expectError();
$TestModel->invalidFields(array('fieldList' => array('title')));
}

Expand Down
14 changes: 10 additions & 4 deletions lib/Cake/Test/Case/Model/ModelWriteTest.php
Expand Up @@ -2145,12 +2145,18 @@ public function testRecordExists() {

$TestModel = new TheVoid();
$this->assertFalse($TestModel->exists());
}

/**
* testRecordExistsMissingTable method
*
* @expectedException PDOException
* @return void
*/
public function testRecordExistsMissingTable() {
$TestModel = new TheVoid();
$TestModel->id = 5;
$this->expectError();
ob_start();
$this->assertFalse($TestModel->exists());
$output = ob_get_clean();
$TestModel->exists();
}

/**
Expand Down
10 changes: 8 additions & 2 deletions lib/Cake/Test/Case/Network/Http/HttpResponseTest.php
Expand Up @@ -378,11 +378,17 @@ public function testDecodeChunkedBody() {
$r = $this->HttpResponse->decodeChunkedBody($encoded);
$this->assertEquals($r['body'], $decoded);
$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";
$this->expectError();
$r = $this->HttpResponse->decodeChunkedBody($encoded);
$this->assertEquals($r, false);
}

/**
Expand Down
16 changes: 11 additions & 5 deletions lib/Cake/Test/Case/Network/Http/HttpSocketTest.php
Expand Up @@ -546,12 +546,18 @@ public function testRequest() {
$request = array('method' => 'POST', 'uri' => 'http://www.cakephp.org/posts/add', 'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today'));
$response = $this->Socket->request($request);
$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');
$this->expectError();
$response = $this->Socket->request($request);
$this->assertFalse($response);
$this->assertFalse($this->Socket->response);
}

/**
Expand Down Expand Up @@ -1036,20 +1042,20 @@ public function testBuildRequestLine() {
/**
* testBadBuildRequestLine method
*
* @expectedException SocketException
* @return void
*/
public function testBadBuildRequestLine() {
$this->expectError();
$r = $this->Socket->buildRequestLine('Foo');
}

/**
* testBadBuildRequestLine2 method
*
* @expectedException SocketException
* @return void
*/
public function testBadBuildRequestLine2() {
$this->expectError();
$r = $this->Socket->buildRequestLine("GET * HTTP/1.1\r\n");
}

Expand Down
9 changes: 8 additions & 1 deletion lib/Cake/Test/Case/Utility/SecurityTest.php
Expand Up @@ -144,10 +144,17 @@ public function testCipher() {
$key = 'my_key';
$result = Security::cipher($txt, $key);
$this->assertEqual(Security::cipher($result, $key), $txt);
}

/**
* testCipherEmptyKey method
*
* @expectedException PHPUnit_Framework_Error
* @return void
*/
public function testCipherEmptyKey() {
$txt = 'some_text';
$key = '';
$this->expectError();
$result = Security::cipher($txt, $key);
}
}

0 comments on commit 7ba2f90

Please sign in to comment.