Permalink
Browse files

API CHANGE Removed assertType() and assertEmpty() workarounds. Use as…

…sertInstanceOf()

instead of assertType(), assertEmpty() is available in PHPUnit 3.5+.
PHPUnit 3.4 is no longer supported, so please upgrade your version to
work.

MINOR Removed FullTestSuite which was a workaround for PHPUnit but not
used.
  • Loading branch information...
halkyon committed May 9, 2012
1 parent 8b607db commit b1e17578c776b4f100803f155c35df86fe45d92a
@@ -16,7 +16,7 @@ public function testBasicMenuHandling() {
CMSMenu::add_controller('CMSMenuTest_LeftAndMainController');
$menuItems = CMSMenu::get_menu_items();
$menuItem = $menuItems['CMSMenuTest_LeftAndMainController'];
- $this->assertType('CMSMenuItem', $menuItem, 'Controller menu item is of class CMSMenuItem');
+ $this->assertInstanceOf('CMSMenuItem', $menuItem, 'Controller menu item is of class CMSMenuItem');
$this->assertEquals($menuItem->url, singleton('CMSMenuTest_LeftAndMainController')->Link(), 'Controller menu item has the correct link');
$this->assertEquals($menuItem->controller, 'CMSMenuTest_LeftAndMainController', 'Controller menu item has the correct controller class');
$this->assertEquals($menuItem->priority, singleton('CMSMenuTest_LeftAndMainController')->stat('menu_priority'), 'Controller menu item has the correct priority');
@@ -26,7 +26,7 @@ public function testBasicMenuHandling() {
CMSMenu::add_link('LinkCode', 'link title', 'http://www.example.com');
$menuItems = CMSMenu::get_menu_items();
$menuItem = $menuItems['LinkCode'];
- $this->assertType('CMSMenuItem', $menuItem, 'Link menu item is of class CMSMenuItem');
+ $this->assertInstanceOf('CMSMenuItem', $menuItem, 'Link menu item is of class CMSMenuItem');
$this->assertEquals($menuItem->title, 'link title', 'Link menu item has the correct title');
$this->assertEquals($menuItem->url,'http://www.example.com', 'Link menu item has the correct link');
$this->assertNull($menuItem->controller, 'Link menu item has no controller class');
@@ -53,7 +53,7 @@ public function testAdvancedMenuHandling() {
CMSMenu::clear_menu();
CMSMenu::populate_menu();
$menuItem = CMSMenu::get_menu_item('SecurityAdmin');
- $this->assertType('CMSMenuItem', $menuItem, 'SecurityAdmin menu item exists');
+ $this->assertInstanceOf('CMSMenuItem', $menuItem, 'SecurityAdmin menu item exists');
$this->assertEquals($menuItem->url, singleton('SecurityAdmin')->Link(), 'Menu item has the correct link');
$this->assertEquals($menuItem->controller, 'SecurityAdmin', 'Menu item has the correct controller class');
$this->assertEquals(
@@ -98,7 +98,7 @@ public function testLeftAndMainSubclasses() {
$response = $this->get($link);
- $this->assertType('SS_HTTPResponse', $response, "$link should return a response object");
+ $this->assertInstanceOf('SS_HTTPResponse', $response, "$link should return a response object");
$this->assertEquals(200, $response->getStatusCode(), "$link should return 200 status code");
// Check that a HTML page has been returned
$this->assertRegExp('/<html[^>]*>/i', $response->getBody(), "$link should contain <html> tag");
View
@@ -652,61 +652,6 @@ function assertDOSAllMatch($match, $dataObjectSet) {
}
}
- /**
- * Backported from PHPUnit 3.4 in order to maintain backwards
- * compatibility: assertType() is deprecated in PHPUnit 3.5 (with PHP 5.2.7+),
- * but as SilverStripe 2.3 and 2.4 support PHP 5.1 we can't require it.
- */
- public static function assertType($expected, $actual, $message = '') {
- // PHPUnit_Util_DeprecatedFeature_Logger::log(
- // 'assertType() will be removed in PHPUnit 3.6 and should no longer ' .
- // 'be used. assertInternalType() should be used for asserting ' .
- // 'internal types such as "integer" or "string" whereas ' .
- // 'assertInstanceOf() should be used for asserting that an object is ' .
- // 'an instance of a specified class or interface.'
- // );
-
- if (is_string($expected)) {
- if (PHPUnit_Util_Type::isType($expected)) {
- $constraint = new PHPUnit_Framework_Constraint_IsType(
- $expected
- );
- }
-
- else if (class_exists($expected) || interface_exists($expected)) {
- $constraint = new PHPUnit_Framework_Constraint_IsInstanceOf(
- $expected
- );
- }
-
- else {
- throw PHPUnit_Util_InvalidArgumentHelper::factory(
- 1, 'class or interface name'
- );
- }
- } else {
- throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
- }
-
- self::assertThat($actual, $constraint, $message);
- }
-
- /**
- * Provide assertEmpty() in PHPUnit <3.5.
- * We want to support PHPUnit 3.4, as this is the most recent release available
- * to environments running PHP <=5.2.6, such as Debian Lenny.
- */
- public static function assertEmpty($item, $message = '') {
- if(class_exists('PHPUnit_Framework_Constraint_IsEmpty')) {
- parent::assertEmpty($item, $message);
- } else {
- if(!empty($item)) {
- $message = $message ? $message : "Failed asserting that " . var_export($item, true) . " is empty.";
- throw new PHPUnit_Framework_AssertionFailedError($message);
- }
- }
- }
-
/**
* Helper function for the DOS matchers
*/
View
@@ -1,83 +0,0 @@
-<?php
-/**
- * Alternative to letting PHPUnit handle class retrieval via
- * traversing the filesystem. Works around restrictions of PHPUnit
- * on running tests on multiple directories at once, without resorting
- * to group or testsuite definitions in a custom phpunit.xml file.
- *
- * Usage:
- * - "phpunit framework/tests/FullTestSuite.php"
- * (all tests)
- * - "phpunit framework/tests/FullTestSuite.php '' module=framework,cms"
- * (comma-separated modules. empty quotes are necessary to avoid PHPUnit argument confusion)
- *
- * See http://www.phpunit.de/manual/current/en/organizing-tests.html#organizing-tests.testsuite
- *
- * Note: We can't unit test this class because of segfaults in PHP5.3 when trying to
- * use get_all_tests() within a SapphireTest.
- *
- * @package framework
- * @subpackage testing
- */
-class FullTestSuite {
-
- /**
- * Called by the PHPUnit runner to gather runnable tests.
- *
- * @return PHPUnit_Framework_TestSuite
- */
- public static function suite() {
- require_once(dirname(__FILE__) . '/bootstrap.php');
-
- $suite = new PHPUnit_Framework_TestSuite();
- if(isset($_GET['module'])) {
- $classList = self::get_module_tests($_GET['module']);
- } else {
- $classList = self::get_all_tests();
- }
-
- foreach($classList as $className) {
- $suite->addTest(new SapphireTestSuite($className));
- }
-
- return $suite;
- }
-
- /**
- * @return Array
- */
- public static function get_all_tests() {
- require_once(dirname(__FILE__) . '/bootstrap.php');
-
- TestRunner::use_test_manifest();
- $tests = ClassInfo::subclassesFor('SapphireTest');
- array_shift($tests);
-
- return $tests;
- }
-
- /**
- * Run tests for one or more "modules".
- * A module is generally a toplevel folder, e.g. "mysite" or "framework".
- *
- * @param String $nameStr
- * @return Array
- */
- protected static function get_module_tests($namesStr) {
- require_once(dirname(__FILE__) . '/bootstrap.php');
-
- $tests = array();
- $names = explode(',', $namesStr);
- foreach($names as $name) {
- $classesForModule = ClassInfo::classes_for_folder($name);
- if($classesForModule) foreach($classesForModule as $class) {
- if(class_exists($class) && is_subclass_of($class, 'SapphireTest')) {
- $tests[] = $class;
- }
- }
- }
-
- return $tests;
- }
-}
-
@@ -165,7 +165,7 @@ public function testTestRequestCarriesGlobals() {
$url = 'DirectorTestRequest_Controller/' . sprintf($testfunction, ucfirst($method)) . '?' . http_build_query($fixture);
$getresponse = Director::test($url, $fixture, null, strtoupper($method), null, null, $fixture);
- $this->assertType('SS_HTTPResponse', $getresponse, 'Director::test() returns SS_HTTPResponse');
+ $this->assertInstanceOf('SS_HTTPResponse', $getresponse, 'Director::test() returns SS_HTTPResponse');
$this->assertEquals($fixture['somekey'], $getresponse->getBody(), 'Director::test() ' . $testfunction);
}
}
@@ -22,7 +22,7 @@ class RequestHandlingTest extends FunctionalTest {
function testConstructedWithNullRequest() {
$r = new RequestHandler();
- $this->assertType('NullHTTPRequest', $r->getRequest());
+ $this->assertInstanceOf('NullHTTPRequest', $r->getRequest());
}
function testRequestHandlerChainingAllParams() {
@@ -165,19 +165,19 @@ public function testGetExtensions() {
$inst = new ObjectTest_ExtensionTest();
$extensions = $inst->getExtensionInstances();
$this->assertEquals(count($extensions), 2);
- $this->assertType(
+ $this->assertInstanceOf(
'ObjectTest_ExtendTest1',
$extensions['ObjectTest_ExtendTest1']
);
- $this->assertType(
+ $this->assertInstanceOf(
'ObjectTest_ExtendTest2',
$extensions['ObjectTest_ExtendTest2']
);
- $this->assertType(
+ $this->assertInstanceOf(
'ObjectTest_ExtendTest1',
$inst->getExtensionInstance('ObjectTest_ExtendTest1')
);
- $this->assertType(
+ $this->assertInstanceOf(
'ObjectTest_ExtendTest2',
$inst->getExtensionInstance('ObjectTest_ExtendTest2')
);
View
@@ -26,7 +26,6 @@ function testExistingWriter() {
SS_Log::add_writer($testFileWriter, SS_Log::WARN);
$writers = SS_Log::get_writers();
- $this->assertType('array', $writers);
$this->assertEquals(2, count($writers));
}
@@ -38,12 +37,11 @@ function testRemoveWriter() {
SS_Log::remove_writer($testEmailWriter);
$writers = SS_Log::get_writers();
- $this->assertType('array', $writers);
+
$this->assertEquals(1, count($writers));
SS_Log::remove_writer($testFileWriter);
$writers = SS_Log::get_writers();
- $this->assertType('array', $writers);
$this->assertEquals(0, count($writers));
}
@@ -61,10 +61,10 @@ function testCreateWithFilenameWithSubfolder() {
$this->assertEquals($testfilePath, $file->Filename, '"Filename" property remains unchanged');
// TODO This should be auto-detected, see File->updateFilesystem()
- // $this->assertType('Folder', $file->Parent(), 'Parent folder is created in database');
+ // $this->assertInstanceOf('Folder', $file->Parent(), 'Parent folder is created in database');
// $this->assertFileExists($file->Parent()->getFullPath(), 'Parent folder is created on filesystem');
// $this->assertEquals('FileTest', $file->Parent()->Name);
- // $this->assertType('Folder', $file->Parent()->Parent(), 'Grandparent folder is created in database');
+ // $this->assertInstanceOf('Folder', $file->Parent()->Parent(), 'Grandparent folder is created in database');
// $this->assertFileExists($file->Parent()->Parent()->getFullPath(), 'Grandparent folder is created on filesystem');
// $this->assertEquals('assets', $file->Parent()->Parent()->Name);
}
View
@@ -241,12 +241,12 @@ function testGloballyDisabledSecurityTokenInheritsToNewForm() {
SecurityToken::enable();
$form1 = $this->getStubForm();
- $this->assertType('SecurityToken', $form1->getSecurityToken());
+ $this->assertInstanceOf('SecurityToken', $form1->getSecurityToken());
SecurityToken::disable();
$form2 = $this->getStubForm();
- $this->assertType('NullSecurityToken', $form2->getSecurityToken());
+ $this->assertInstanceOf('NullSecurityToken', $form2->getSecurityToken());
SecurityToken::enable();
}
@@ -255,7 +255,7 @@ function testDisableSecurityTokenDoesntAddTokenFormField() {
SecurityToken::enable();
$formWithToken = $this->getStubForm();
- $this->assertType(
+ $this->assertInstanceOf(
'HiddenField',
$formWithToken->Fields()->fieldByName(SecurityToken::get_default_name()),
'Token field added by default'
@@ -8,7 +8,7 @@ class GridFieldConfigTest extends SapphireTest {
function testGetComponents() {
$config = GridFieldConfig::create();
- $this->assertType('ArrayList', $config->getComponents());
+ $this->assertInstanceOf('ArrayList', $config->getComponents());
$this->assertEquals($config->getComponents()->Count(), 0);
$config
View
@@ -441,8 +441,8 @@ function testRegisterTranslator() {
i18n::register_translator($translator, 'custom', 10);
$translators = i18n::get_translators();
$this->assertArrayHasKey('custom', $translators[10]);
- $this->assertType('Zend_Translate', $translators[10]['custom']);
- $this->assertType('i18nTest_CustomTranslatorAdapter', $translators[10]['custom']->getAdapter());
+ $this->assertInstanceOf('Zend_Translate', $translators[10]['custom']);
+ $this->assertInstanceOf('i18nTest_CustomTranslatorAdapter', $translators[10]['custom']->getAdapter());
i18n::unregister_translator('custom');
$translators = i18n::get_translators();
@@ -41,10 +41,10 @@ function testOneToManyAssociationWithExtension() {
$object = DataObject::get_one('DataExtensionTest_RelatedObject', "\"ContactID\" = {$contactID}");
$this->assertNotNull($object, 'Related object not null');
- $this->assertType('DataExtensionTest_Member', $object->Contact(), 'Related contact is a member dataobject');
- $this->assertType('DataExtensionTest_Member', $object->getComponent('Contact'), 'getComponent does the same thing as Contact()');
+ $this->assertInstanceOf('DataExtensionTest_Member', $object->Contact(), 'Related contact is a member dataobject');
+ $this->assertInstanceOf('DataExtensionTest_Member', $object->getComponent('Contact'), 'getComponent does the same thing as Contact()');
- $this->assertType('DataExtensionTest_RelatedObject', $contact->RelatedObjects()->First());
+ $this->assertInstanceOf('DataExtensionTest_RelatedObject', $contact->RelatedObjects()->First());
$this->assertEquals("Lorem ipsum dolor", $contact->RelatedObjects()->First()->FieldOne);
$this->assertEquals("Random notes", $contact->RelatedObjects()->First()->FieldTwo);
$contact->delete();
@@ -143,7 +143,7 @@ function testPopulateDefaults() {
function testDbObjectOnExtendedFields() {
$member = $this->objFromFixture('DataExtensionTest_Member', 'member1');
$this->assertNotNull($member->dbObject('Website'));
- $this->assertType('Varchar', $member->dbObject('Website'));
+ $this->assertInstanceOf('Varchar', $member->dbObject('Website'));
}
function testExtensionCanBeAppliedToDataObject() {
@@ -161,7 +161,7 @@ function testByID() {
$team = DataList::create("DataObjectTest_Team")->byID($id);
// byID() returns a DataObject, rather than a DataList
- $this->assertType('DataObjectTest_Team', $team);
+ $this->assertInstanceOf('DataObjectTest_Team', $team);
$this->assertEquals('Team 2', $team->Title);
}
@@ -187,7 +187,7 @@ function testLazyLoadedFieldsHasOneRelation() {
$subteam1Lazy = $teams->find('ID', $subteam1->ID);
$parentTeamLazy = $subteam1Lazy->ParentTeam();
- $this->assertType('DataObjectTest_Team', $parentTeamLazy);
+ $this->assertInstanceOf('DataObjectTest_Team', $parentTeamLazy);
$this->assertEquals($parentTeam->ID, $parentTeamLazy->ID);
}
@@ -719,15 +719,15 @@ function testNewClassInstance() {
$changedFields = $changedDO->getChangedFields();
// Don't write the record, it will reset changed fields
- $this->assertType('DataObjectTest_SubTeam', $changedDO);
+ $this->assertInstanceOf('DataObjectTest_SubTeam', $changedDO);
$this->assertEquals($changedDO->ClassName, 'DataObjectTest_SubTeam');
$this->assertContains('ClassName', array_keys($changedFields));
$this->assertEquals($changedFields['ClassName']['before'], 'DataObjectTest_Team');
$this->assertEquals($changedFields['ClassName']['after'], 'DataObjectTest_SubTeam');
$changedDO->write();
- $this->assertType('DataObjectTest_SubTeam', $changedDO);
+ $this->assertInstanceOf('DataObjectTest_SubTeam', $changedDO);
$this->assertEquals($changedDO->ClassName, 'DataObjectTest_SubTeam');
}
@@ -21,14 +21,14 @@ class MoneyTest extends SapphireTest {
function testMoneyFieldsReturnedAsObjects() {
$obj = $this->objFromFixture('MoneyTest_DataObject', 'test1');
- $this->assertType('Money', $obj->MyMoney);
+ $this->assertInstanceOf('Money', $obj->MyMoney);
}
function testLoadFromFixture() {
$obj = $this->objFromFixture('MoneyTest_DataObject', 'test1');
- $this->assertType('Money', $obj->MyMoney);
+ $this->assertInstanceOf('Money', $obj->MyMoney);
$this->assertEquals($obj->MyMoney->getCurrency(), 'EUR');
$this->assertEquals($obj->MyMoney->getAmount(), 1.23);
}
@@ -42,7 +42,7 @@ function testDataObjectChangedFields() {
$this->assertNotContains('MyMoney', array_keys($changed));
// With changes
- $this->assertType('Money', $obj->MyMoney);
+ $this->assertInstanceOf('Money', $obj->MyMoney);
$obj->MyMoney->setAmount(99);
$changed = $obj->getChangedFields();
$this->assertContains('MyMoney', array_keys($changed), 'Field is detected as changed');
@@ -229,7 +229,7 @@ function testExists() {
function testLoadIntoDataObject() {
$obj = new MoneyTest_DataObject();
- $this->assertType('Money', $obj->obj('MyMoney'));
+ $this->assertInstanceOf('Money', $obj->obj('MyMoney'));
$m = new Money();
$m->setValue(array(
Oops, something went wrong.

0 comments on commit b1e1757

Please sign in to comment.