Skip to content

Commit

Permalink
Update test case Utility folder
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbasso committed May 26, 2012
1 parent 8ffd676 commit 773ce02
Show file tree
Hide file tree
Showing 15 changed files with 226 additions and 186 deletions.
19 changes: 12 additions & 7 deletions lib/Cake/Test/TestCase/Utility/ClassRegistryTest.php
Expand Up @@ -16,14 +16,19 @@
* @since CakePHP(tm) v 1.2.0.5432
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('ClassRegistry', 'Utility');
namespace Cake\Test\TestCase\Utility;
use Cake\TestSuite\Fixture\TestModel,
Cake\TestSuite\TestCase,
Cake\Core\Plugin,
Cake\Model\ConnectionManager,
Cake\Utility\ClassRegistry;

/**
* ClassRegisterModel class
*
* @package Cake.Test.Case.Utility
*/
class ClassRegisterModel extends CakeTestModel {
class ClassRegisterModel extends TestModel {

/**
* useTable property
Expand Down Expand Up @@ -160,7 +165,7 @@ public function doSomething();
*
* @package Cake.Test.Case.Utility
*/
class ClassRegistryTest extends CakeTestCase {
class ClassRegistryTest extends TestCase {

/**
* testAddModel method
Expand Down Expand Up @@ -285,7 +290,7 @@ public function testPluginAppModel() {
$this->assertFalse($TestRegistryPluginModel);

//Faking a plugin
CakePlugin::load('RegistryPlugin', array('path' => '/fake/path'));
Plugin::load('RegistryPlugin', array('path' => '/fake/path'));
$TestRegistryPluginModel = ClassRegistry::init('RegistryPlugin.TestRegistryPluginModel');
$this->assertTrue(is_a($TestRegistryPluginModel, 'TestRegistryPluginModel'));

Expand All @@ -297,7 +302,7 @@ public function testPluginAppModel() {
$PluginUserCopy = ClassRegistry::getObject('RegistryPluginUser');
$this->assertTrue(is_a($PluginUserCopy, 'RegistryPluginAppModel'));
$this->assertSame($PluginUser, $PluginUserCopy);
CakePlugin::unload();
Plugin::unload();
}

/**
Expand Down Expand Up @@ -330,7 +335,7 @@ public function testInitStrict() {
/**
* Test that you cannot init() an abstract class. An exception will be raised.
*
* @expectedException CakeException
* @expectedException Cake\Error\Exception
* @return void
*/
public function testInitAbstractClass() {
Expand All @@ -340,7 +345,7 @@ public function testInitAbstractClass() {
/**
* Test that you cannot init() an abstract class. A exception will be raised.
*
* @expectedException CakeException
* @expectedException Cake\Error\Exception
* @return void
*/
public function testInitInterface() {
Expand Down
46 changes: 25 additions & 21 deletions lib/Cake/Test/TestCase/Utility/DebuggerTest.php
Expand Up @@ -16,7 +16,12 @@
* @since CakePHP(tm) v 1.2.0.5432
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Debugger', 'Utility');
namespace Cake\Test\TestCase\Utility;
use Cake\Utility\Debugger,
Cake\TestSuite\TestCase,
Cake\Core\Configure,
Cake\Controller\Controller,
Cake\View\View;

/**
* DebugggerTestCaseDebuggger class
Expand All @@ -34,7 +39,7 @@ class DebuggerTestCaseDebugger extends Debugger {
*
* @package Cake.Test.Case.Utility
*/
class DebuggerTest extends CakeTestCase {
class DebuggerTest extends TestCase {

protected $_restoreError = false;

Expand Down Expand Up @@ -102,7 +107,7 @@ public function testExcerpt() {
* @return void
*/
public function testOutput() {
set_error_handler('Debugger::showError');
set_error_handler('Cake\Utility\Debugger::showError');
$this->_restoreError = true;

$result = Debugger::output(false);
Expand Down Expand Up @@ -158,7 +163,7 @@ public function testOutput() {
* @return void
*/
public function testChangeOutputFormats() {
set_error_handler('Debugger::showError');
set_error_handler('Cake\Utility\Debugger::showError');
$this->_restoreError = true;

Debugger::output('js', array(
Expand Down Expand Up @@ -204,7 +209,7 @@ public function testOutputAs() {
/**
* Test that choosing a non-existent format causes an exception
*
* @expectedException CakeException
* @expectedException Cake\Error\Exception
* @return void
*/
public function testOutputAsException() {
Expand All @@ -217,7 +222,7 @@ public function testOutputAsException() {
* @return void
*/
public function testAddFormat() {
set_error_handler('Debugger::showError');
set_error_handler('Cake\Utility\Debugger::showError');
$this->_restoreError = true;

Debugger::addFormat('js', array(
Expand Down Expand Up @@ -256,7 +261,7 @@ public function testAddFormat() {
* @return void
*/
public function testAddFormatCallback() {
set_error_handler('Debugger::showError');
set_error_handler('Cake\Utility\Debugger::showError');
$this->_restoreError = true;

Debugger::addFormat('callback', array('callback' => array($this, 'customFormat')));
Expand Down Expand Up @@ -292,7 +297,6 @@ public function testTrimPath() {
* @return void
*/
public function testExportVar() {
App::uses('Controller', 'Controller');
$Controller = new Controller();
$Controller->helpers = array('Html', 'Form');
$View = new View($Controller);
Expand All @@ -301,9 +305,9 @@ public function testExportVar() {

$result = Debugger::exportVar($View);
$expected = <<<TEXT
object(View) {
Helpers => object(HelperCollection) {}
Blocks => object(ViewBlock) {}
object(Cake\View\View) {
Helpers => object(Cake\View\HelperCollection) {}
Blocks => object(Cake\View\ViewBlock) {}
plugin => null
name => ''
passedArgs => array()
Expand All @@ -325,7 +329,7 @@ public function testExportVar() {
hasRendered => false
uuids => array()
request => null
response => object(CakeResponse) {}
response => object(Cake\Network\Response) {}
elementCache => 'default'
int => (int) 2
float => (float) 1.333
Expand Down Expand Up @@ -414,16 +418,16 @@ public function testDump() {
*/
public function testGetInstance() {
$result = Debugger::getInstance();
$this->assertInstanceOf('Debugger', $result);
$this->assertInstanceOf('Cake\Utility\Debugger', $result);

$result = Debugger::getInstance('DebuggerTestCaseDebugger');
$this->assertInstanceOf('DebuggerTestCaseDebugger', $result);
$result = Debugger::getInstance(__NAMESPACE__ . '\DebuggerTestCaseDebugger');
$this->assertInstanceOf(__NAMESPACE__ . '\DebuggerTestCaseDebugger', $result);

$result = Debugger::getInstance();
$this->assertInstanceOf('DebuggerTestCaseDebugger', $result);
$this->assertInstanceOf(__NAMESPACE__ . '\DebuggerTestCaseDebugger', $result);

$result = Debugger::getInstance('Debugger');
$this->assertInstanceOf('Debugger', $result);
$result = Debugger::getInstance('Cake\Utility\Debugger');
$this->assertInstanceOf('Cake\Utility\Debugger', $result);
}

/**
Expand Down Expand Up @@ -468,11 +472,11 @@ public function testNoDbCredentials() {
*/
public function testTraceExclude() {
$result = Debugger::trace();
$this->assertRegExp('/^DebuggerTest::testTraceExclude/', $result);
$this->assertRegExp('/^Cake\\\Test\\\TestCase\\\Utility\\\DebuggerTest::testTraceExclude/', $result);

$result = Debugger::trace(array(
'exclude' => array('DebuggerTest::testTraceExclude')
'exclude' => array('Cake\Test\TestCase\Utility\DebuggerTest::testTraceExclude')
));
$this->assertNotRegExp('/^DebuggerTest::testTraceExclude/', $result);
$this->assertNotRegExp('/^Cake\\\Test\\\TestCase\\\Utility\\\DebuggerTest::testTraceExclude/', $result);
}
}
12 changes: 7 additions & 5 deletions lib/Cake/Test/TestCase/Utility/FileTest.php
Expand Up @@ -16,15 +16,17 @@
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('File', 'Utility');
App::uses('Folder', 'Utility');
namespace Cake\Test\TestCase\Utility;
use Cake\TestSuite\TestCase,
Cake\Utility\File,
Cake\Utility\Folder;

/**
* FileTest class
*
* @package Cake.Test.Case.Utility
*/
class FileTest extends CakeTestCase {
class FileTest extends TestCase {

/**
* File property
Expand Down Expand Up @@ -119,7 +121,7 @@ function_exists('mime_content_type') && false === mime_content_type($this->File-
$this->assertEquals($expecting, $result);

$result = $this->File->Folder();
$this->assertInstanceOf('Folder', $result);
$this->assertInstanceOf('Cake\Utility\Folder', $result);
}

/**
Expand Down Expand Up @@ -522,7 +524,7 @@ public function testCopy() {
*/
public function testMime() {
$this->skipIf(!function_exists('finfo_open') && !function_exists('mime_content_type'), 'Not able to read mime type');
$path = CAKE . 'Test' . DS . 'test_app' . DS . 'webroot' . DS . 'img' . DS . 'cake.power.gif';
$path = CAKE . 'Test' . DS . 'TestApp' . DS . 'webroot' . DS . 'img' . DS . 'cake.power.gif';
$file = new File($path);
$expected = 'image/gif';
if (function_exists('mime_content_type') && false === mime_content_type($file->pwd())) {
Expand Down
14 changes: 8 additions & 6 deletions lib/Cake/Test/TestCase/Utility/FolderTest.php
Expand Up @@ -16,15 +16,17 @@
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Folder', 'Utility');
App::uses('File', 'Utility');
namespace Cake\Test\TestCase\Utility;
use Cake\TestSuite\TestCase,
Cake\Utility\File,
Cake\Utility\Folder;

/**
* FolderTest class
*
* @package Cake.Test.Case.Utility
*/
class FolderTest extends CakeTestCase {
class FolderTest extends TestCase {

protected static $_tmp = array();

Expand Down Expand Up @@ -60,8 +62,8 @@ public function tearDown() {
$exclude = array_merge(self::$_tmp, array('.', '..'));
foreach (scandir(TMP) as $dir) {
if (is_dir(TMP . $dir) && !in_array($dir, $exclude)) {
$iterator = new RecursiveDirectoryIterator(TMP . $dir);
foreach (new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::CHILD_FIRST) as $file) {
$iterator = new \RecursiveDirectoryIterator(TMP . $dir);
foreach (new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::CHILD_FIRST) as $file) {
if ($file->isFile() || $file->isLink()) {
unlink($file->getPathname());
} elseif ($file->isDir() && !in_array($file->getFilename(), array('.', '..'))) {
Expand Down Expand Up @@ -180,7 +182,7 @@ public function testRecursiveCreateFailure() {
$Folder = new Folder($path);
$result = $Folder->create($path . DS . 'two' . DS . 'three');
$this->assertFalse($result);
} catch (PHPUnit_Framework_Error $e) {
} catch (\PHPUnit_Framework_Error $e) {
$this->assertTrue(true);
}

Expand Down
6 changes: 4 additions & 2 deletions lib/Cake/Test/TestCase/Utility/HashTest.php
Expand Up @@ -12,9 +12,11 @@
* @since CakePHP(tm) v 2.2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('Hash', 'Utility');
namespace Cake\Test\TestCase\Utility;
use Cake\TestSuite\TestCase,
Cake\Utility\Hash;

class HashTest extends CakeTestCase {
class HashTest extends TestCase {

public static function articleData() {
return array(
Expand Down
11 changes: 4 additions & 7 deletions lib/Cake/Test/TestCase/Utility/InflectorTest.php
Expand Up @@ -18,19 +18,16 @@
* @since CakePHP(tm) v 1.2.0.4206
* @license Open Group Test Suite License (http://www.opensource.org/licenses/opengroup.php)
*/

/**
* Included libraries.
*
*/
App::uses('Inflector', 'Utility');
namespace Cake\Test\TestCase\Utility;
use Cake\TestSuite\TestCase,
Cake\Utility\Inflector;

/**
* Short description for class.
*
* @package Cake.Test.Case.Utility
*/
class InflectorTest extends CakeTestCase {
class InflectorTest extends TestCase {

/**
* tearDown
Expand Down
@@ -1,6 +1,6 @@
<?php
/**
* CakeNumberTest file
* NumberTest file
*
* PHP 5
*
Expand All @@ -17,15 +17,16 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

App::uses('View', 'View');
App::uses('CakeNumber', 'Utility');
namespace Cake\Test\TestCase\Utility;
use Cake\TestSuite\TestCase,
Cake\Utility\Number;

/**
* CakeNumberTest class
* NumberTest class
*
* @package Cake.Test.Case.Utility
*/
class CakeNumberTest extends CakeTestCase {
class NumberTest extends TestCase {

/**
* setUp method
Expand All @@ -34,7 +35,7 @@ class CakeNumberTest extends CakeTestCase {
*/
public function setUp() {
parent::setUp();
$this->Number = new CakeNumber();
$this->Number = new Number();
}

/**
Expand Down Expand Up @@ -111,7 +112,7 @@ public function testMultibyteFormat() {
$this->assertEquals($expected, $result);

$value = '13371337.1337';
$result = CakeNumber::format($value, array(
$result = Number::format($value, array(
'thousands' => '- |-| /-\ >< () |2 -',
'decimals' => '- £€€† -',
'before' => ''
Expand Down

0 comments on commit 773ce02

Please sign in to comment.