lundi 3 septembre 2018

How to mock a property of a class in Laravel tests

Im using the ZipArchive class in my laravel 5.6 application for handling zip files. In my tests I have created a mock for the ZipArchive class as follows:

$this->zipArchiveMock = $this->createMock(ZipArchive::class);

Im able to mock methods on the ZipArchive class like follows:

$this->zipArchiveMock->expects($this->once())
            ->method('open')
            ->will($this->returnValue(true));

I want to mock a property called numFiles of the ZipArchive class. I tried doing $this->zipArchiveMock->numFiles = 2. But $this->zipArchiveMock->numFiles is always 0. How to mock a property on the ZipArchive class ?

Thank You



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire