Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save dclarke-modus/4233d563d8dbb93e8d6235f739736512 to your computer and use it in GitHub Desktop.

Select an option

Save dclarke-modus/4233d563d8dbb93e8d6235f739736512 to your computer and use it in GitHub Desktop.
// ERROR:
EEEEEEEEEEEEEEEEEIIEEEEIIIPHP Fatal error: Call to a member function input() on null in /vagrant/webroot/vendor/laravel/framework/src/Illuminate/Support/Facades/Input.php on line 21
PHP Stack trace:
PHP 1. {main}() /vagrant/webroot/vendor/phpunit/phpunit/phpunit:0
PHP 2. PHPUnit_TextUI_Command::main() /vagrant/webroot/vendor/phpunit/phpunit/phpunit:52
PHP 3. PHPUnit_TextUI_Command->run() /vagrant/webroot/vendor/phpunit/phpunit/src/TextUI/Command.php:116
PHP 4. PHPUnit_TextUI_TestRunner->doRun() /vagrant/webroot/vendor/phpunit/phpunit/src/TextUI/Command.php:186
PHP 5. PHPUnit_Framework_TestSuite->run() /vagrant/webroot/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:517
PHP 6. PHPUnit_Framework_TestSuite->run() /vagrant/webroot/vendor/phpunit/phpunit/src/Framework/TestSuite.php:722
PHP 7. PHPUnit_Framework_TestCase->run() /vagrant/webroot/vendor/phpunit/phpunit/src/Framework/TestSuite.php:722
PHP 8. PHPUnit_Framework_TestResult->run() /vagrant/webroot/vendor/phpunit/phpunit/src/Framework/TestCase.php:860
PHP 9. PHPUnit_Framework_TestCase->runBare() /vagrant/webroot/vendor/phpunit/phpunit/src/Framework/TestResult.php:686
PHP 10. PHPUnit_Framework_TestCase->runTest() /vagrant/webroot/vendor/phpunit/phpunit/src/Framework/TestCase.php:905
PHP 11. ReflectionMethod->invokeArgs() /vagrant/webroot/vendor/phpunit/phpunit/src/Framework/TestCase.php:1054
PHP 12. UploadDocumentsControllerTest->testCanUploadFile() /vagrant/webroot/vendor/phpunit/phpunit/src/Framework/TestCase.php:1054
PHP 13. UploadDocumentsController->uploadFile() /vagrant/webroot/tests/unit/controllers/UploadDocumentsControllerTest.php:59
PHP 14. Illuminate\Support\Facades\Input::get() /vagrant/webroot/app/Http/Controllers/UploadDocumentsController.php:64
Test
public function testCanUploadFile()
{
$user = \Mockery::mock('\BLAH\EloquentUser');
$user->shouldReceive('getUserId')->andReturn(1);
Input::shouldReceive('all')->once()->andReturn($this->getUploadedTestData());
Input::shouldReceive('get')->once()->andReturn("");
$vendorManagementUpload = \Mockery::mock('\BLAH\EqVendorManagementUpload');
$vendorManagementUpload->shouldReceive('save');
$vendorManagementUpload->shouldReceive('getUploadID')->andReturn(1);
$vendorManagementUpload->shouldReceive('getUploadByUploadID')->andReturn(array(
array(
'uploadBy' => 'Foo',
'fileName' => 'testFile.pdf',
'fileLocation' => 'testFile.pdf',
'uploadStamp' => '2016-12-02 13:24:46',
'fileType' => 'fa fa-file-pdf-o icon-red',
)
));
$controller = \Mockery::mock('\UploadDocumentsController[validateUpload]', array($user, $vendorManagementUpload));
$controller->shouldReceive('validateUpload')->andReturn(array('size' => '1', 'path' => '/tmp'));
$result = $controller->uploadFile();
$this->assertEquals(\Response::json(array(
'success' => "1",
'uploadId' => 1,
'uploadTime' => '2016-12-02 13:24:46',
'uploadBy' => 'Foo',
'uploadType' => 'fa fa-file-pdf-o icon-red',
'uploadFileName' => 'testFile.pdf',
'uploadLocation' => 'testFile.pdf',
)), $result);
}
//CONTROLLER METHOD:
public function uploadFile()
{
$all = Input::all();
$userID = $this->user->getUserId();
$companyID = $all['companyID'];
$originalName = $all['name'];
$fileName = $this->GUID() . '_' . $originalName;
$rootPath = DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'www' . DIRECTORY_SEPARATOR . 'uploads';
$targetDir = $all['target_dir'];
//FAILS HEREEEEEEEEEEEE
$allowedExts = Input::get('allowed_exts', \AppConfig::get('plupload_allow_extensions'));
$filePath = $rootPath . DIRECTORY_SEPARATOR . $targetDir;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment