I need to create a variable of type resource, which is not a stream. This means that resources created by fopen() etc. are out. Ideally it should be possible to create the resource without the help of extensions.
I would use an SQLite in-memory database handle, but sqlite is an optional PHP extension (even though it is enabled by default) which is not guaranteed to be installed on any given system (in current Ubuntu installations, for example, the sqlite extension is NOT installed by default).
Here’s an example of how the test case might be structured:
function is_stream($resource)
{
// some code that determines whether input is stream
}
class StreamResourceTest extends PHPUnit_Framework_TestCase
{
public function testStreamResource()
{
$stream = fopen(__FILE__, 'r');
$nonStream = ???; // how can this be created?
$this->assertTrue(is_resource($stream));
$this->assertTrue(is_stream($stream));
$this->assertTrue(is_resource($nonStream));
$this->assertFalse(is_stream($nonStream));
fclose($stream);
}
}
stream_context_create()Docs creates a resource that is not strictly a stream resource.They could be considered to not require extensions since
…although the same could possibly be said of sqlite, so whether you want to accept that as better alternative would be up to you.
Also, this page might help.