Browse Source

better tests

master
Anton Grebnev 13 years ago
parent
commit
7d12bcf26c
  1. 11
      tests/ConfigTest.php
  2. 14
      tests/LoadTest.php
  3. 29
      tests/util/AutoloadBuilderTest.php

11
tests/ConfigTest.php

@ -32,17 +32,26 @@ class ConfigTest extends PHPUnit_Framework_TestCase
$this->assertNotEquals('Config', get_class(Config::getInstance()));
}
/**
* @expectedException Exception
*/
public function testArrayAsParam()
{
$arr = array(
'one' => 1,
'two' => 2,
'three' => 3
'three' => 3,
4 => 'four'
);
Config::set(0, $arr);
$new_arr = Config::get(0);
$this->assertEquals('ConfigArray', get_class($new_arr));
$this->assertEquals('four', $new_arr->offsetGet(4));
$this->assertEquals(1, $new_arr->offsetGet('one'));
$this->assertNotEquals(1, $new_arr->offsetGet('two'));
$new_arr->offsetGet(24);
}
}

14
tests/LoadTest.php

@ -56,6 +56,20 @@ class LoadTest extends PHPUnit_Framework_TestCase
$autoload = require(self::$file);
$this->assertNotEmpty($autoload);
Load::autoload('Action');
}
public function testDebugAutoload()
{
Load::setAutoloadFrom(self::$file);
$autoload = require(self::$file);
$this->assertNotEmpty($autoload);
define('DEBUG', true);
Load::autoload('Func');
Load::autoload('Captcha');
}
public function testAutoloadArrayExists()

29
tests/util/AutoloadBuilderTest.php

@ -10,6 +10,7 @@
* Unit tests for AutoloadBuilder class
*/
require_once 'vfsStream/vfsStream.php';
require_once dirname(__FILE__) . '/../../util/AutoloadBuilder.php';
/**
@ -65,12 +66,40 @@ class AutoloadBuilderTest extends PHPUnit_Framework_TestCase
$builder->build();
}
public function testBuild()
{
$builder = new AutoloadBuilder(self::$file, array(PATH . '/' . APP . '/src', PATH . '/' . APP . '/cache', PATH . '/lib'));
$builder->build();
$this->assertFileExists(self::$file);
}
public function testAutoloadFileExists()
{
$this->assertFileExists(self::$file);
}
public function testAutoloadArray()
{
$this->assertFileExists(self::$file);
$array = require self::$file;
$this->assertInternalType('array', $array);
$this->assertNotEmpty($array);
}
/**
* @expectedException PHPUnit_Framework_Error
*/
public function testAccessDenied()
{
chmod(self::$file, 0400);
$builder = new AutoloadBuilder(self::$file, array(PATH . '/' . APP . '/src', PATH . '/' . APP . '/cache', PATH . '/lib'));
$builder->build();
chmod(self::$file, 0777);
}
public static function tearDownAfterClass()
{
if (file_exists(self::$file)) {

Loading…
Cancel
Save