Browse Source

Load class tested

master
Anton Grebnev 13 years ago
parent
commit
a73ae74bd4
  1. 2
      tests/ConfigTest.php
  2. 112
      tests/LoadTest.php
  3. 4
      tests/RegistryTest.php

2
tests/ConfigTest.php

@ -27,7 +27,7 @@ class ConfigTest extends PHPUnit_Framework_TestCase
$this->assertSame($this->_instance, Config::getInstance()); $this->assertSame($this->_instance, Config::getInstance());
/** /**
* @TODO: Config class does not instanciate!!! It is still Registry. Use late static binding
* @TODO: Config - class does not instanciate, Registry instead!!! Use late static binding
*/ */
$this->assertNotEquals('Config', get_class(Config::getInstance())); $this->assertNotEquals('Config', get_class(Config::getInstance()));
} }

112
tests/LoadTest.php

@ -0,0 +1,112 @@
<?php
/*
* @copyright NetMonsters <team@netmonsters.ru>
* @link http://netmonsters.ru
* @package Majestic
* @subpackage UnitTests
* @since 2011-10-..
*
* Unit tests for Load class
*/
class LoadTest extends PHPUnit_Framework_TestCase
{
private static $inc_dirs = array();
private static $file;
/**
* @TODO: Load->buildAutoload() - uses two paths - PATH . '/' . APP . '/src' and PATH . '/lib' those are not checked. Can couse error.
* @expectedException UnexpectedValueException
* @expectedException PHPUnit_Framework_Error
*/
public static function setUpBeforeClass()
{
define('PATH', realpath(dirname(__FILE__) . '/../../..'));
// default application name
if (!defined('APP')) {
define('APP', 'lib/core/tests/face');
}
self::$file = PATH . '/'. APP. '/cache//autoload.php';
// value - if dir exists (to delete it if it was created), default true
self::$inc_dirs[PATH . '/' . APP . '/src'] = true;
self::$inc_dirs[PATH . '/' . APP . '/cache'] = true;
self::$inc_dirs[PATH . '/lib'] = true;
foreach (self::$inc_dirs as $dir => &$is_exist) {
if (!file_exists($dir)) {
$is_exist = false;
mkdir($dir, 0777, true);
}
}
}
public function testSetAutoLoadFrom()
{
// autoload
require (PATH . '/lib/core/Load.php');
Load::setAutoloadFrom(self::$file);
$autoload = require(self::$file);
$this->assertNotEmpty($autoload);
}
public function testAutoloadArrayExists()
{
$this->assertFileExists(self::$file);
}
/**
* @TODO: Load - check if input file returns array
*/
public function testFileForArray()
{
$autoload = require(self::$file);
$this->assertInternalType('array', $autoload);
}
public function testAutoloadArrayNotEmpty()
{
$autoload = require(self::$file);
$this->assertNotEmpty($autoload);
$this->assertArrayHasKey('Action', $autoload);
}
public function testAutoloadGetFilePath()
{
$autoload = require(self::$file);
$this->assertNotEmpty($autoload['Registry']);
}
/**
* @TODO: Load::getFilePath - check for wrong index
* @expectedException PHPUnit_Framework_Error
*/
public function testAutoloadGetFilePathNullIndex()
{
$autoload = require(self::$file);
$this->assertNotEmpty($autoload['anton']);
}
public static function tearDownAfterClass()
{
if(file_exists(self::$file)) {
unlink(self::$file);
}
foreach (self::$inc_dirs as $dir => $is_exist) {
if (!$is_exist) {
rmdir($dir);
}
}
rmdir(PATH . '/' . APP);
}
}

4
tests/RegistryTest.php

@ -32,7 +32,7 @@ class RegistryTest extends PHPUnit_Framework_TestCase
} }
/** /**
* @TODO: make __construct private
* @TODO: Registry - make __construct private
*/ */
// public function testRegistryConstructor() // public function testRegistryConstructor()
// { // {
@ -56,7 +56,7 @@ class RegistryTest extends PHPUnit_Framework_TestCase
} }
/** /**
* @TODO: check input for null
* @TODO: Registry::isRegistered - check input for null
* @expectedException PHPUnit_Framework_Error * @expectedException PHPUnit_Framework_Error
*/ */
public function testIsRegistered() public function testIsRegistered()

Loading…
Cancel
Save