File tree Expand file tree Collapse file tree 5 files changed +58
-4
lines changed
spec/Proget/Tests/PHPStan/PhpSpec Expand file tree Collapse file tree 5 files changed +58
-4
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace spec \Proget \Tests \PHPStan \PhpSpec ;
6+
7+ use Proget \Tests \PHPStan \PhpSpec \Baz ;
8+ use Proget \Tests \PHPStan \PhpSpec \Foo ;
9+ use PhpSpec \ObjectBehavior ;
10+
11+ class FooSpec extends ObjectBehavior
12+ {
13+ public function let (Baz $ baz ): void
14+ {
15+ $ this ->beConstructedWith ($ baz );
16+ }
17+
18+ public function it_is_initializable (): void
19+ {
20+ $ this ->shouldHaveType (Foo::class);
21+ }
22+
23+ public function it_should_make_baz (Baz $ baz ): void
24+ {
25+ $ baz ->make ()->willReturn (123 );
26+
27+ $ this ->makeBaz ()->shouldBe (123 );
28+ }
29+ }
Original file line number Diff line number Diff line change 66
77use Nette \DI \CompilerExtension ;
88use Nette \DI \ServiceDefinition ;
9- use Proget \PHPStan \PhpSpec \Locator \NonFinalClassLocator ;
9+ use Proget \PHPStan \PhpSpec \Locator \SourceClassLocator ;
1010use Proget \PHPStan \PhpSpec \Reflection \CollaboratorDynamicMethodReturnTypeExtension ;
1111
1212final class PhpSpecDynamicMethodReturnTypeExtensionCreator extends CompilerExtension
@@ -15,7 +15,7 @@ public function beforeCompile()
1515 {
1616 $ builder = $ this ->getContainerBuilder ();
1717 $ workingDir = $ this ->getContainerBuilder ()->parameters ['currentWorkingDirectory ' ];
18- $ classes = (new NonFinalClassLocator ())->locate (array_map (function (string $ dir ) use ($ workingDir ) {
18+ $ classes = (new SourceClassLocator ())->locate (array_map (function (string $ dir ) use ($ workingDir ) {
1919 return $ workingDir .DIRECTORY_SEPARATOR .ltrim ($ dir , DIRECTORY_SEPARATOR );
2020 }, $ this ->getContainerBuilder ()->parameters ['phpspecSourceFiles ' ]));
2121
Original file line number Diff line number Diff line change 77use Symfony \Component \Finder \Finder ;
88use Symfony \Component \Finder \SplFileInfo ;
99
10- final class NonFinalClassLocator
10+ final class SourceClassLocator
1111{
1212 public function locate (array $ dirs ): array
1313 {
@@ -44,7 +44,7 @@ private function getClassName(SplFileInfo $fileInfo): ?string
4444 }
4545 }
4646
47- if ($ tokens [$ i ][0 ] === T_CLASS ) {
47+ if ($ tokens [$ i ][0 ] === T_CLASS || $ tokens [ $ i ][ 0 ] === T_INTERFACE ) {
4848 for ($ j = $ i + 1 ; $ j < $ count ; ++$ j ) {
4949 if ($ tokens [$ j ] === '{ ' ) {
5050 return $ namespace .$ tokens [$ i + 2 ][1 ];
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Proget \Tests \PHPStan \PhpSpec ;
6+
7+ interface Baz
8+ {
9+ public function make (): int ;
10+ }
Original file line number Diff line number Diff line change 66
77class Foo
88{
9+ /**
10+ * @var Baz
11+ */
12+ private $ baz ;
13+
14+ public function __construct (Baz $ baz )
15+ {
16+ $ this ->baz = $ baz ;
17+ }
18+
919 public function foo (): string
1020 {
1121 return '' ;
1222 }
23+
24+ public function makeBaz (): int
25+ {
26+ return $ this ->baz ->make ();
27+ }
1328}
You can’t perform that action at this time.
0 commit comments