Bug #24190 » makeInstanceTests.diff
tests/t3lib/t3lib_divTest.php (working copy) | ||
---|---|---|
* This copyright notice MUST APPEAR in all copies of the script!
|
||
***************************************************************/
|
||
/**
|
||
* Testcase for class t3lib_div
|
||
*
|
||
... | ... | |
t3lib_div::dirname($input)
|
||
);
|
||
}
|
||
//////////////////////////////////
|
||
// Tests concerning makeInstance
|
||
//////////////////////////////////
|
||
/**
|
||
* @test
|
||
*/
|
||
public function makeInstanceCanReturnInstanceOfNonSingletonClass() {
|
||
$className = get_class($this->getMock('foo'));
|
||
$this->assertTrue(
|
||
t3lib_div::makeInstance($className) instanceof $className
|
||
);
|
||
}
|
||
/**
|
||
* @test
|
||
*/
|
||
public function makeInstancePassesParametersToConstructor() {
|
||
$className = 'testingClass' . uniqid();
|
||
if (!class_exists($className, FALSE)) {
|
||
eval(
|
||
'class ' . $className . ' {' .
|
||
' public $constructorParameter;' .
|
||
' public function __construct($parameter) {' .
|
||
' $this->constructorParameter = $parameter;' .
|
||
' }' .
|
||
'}'
|
||
);
|
||
}
|
||
$instance = t3lib_div::makeInstance($className, 42);
|
||
$this->assertEquals(
|
||
42,
|
||
$instance->constructorParameter
|
||
);
|
||
}
|
||
/**
|
||
* @test
|
||
*/
|
||
public function makeInstanceCalledTwoTimesForNonSingletonClassReturnsDifferentInstances() {
|
||
$className = get_class($this->getMock('foo'));
|
||
$this->assertNotSame(
|
||
t3lib_div::makeInstance($className),
|
||
t3lib_div::makeInstance($className)
|
||
);
|
||
}
|
||
/**
|
||
* @test
|
||
*/
|
||
public function makeInstanceCanReturnInstanceOfSingletonClass() {
|
||
$singletonClassName = get_class($this->getMock('t3lib_Singleton'));
|
||
$this->assertTrue(
|
||
t3lib_div::makeInstance($singletonClassName) instanceof $singletonClassName
|
||
);
|
||
}
|
||
/**
|
||
* @test
|
||
*/
|
||
public function makeInstanceCalledTwoTimesForSingletonClassReturnsSameInstance() {
|
||
$className = get_class($this->getMock('t3lib_Singleton'));
|
||
$this->assertSame(
|
||
t3lib_div::makeInstance($className),
|
||
t3lib_div::makeInstance($className)
|
||
);
|
||
}
|
||
}
|
||
?>
|