I am creating some test cases for my application and i am stuck at a point. I am trying to set a property to the class. But its a parent Class property. This is my actual method
public function uploadFiles($files, $endpoint = 'outbox', $config = [])
{
$user = $this->_BxApi->users->getUser($config);
$result = [];
foreach ($files as $key => $file) {
$policy = 'policy' . $key;
$result[] = $this->_fileUploader->uploadFile($file, $policy, $config);
}
return $result;
}
This is a method in Class Uploads which extent Class API and the API class is
class Api
{
public function __construct(BxClient $bxclient)
{
$this->_BxApi = $bxclient;
}
}
And my test case is
public function testUploadFiles_Upload2Files()
{
$bxMock = $this->_getMock(\BxClient\Core\Api\Uploads::class, [
'_request' => true
]);
$this->_setProperty($bxMock, 'users', $this->_getMock(Users::class, [
'getUser' => (object) ['userId' => 'test']
]));
$this->_setProperty($bxMock, '_fileUploader', $this->_getMock(FileUploader::class, [
'uploadFile' => true,
]));
$result = $bxMock->uploadFiles(['1.txt', '2.txt']);
$this->assertEquals(2, count($result));
$this->assertTrue($result[0]);
$this->assertTrue($result[1]);
}
I think I am doing something wrong in
$this->_setProperty($bxMock, 'users', $this->_getMock(Users::class, [
'getUser' => (object) ['userId' => 'test']
]));
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire