I am new to phpspec, and I am trying to test if a method returns a file. The method is essentially:
public function getFile(){
return file_get_contents('myFile.pdf');
}
So my initial though was to test if getFile()
returns a string since file_get_contents
returns a string according to the docs.
So my test looks like this:
$this->getFile()->shouldHaveType("string");
But my test fails with the following message:
expected an instance of string, but got "%PDF-1.4"....
I have even tried gettype(getFile())
and it returns "string"
.
Can anyone tell me what I am doing wrong.
You are checking for a type of class. But you really want to check if the data returned is of type string. @zerkms is correct. You should use a Scalar Matcher (http://www.phpspec.net/cookbook/matchers.html#scalar-matcher)
$this->getFile()->shouldBeString()