sebastianbergmann / phpunit

The PHP Unit Testing framework.
https://phpunit.de/
BSD 3-Clause "New" or "Revised" License
19.67k stars 2.2k forks source link

Migrate test double code generator tests from PHPT #5476

Open sebastianbergmann opened 1 year ago

sebastianbergmann commented 1 year ago

We currently have quite a few slow PHPT tests for the test double code generator.

These tests should be migrated from PHPT to regular PHPUnit tests.

This will reduce the time needed to run PHPUnit's test suite and lead to tests that are oblivious to changes in the generated code that do not affect behaviour.

marac19901990 commented 8 months ago

@sebastianbergmann Just to check so I don't waste time, is this what you had in mind? If you give me the heads up, I'll move all the phpt files from the generator folder to simple unit tests.

    public function testReturnTypeDeclarationsVoid()
    {
        $generator = new PHPUnit\Framework\MockObject\Generator\Generator;
        $mock = $generator->generate(
            'Foo2',
            true,
            [],
            'MockFoo'
        );
        $mock = $this->instantiate($mock->generate());

        $mock->expects($this->once())->method('bar')->willReturnCallback(function(string $baz): void {
            $this->assertSame('test_foo2', $baz);
        });

        $this->assertNull($mock->bar('test_foo2'));
        $this->assertInstanceOf(Foo2::class, $mock);
        $this->assertInstanceOf(MockObjectInternal::class, $mock);
    }
sebastianbergmann commented 8 months ago

Thank you, Marko, for offering to help. But I do not know yet what the right test strategy here is. I also do not know when I will find the time to think about this. Sorry.