Permalink
Browse files

Inheritance fix for CakeTestCase

Fix overriden methods to be static like other methods in
PHPUnit_Framework_Assert.
Fixes #2170

Signed-off-by: mark_story <mark@mark-story.com>
  • Loading branch information...
1 parent 1244656 commit 010abd9e189cc37cbea2ce3a294aa4304ad6e669 @dereuromark dereuromark committed with markstory Oct 26, 2011
Showing with 18 additions and 18 deletions.
  1. +18 −18 lib/Cake/TestSuite/CakeTestCase.php
@@ -387,8 +387,8 @@ protected function _array_permute($items, $perms = array()) {
* @param string $message the text to display if the assertion is not correct
* @return void
*/
- protected function assertEqual($result, $expected, $message = '') {
- return $this->assertEquals($expected, $result, $message);
+ protected static function assertEqual($result, $expected, $message = '') {
+ return self::assertEquals($expected, $result, $message);
}
/**
@@ -399,8 +399,8 @@ protected function assertEqual($result, $expected, $message = '') {
* @param string $message the text to display if the assertion is not correct
* @return void
*/
- protected function assertNotEqual($result, $expected, $message = '') {
- return $this->assertNotEquals($expected, $result, $message);
+ protected static function assertNotEqual($result, $expected, $message = '') {
+ return self::assertNotEquals($expected, $result, $message);
}
/**
@@ -411,8 +411,8 @@ protected function assertNotEqual($result, $expected, $message = '') {
* @param string $message the text to display if the assertion is not correct
* @return void
*/
- protected function assertPattern($pattern, $string, $message = '') {
- return $this->assertRegExp($pattern, $string, $message);
+ protected static function assertPattern($pattern, $string, $message = '') {
+ return self::assertRegExp($pattern, $string, $message);
}
/**
@@ -423,8 +423,8 @@ protected function assertPattern($pattern, $string, $message = '') {
* @param string $message the text to display if the assertion is not correct
* @return void
*/
- protected function assertIdentical($actual, $expected, $message = '') {
- return $this->assertSame($expected, $actual, $message);
+ protected static function assertIdentical($actual, $expected, $message = '') {
+ return self::assertSame($expected, $actual, $message);
}
/**
@@ -435,8 +435,8 @@ protected function assertIdentical($actual, $expected, $message = '') {
* @param string $message the text to display if the assertion is not correct
* @return void
*/
- protected function assertNotIdentical($actual, $expected, $message = '') {
- return $this->assertNotSame($expected, $actual, $message);
+ protected static function assertNotIdentical($actual, $expected, $message = '') {
+ return self::assertNotSame($expected, $actual, $message);
}
/**
@@ -447,8 +447,8 @@ protected function assertNotIdentical($actual, $expected, $message = '') {
* @param string $message the text to display if the assertion is not correct
* @return void
*/
- protected function assertNoPattern($pattern, $string, $message = '') {
- return $this->assertNotRegExp($pattern, $string, $message);
+ protected static function assertNoPattern($pattern, $string, $message = '') {
+ return self::assertNotRegExp($pattern, $string, $message);
}
protected function assertNoErrors() {
@@ -487,8 +487,8 @@ protected function expectException($name = 'Exception', $message = '') {
* @param string $message the text to display if the assertion is not correct
* @return void
*/
- protected function assertReference(&$first, &$second, $message = '') {
- return $this->assertSame($first, $second, $message);
+ protected static function assertReference(&$first, &$second, $message = '') {
+ return self::assertSame($first, $second, $message);
}
/**
@@ -499,8 +499,8 @@ protected function assertReference(&$first, &$second, $message = '') {
* @param string $message
* @return void
*/
- protected function assertIsA($object, $type, $message = '') {
- return $this->assertInstanceOf($type, $object, $message);
+ protected static function assertIsA($object, $type, $message = '') {
+ return self::assertInstanceOf($type, $object, $message);
}
/**
@@ -512,10 +512,10 @@ protected function assertIsA($object, $type, $message = '') {
* @param string $message the text to display if the assertion is not correct
* @return void
*/
- protected function assertWithinMargin($result, $expected, $margin, $message = '') {
+ protected static function assertWithinMargin($result, $expected, $margin, $message = '') {
$upper = $result + $margin;
$lower = $result - $margin;
- $this->assertTrue((($expected <= $upper) && ($expected >= $lower)), $message);
+ return self::assertTrue((($expected <= $upper) && ($expected >= $lower)), $message);
}
/**

10 comments on commit 010abd9

@ADmad
Member
ADmad commented on 010abd9 Oct 27, 2011

Hmm so the functions are static now but all test cases still access them using $this-> which isn't too nice. It would throws errors if one uses E_STRICT error reporting.

@renan
Member
renan commented on 010abd9 Oct 27, 2011

It would give E_STRICT errors anyway.

@dereuromark
Member

indeed. we could either make the tests use the new methods instead (has to be done some day anyway) or simply switch to static calls.

But working with E_STRICT is kind of impossible at the moment anyway with the current 2.0 head.
too much stuff not yet commited for E_STRICT to be useful

@ADmad
Member
ADmad commented on 010abd9 Oct 27, 2011

@renansaddam Yes that was my point, I probably didn't phrase it properly. This fix should have been done along with updating all test cases to call the asserts statically. Personally I don't like incomplete fixes.

@dereuromark
Member

it doesnt throw E_STRICT errors even if I explicitly set. Thats why I never noticed. I guess that is due to the Cake bootstrap "error_reporting(E_ALL & ~E_DEPRECATED);" it is loaded after the App Boostrap. Not sure if that is the intension...

@ADmad
Member
ADmad commented on 010abd9 Oct 27, 2011

You need to update your error reporting level in app/Config/core.php

@dereuromark
Member

thats another thing that the migration guide or shell was missing ;) Some core configs I did not yet import from the original core file. Anyway, the App itself throws lots of E_STRICT errors, the Tests NONE. how is that possible...

@ADmad
Member
ADmad commented on 010abd9 Oct 27, 2011

Think of it as easter eggs we have kept scattered around for people to find.

@markstory
Member

You can always access static methods in a non static context without errors, PHPUnit has its assertion methods setup this way as well, no change is required. You only get an E_STRICT when you call a instance method in a static setting.

@dereuromark
Member

that explains why everything is fine :) thx for the clarification. I was looking for the error the last hour.

Please sign in to comment.