Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AmyStephen/5517599 to your computer and use it in GitHub Desktop.
Save AmyStephen/5517599 to your computer and use it in GitHub Desktop.
I ran into a couple of challenges for how to unit test my FileUpload package.: mocking $_FILES and PHP function "move_uploaded_file." What I ended up doing was establishing a property named $file_array in my upload class. In the constructor, I set that property to the value contained in $_FILES. Then, I allowed it to be overridden by the value i…
<?php
/**
* $files_array contains $_FILE superglobal
*
* Helps with Unit Testing
*
* @var array
*/
protected $file_array = array();
/**
* Constructor
*
* @param array $options
*
* @since 1.0
*/
public function __construct($options = array())
{
$this->file_array = $_FILES;
if (isset($options['file_array'])) {
$this->file_array = $options['file_array'];
}
//etc...
}
//etc...
}
/**
* Placed this in my Unit Test Class to override the PHP function
*/
function move_uploaded_file($temporary_name, $target_path)
{
//override PHP's function here...
}
@iby
Copy link

iby commented Feb 26, 2014

/**
 * Placed this in my Unit Test Class to override the PHP function
 */ 
function move_uploaded_file($temporary_name, $target_path)
{
    //override PHP's function here...
}

And what happens when you run it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment