donatj / mock-webserver

Simple mock web server in PHP for unit testing.
MIT License
133 stars 21 forks source link

TypeError : fclose(): supplied resource is not a valid stream resource #67

Closed cgimenes closed 10 months ago

cgimenes commented 10 months ago

I don't think @fclose($descriptor); at src/MockWebServer.php#L135 is working. Maybe wrap in an empty try/catch?

cgimenes commented 10 months ago

What do you think of? https://github.com/donatj/mock-webserver/pull/68

donatj commented 10 months ago

Can you provide a code example of how to trigger the issue?

cgimenes commented 10 months ago

Just to be clear. I was using 2.6.1 and after upgrading to 2.7.1 I started getting TypeError : fclose(): supplied resource is not a valid stream resource when calling MockWebServer->stop()

donatj commented 10 months ago

I can't come up with any way that that a descriptor should be in that array and an open valid stream resource.

Are you using any sort of test parallelizers or such?

cgimenes commented 10 months ago

Yes, I'm using. But, I think I may found out why I'm the only one having this issue. I'm calling stop() twice.

cgimenes commented 10 months ago
<?php

declare(strict_types=1);

use donatj\MockWebServer\MockWebServer;
use PHPUnit\Framework\TestCase;

class ExampleTest extends TestCase
{
    public function setUp(): void
    {
        $this->server = new MockWebServer();
        $this->server->start();
    }

    public function tearDown(): void
    {
        $this->server->stop();
        $this->server->stop();
    }

    public function testValid(): void
    {
        self::assertTrue(true);
    }
}
donatj commented 10 months ago

You know, that's the one thing I didn't think of. That would do it. I will fix that!

donatj commented 10 months ago

Published a release with a fix and a regression test ;)

Thanks for the report!

https://github.com/donatj/mock-webserver/releases/tag/v2.7.2

cgimenes commented 10 months ago

Thank you!