php - Cannot set public property on Mockery mock object -
i'm trying use mockery create mock object mimics php's internal ziparchive
class.
i have following php code:
$zipmock = mockery::mock('ziparchive'); $zipmock->numfiles = 10; echo 'number of files: '.$zipmock->numfiles;
however, when run following result:
number of files: 0
i'd expect show 10, rather 0. can't work out why happening since the documentation implies should possible set public properties on mock objects directly. missing?
i can't work out why happening since documentation implies should possible set public properties on mock objects directly. missing?
you're missing point ziparchive::$numfiles
not standard public property. ziparchive not userland php class (plain old php object) 1 php extension. means property effectively read-only:
so mocking mockery not option num-files property. can mock own object, here 10 files:
$file = tempnam(sys_get_temp_dir(), 'zip'); $zip = new ziparchive; $zip->open($file, ziparchive::create); foreach(range(1, 10) $num) { $zip->addfromstring($num, ""); } var_dump($zip->numfiles); $zip->close(); unlink($file);
Comments
Post a Comment