Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Stream class accept all resource types #67

Merged
merged 1 commit into from
Jul 12, 2015

Conversation

weierophinney
Copy link
Member

Problem:
Stream accept resource, not only stream resource.
You can initialize stream class with wrong parameter.

Simple(bad) test:

    public function testCanNotInstantiateWithStreamIdentifier()
    {
        $true = false;
        $image = imagecreate(200, 200);

        try {
            $this->stream = new Stream($image, 'wb+');
        } catch(\Exception $e)
        {
            $true = true;
        }

        $this->assertTrue($true); //test is red
    }

Simple (not that bad) solution.

        if (is_resource($stream)) {
            $type = get_resource_type($stream);
            if($type !== 'stream')
            {
                throw new \InvalidArgumentException("Resource is not a stream");
            }
            $this->resource = $stream;
        } elseif (is_string($stream)) {

Adds tests to validate that construction and stream attachment receive
valid stream resources.
@weierophinney weierophinney self-assigned this Jul 12, 2015
@weierophinney weierophinney added this to the 1.1.2 milestone Jul 12, 2015
@weierophinney weierophinney merged commit 8d6780a into zendframework:master Jul 12, 2015
weierophinney added a commit that referenced this pull request Jul 12, 2015
weierophinney added a commit that referenced this pull request Jul 12, 2015
weierophinney added a commit that referenced this pull request Jul 12, 2015
@weierophinney weierophinney deleted the hotfix/67 branch July 12, 2015 16:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant