I have a ModuleManifest class with this constructor:
/**
* Create a new instance of the ModuleManifest class.
*
* @param string $vendor The vendor of the module.
* @param string $package The name of the package.
* @return void
*/
public function __construct(string $vendor, string $package)
{
$manifest = $this->manifestPath($vendor, $package);
if (!File::exists($manifest))
{
throw new InvalidArgumentException(sprintf(
'Package %s from vendor %s does not contain a manifest',
$vendor, $package
));
}
$this->manifest = $this->load($manifest);
}
This constructor loads a json file with the load method.
/**
* Load a module manifest into an object.
*
* @param string $path The path to the module.
* @return object
*/
protected function load(string $path) : object
{
return json_decode(file_get_contents($path));
}
I want determine whether the method is returning an object:
/** @testdox Returns an object when the path exists */
public function test_manifest_returns_object() : void
{
File::shouldReceive('exists')->once()->andReturnTrue();
$this->mock(ModuleManifest::class, function (MockInterface $mock) {
$mock->shouldAllowMockingProtectedMethods();
$mock->shouldReceive('load')->once()->andReturn(
json_decode('{"name": "testModule"}')
);
});
$manifest = new ModuleManifest('vendor', 'package');
$this->assertTrue($manifest->has('name'));
}
I get the error:
ErrorException: file_get_contents(…): Failed to open stream: No such file or directory
I would expect it to return the result of json_decode('{"name": "testModule"}'), but it tries to call the function normally.