Erupting the basic functions of PHP is a bit more complicated.
I think you have something similar in your message model.
public function processFile($file) { if (is_uploaded_file($file)) {
And you have an appropriate test like this.
public function testProcessFile() { $actual = $this->Posts->processFile('noFile'); $this->assertTrue($actual); }
Since you are not loading anything during the test process, the test always fails.
You must add a second namespace at the beginning of your PostsTableTest.php, even having more namespaces in a single file is bad practice.
<?php namespace {
Than you should have your original namespace declaration in curly braces.
namespace App\Model\Table {
And you can add a basic PHP method to overwrite
function is_uploaded_file() { global $mockIsUploadedFile; if ($mockIsUploadedFile === true) { return true; } else { return call_user_func_array('\is_uploaded_file',func_get_args()); } }
Read more about testing the CakePHP module here: http://www.apress.com/9781484212134
source share