Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactoring expectError() calls to PHPUnit annotations

  • Loading branch information...
commit 7ba2f90b2afb16b752ec5e19f450ed8ddbc86a45 1 parent 8272705
Jelle Henkens jellehenkens authored
5 lib/Cake/Test/Case/Cache/CacheTest.php
View
@@ -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',
@@ -124,7 +124,6 @@ public function testInvaidConfig() {
'random' => 'wii'
));
$read = Cache::read('Test', 'invalid');
- $this->assertEqual($read, null);
}
/**
2  lib/Cake/Test/Case/Cache/Engine/FileEngineTest.php
View
@@ -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'
18 lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php
View
@@ -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'));
}
@@ -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')));
}
41 lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php
View
@@ -2479,10 +2479,6 @@ 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));
@@ -2491,6 +2487,16 @@ public function testSchema() {
}
/**
+ * testDropSchemaNoSchema method
+ *
+ * @expectedException PHPUnit_Framework_Error
+ * @return void
+ */
+ public function testDropSchemaNoSchema() {
+ $result = $this->Dbo->dropSchema(null);
+ }
+
+/**
* testOrderParsing method
*
* @return void
@@ -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',
@@ -2801,6 +2797,23 @@ public function testBuildColumn2() {
}
/**
+ * 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()
*
* @return void
13 lib/Cake/Test/Case/Model/ModelDeleteTest.php
View
@@ -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');
}
11 lib/Cake/Test/Case/Model/ModelReadTest.php
View
@@ -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')));
}
2  lib/Cake/Test/Case/Model/ModelValidationTest.php
View
@@ -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() {
@@ -656,7 +657,6 @@ public function testMissingValidationErrorTriggering() {
'required' => true
)
);
- $this->expectError();
$TestModel->invalidFields(array('fieldList' => array('title')));
}
14 lib/Cake/Test/Case/Model/ModelWriteTest.php
View
@@ -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();
}
/**
10 lib/Cake/Test/Case/Network/Http/HttpResponseTest.php
View
@@ -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);
}
/**
16 lib/Cake/Test/Case/Network/Http/HttpSocketTest.php
View
@@ -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);
}
/**
@@ -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");
}
9 lib/Cake/Test/Case/Utility/SecurityTest.php
View
@@ -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);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.