Skip to content

Commit 68fe38b

Browse files
authored
Implement custom node visitors with spec collaborator and custom matcher resolver
* Some experiments with anaon classes * Implement custom parser with spec collaborator and custom matcher resolver
1 parent 55c1791 commit 68fe38b

33 files changed

+860
-246
lines changed

extension.neon

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,27 @@ services:
55
-
66
class: Proget\PHPStan\PhpSpec\Reflection\DuringCallMethodsClassReflectionExtension
77
tags: [phpstan.broker.methodsClassReflectionExtension]
8+
-
9+
class: Proget\PHPStan\PhpSpec\Reflection\DelayedCallMethodsClassReflectionExtension
10+
tags: [phpstan.broker.methodsClassReflectionExtension]
11+
-
12+
class: Proget\PHPStan\PhpSpec\Reflection\SpoofedCollaboratorMethodsClassReflectionExtension
13+
tags: [phpstan.broker.methodsClassReflectionExtension]
814
-
915
class: Proget\PHPStan\PhpSpec\Reflection\ObjectBehaviorPropertiesClassReflectionExtension
1016
tags: [phpstan.broker.propertiesClassReflectionExtension]
1117
-
1218
class: Proget\PHPStan\PhpSpec\Type\ObjectBehaviorDynamicMethodReturnTypeExtension
1319
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
20+
-
21+
class: Proget\PHPStan\PhpSpec\Type\ObjectBehaviorDynamicStaticMethodReturnTypeExtension
22+
tags: [phpstan.broker.dynamicStaticMethodReturnTypeExtension]
1423

15-
extensions:
16-
phpspec: Proget\PHPStan\PhpSpec\DependencyInjection\CollaboratorExtension
24+
directParser:
25+
class: Proget\PHPStan\PhpSpec\Parser\SpecAwareDirectParser
26+
arguments:
27+
specDir: %currentWorkingDirectory%/%specDir%
28+
autowired: no
1729

1830
parameters:
19-
specDirs:
20-
- 'spec/'
31+
specDir: 'spec/'

spec/PhpSpec/CodeAnalysis/MagicAwareAccessInspectorSpec.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function it_should_detect_a_magic_setter_if_a_value_is_given()
3131

3232
public function it_should_detect_a_magic_call_method()
3333
{
34-
$this->isMethodCallable(new ObjectWithMagicCall, 'method')->shouldreturn(true);
34+
$this->isMethodCallable(new ObjectWithMagicCall, 'method')->shouldReturn(true);
3535
}
3636

3737
public function it_should_not_detect_a_getter_if_there_is_no_magic_getter_and_wrapped_inspector_finds_none(AccessInspector $accessInspector)

spec/PhpSpec/Event/ExampleEventSpec.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function it_provides_a_link_to_suite($suite)
4545

4646
public function it_provides_a_link_to_time()
4747
{
48-
$this->getTime()->shouldReturn((double) 10.0);
48+
$this->getTime()->shouldReturn(10.0);
4949
}
5050

5151
public function it_provides_a_link_to_result()
@@ -69,6 +69,6 @@ public function it_initializes_a_default_time(ExampleNode $example)
6969
{
7070
$this->beConstructedWith($example);
7171

72-
$this->getTime()->shouldReturn((double) 0.0);
72+
$this->getTime()->shouldReturn(0.0);
7373
}
7474
}

spec/PhpSpec/Event/SpecificationEventSpec.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ public function it_initializes_a_default_time(SpecificationNode $specification)
5656
{
5757
$this->beConstructedWith($specification);
5858

59-
$this->getTime()->shouldReturn((double) 0.0);
59+
$this->getTime()->shouldReturn(0.0);
6060
}
6161
}

spec/PhpSpec/Event/SuiteEventSpec.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ public function it_initializes_a_default_time(Suite $suite)
6767
{
6868
$this->beConstructedWith($suite);
6969

70-
$this->getTime()->shouldReturn((double) 0.0);
70+
$this->getTime()->shouldReturn(0.0);
7171
}
7272
}

spec/PhpSpec/Locator/PSR0/PSR0LocatorSpec.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function it_supports_file_queries_in_srcPath(Filesystem $fs)
181181
$this->beConstructedWith($fs, 'PhpSpec', 'spec', $this->srcPath, $this->specPath);
182182

183183
$this->supportsQuery(
184-
realpath($this->srcPath.'/PhpSpec/Locator/PSR0/PSR0Locator.php')
184+
(string) realpath($this->srcPath.'/PhpSpec/Locator/PSR0/PSR0Locator.php')
185185
)->shouldReturn(true);
186186
}
187187

@@ -204,7 +204,7 @@ public function it_supports_file_queries_in_specPath(Filesystem $fs)
204204
$this->beConstructedWith($fs, 'PhpSpec', 'spec', $this->srcPath, $this->specPath);
205205

206206
$this->supportsQuery(
207-
realpath($this->specPath.'/spec/PhpSpec/Locator/PSR0/PSR0LocatorSpec.php')
207+
(string) realpath($this->specPath.'/spec/PhpSpec/Locator/PSR0/PSR0LocatorSpec.php')
208208
)->shouldReturn(true);
209209
}
210210

spec/PhpSpec/Matcher/ScalarMatcherSpec.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,9 @@ public function it_matches_a_resource()
406406
{
407407
$fp = fopen(__FILE__, 'r');
408408
$this->shouldNotThrow()->duringPositiveMatch('beResource', $fp, ['']);
409-
fclose($fp);
409+
if (is_resource($fp)) {
410+
fclose($fp);
411+
}
410412
}
411413

412414
public function it_does_not_match_not_resource()
@@ -423,7 +425,9 @@ public function it_does_not_mismatches_resource()
423425
{
424426
$fp = fopen(__FILE__, 'r');
425427
$this->shouldThrow()->duringNegativeMatch('beResource', $fp, ['']);
426-
fclose($fp);
428+
if (is_resource($fp)) {
429+
fclose($fp);
430+
}
427431
}
428432

429433
public function it_responds_to_be_scalar()

spec/PhpSpec/Process/Shutdown/UpdateConsoleActionSpec.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function it_should_update_the_console(FatalPresenter $currentExampleWrite
2020
{
2121
$currentExample = new CurrentExampleTracker();
2222
$error = ['type' => 1, 'message' => 'Hello'];
23-
$currentExample->getCurrentExample('Hello');
23+
$currentExample->getCurrentExample();
2424
$currentExampleWriter->displayFatal($currentExample, $error)->shouldBeCalled();
2525
$this->runAction($error);
2626
}

spec/PhpSpec/Runner/CollaboratorManagerSpec.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,30 +45,30 @@ public function it_creates_function_arguments_for_ReflectionFunction(
4545
ReflectionParameter $param1,
4646
ReflectionParameter $param2
4747
) {
48-
$this->set('arg1', '123');
49-
$this->set('arg2', '456');
50-
$this->set('arg3', '789');
48+
$this->set('arg1', $arg1 = new \stdClass());
49+
$this->set('arg2', $arg2 = new \stdClass());
50+
$this->set('arg3', $arg3 = new \stdClass());
5151

5252
$function->getParameters()->willReturn([$param1, $param2]);
5353
$param1->getName()->willReturn('arg1');
5454
$param2->getName()->willReturn('arg3');
5555

56-
$this->getArgumentsFor($function)->shouldReturn(['123', '789']);
56+
$this->getArgumentsFor($function)->shouldReturn([$arg1, $arg3]);
5757
}
5858

5959
public function it_creates_null_function_arguments_for_ReflectionFunction_if_no_collaborator_found(
6060
ReflectionFunction $function,
6161
ReflectionParameter $param1,
6262
ReflectionParameter $param2
6363
) {
64-
$this->set('arg1', '123');
65-
$this->set('arg2', '456');
66-
$this->set('arg3', '789');
64+
$this->set('arg1', $arg1 = new \stdClass());
65+
$this->set('arg2', $arg2 = new \stdClass());
66+
$this->set('arg3', $arg3 = new \stdClass());
6767

6868
$function->getParameters()->willReturn([$param1, $param2]);
6969
$param1->getName()->willReturn('arg4');
7070
$param2->getName()->willReturn('arg3');
7171

72-
$this->getArgumentsFor($function)->shouldReturn([null, '789']);
72+
$this->getArgumentsFor($function)->shouldReturn([null, $arg3]);
7373
}
7474
}

spec/PhpSpec/ServiceContainer/IndexedServiceContainerSpec.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,16 @@ public function it_uses_new_definition_when_a_service_is_redefined()
9393
$this->get('some_service')->shouldBe(2);
9494
}
9595

96-
public function it_does_not_evaluate_callables_that_are_set()
97-
{
98-
$this->set('some_service', function () {
99-
return 100;
100-
});
101-
$this->get('some_service')->shouldNotBe(100);
102-
}
96+
/**
97+
* invalid docblock - callable is an object XD
98+
*/
99+
// public function it_does_not_evaluate_callables_that_are_set()
100+
// {
101+
// $this->set('some_service', function () {
102+
// return 100;
103+
// });
104+
// $this->get('some_service')->shouldNotBe(100);
105+
// }
103106

104107
public function it_provides_a_way_to_remove_service_by_key($service)
105108
{

0 commit comments

Comments
 (0)