I came up with a way by creating a static factory that will let me inject an
adapter that my controller will call:
<code>
// factory
class Manchuck_File
{
protected static $_adapter;
/**
* Returns the instance of the adapter
*
* @return Zend_File_Transfer_Adapter_Abstract
*/
public static function getAdapter()
{
if (self::$_adapter === null) {
self::setAdapter(new Zend_File_Transfer_Adapter_Http());
}
return self::$_adapter;
}
/**
* Sets the adapter
*
* @param Zend_File_Transfer_Adapter_Abstract $value
*/
public static function setAdapter(Zend_File_Transfer_Adapter_Abstract
$value)
{
self::$_adapter = $value;
}
/**
* Clears out the set adapter
*/
public static function clearAdapter()
{
self::$_adapter = null;
}
}
//Controller:
class File_FileController
extends Zend_Controller_Action
{
public function uploadAction()
{
$adapter = Manchuck_File::getAdapter();
// do stuff
}
}
// Test:
class File_FileControllerTest
extends ZendTestController
{
public function tearDown()
{
Manchuck_File::clearAdapter();
}
public function testUploadAction()
{
$mock = $this->getMock('Zend_File_Transfer_Adapter_Abstract');
// set up expectations and the like
Manchuck_File::setAdapter($mock);
// more assertions
}
}
</code>
--
View this message in context:
http://zend-framework-community.634137.n4.nabble.com/How-to-simulate-a-file-upload-to-test-form-tp653154p4658617.html
Sent from the Zend Framework mailing list archive at Nabble.com.
--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]