Files
majestic/tests/LoadTest.php

129 lines
3.4 KiB
PHP
Raw Normal View History

2011-10-06 16:33:50 +04:00
<?php
/*
* @copyright NetMonsters <team@netmonsters.ru>
* @link http://netmonsters.ru
* @package Majestic
* @subpackage UnitTests
* @since 2011-10-..
*
* Unit tests for Load class
*/
2011-10-06 18:04:05 +04:00
require dirname(__FILE__) . '/../Load.php';
2011-10-06 16:33:50 +04:00
class LoadTest extends PHPUnit_Framework_TestCase
{
private static $inc_dirs = array();
private static $file;
/**
2011-10-13 14:00:31 +04:00
* @TODO: Load->buildAutoload() should recieve AutoloadBuilder as a parameter
2011-10-06 16:33:50 +04:00
* @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()
{
2011-10-06 18:04:05 +04:00
if (!defined('PATH')) {
define('PATH', realpath(dirname(__FILE__) . '/../../..'));
}
2011-10-06 16:33:50 +04:00
// default application name
if (!defined('APP')) {
define('APP', 'lib/core/tests/face');
}
2011-10-06 18:04:05 +04:00
self::$file = PATH . '/' . APP . '/cache/autoload.php';
2011-10-06 16:33:50 +04:00
// value - if dir exists (to delete it if it was created), default true
2011-10-06 18:04:05 +04:00
self::$inc_dirs[PATH . '/' . APP . '/src'] = true;
2011-10-06 16:33:50 +04:00
self::$inc_dirs[PATH . '/' . APP . '/cache'] = true;
2011-10-06 18:04:05 +04:00
self::$inc_dirs[PATH . '/lib'] = true;
2011-10-06 16:33:50 +04:00
foreach (self::$inc_dirs as $dir => &$is_exist) {
if (!file_exists($dir)) {
$is_exist = false;
mkdir($dir, 0777, true);
}
}
}
2011-10-06 18:04:05 +04:00
public function testSetAutoLoadFrom()
2011-10-06 16:33:50 +04:00
{
// autoload
Load::setAutoloadFrom(self::$file);
2011-10-06 18:04:05 +04:00
2011-10-06 16:33:50 +04:00
$autoload = require(self::$file);
2011-10-06 18:04:05 +04:00
$this->assertNotEmpty($autoload);
2011-10-10 14:21:44 +04:00
Load::autoload('Action');
}
/**
* @TODO: Load::autoload() needs self::$autoload = require(self::$file); after self::buildAutoload();
*/
2011-10-10 14:21:44 +04:00
public function testDebugAutoload()
{
Load::setAutoloadFrom(self::$file);
$autoload = require(self::$file);
$this->assertNotEmpty($autoload);
define('DEBUG', true);
Load::autoload('Func');
Load::autoload('Captcha');
2011-10-06 16:33:50 +04:00
}
2011-10-06 18:04:05 +04:00
2011-10-06 16:33:50 +04:00
public function testAutoloadArrayExists()
{
$this->assertFileExists(self::$file);
}
2011-10-06 18:04:05 +04:00
2011-10-06 16:33:50 +04:00
/**
* @TODO: Load - check if input file returns array
*/
public function testFileForArray()
{
$autoload = require(self::$file);
2011-10-06 18:04:05 +04:00
$this->assertInternalType('array', $autoload);
2011-10-06 16:33:50 +04:00
}
2011-10-06 18:04:05 +04:00
2011-10-06 16:33:50 +04:00
public function testAutoloadArrayNotEmpty()
{
$autoload = require(self::$file);
$this->assertNotEmpty($autoload);
$this->assertArrayHasKey('Action', $autoload);
}
2011-10-06 18:04:05 +04:00
2011-10-06 16:33:50 +04:00
public function testAutoloadGetFilePath()
{
$autoload = require(self::$file);
2011-10-06 19:19:40 +04:00
$this->assertNotEmpty(Load::getFilePath('Registry'));
2011-10-06 16:33:50 +04:00
}
2011-10-06 18:04:05 +04:00
2011-10-06 16:33:50 +04:00
/**
* @TODO: Load::getFilePath - check for wrong index
* @expectedException PHPUnit_Framework_Error
*/
public function testAutoloadGetFilePathNullIndex()
{
$autoload = require(self::$file);
2011-10-06 19:19:40 +04:00
$this->assertNotEmpty(Load::getFilePath('anton'));
2011-10-06 16:33:50 +04:00
}
2011-10-06 18:04:05 +04:00
2011-10-06 16:33:50 +04:00
public static function tearDownAfterClass()
{
2011-10-06 18:04:05 +04:00
if (file_exists(self::$file)) {
2011-10-06 16:33:50 +04:00
unlink(self::$file);
}
2011-10-06 18:04:05 +04:00
2011-10-06 16:33:50 +04:00
foreach (self::$inc_dirs as $dir => $is_exist) {
if (!$is_exist) {
rmdir($dir);
}
}
2011-10-06 18:04:05 +04:00
rmdir(PATH . '/' . APP);
2011-10-06 16:33:50 +04:00
}
}