phpspec / phpspec

SpecBDD Framework for PHP
http://www.phpspec.net
Other
1.87k stars 275 forks source link

Testing Constructors Doesn't Seem to Work As Expected #1451

Closed Saeven closed 8 months ago

Saeven commented 8 months ago

PHPSPEC 7.4.0

Based on docs and conversations in this repo, it seems we should be able to test constructor logic? I find that it isn't working as expected, consider a class with constructor like so:

class Bar {
     public function __construct( Foo $a, Foo $b ){
    }
}

And a collaborator based on this class

class Foo {

}

Lastly, this spec:

public function it_can_test_constructor_issues( Foo $a, Foo $b ){
    $this->beConstructedWith( $a, $b );
    $this->shouldThrow(\RuntimeException::class)->duringInstantiation();
}

The test should fail, yet passes.