@@ -52,32 +52,71 @@ public function testBuildConfigurableProcessor(): void
52
52
$ this ->assertSame ($ processor , $ result );
53
53
}
54
54
55
- public function testBuildPipeline (): void
55
+ public function testBuildConfigurableProcessorWithEmptyConfig (): void
56
+ {
57
+ $ processor = $ this ->createMock (ConfigurableProcessor::class);
58
+ $ this ->registry ->expects ($ this ->once ())
59
+ ->method ('get ' )
60
+ ->with ('context ' , 'name ' )
61
+ ->willReturn ($ processor );
62
+
63
+ $ processor ->expects ($ this ->never ())
64
+ ->method ('configure ' );
65
+
66
+ $ result = $ this ->builder ->build ('context ' , 'name ' , []);
67
+ $ this ->assertSame ($ processor , $ result );
68
+ }
69
+
70
+ public function testBuildPipelineWithVariousProcessorTypes (): void
56
71
{
57
72
$ processor1 = $ this ->createMock (Processor::class);
58
73
$ processor2 = $ this ->createMock (ConfigurableProcessor::class);
74
+ $ processor3 = $ this ->createMock (Processor::class);
59
75
60
- $ this ->registry ->expects ($ this ->exactly (2 ))
76
+ $ this ->registry ->expects ($ this ->exactly (3 ))
61
77
->method ('get ' )
62
- ->willReturnCallback (function ($ context , $ name ) use ($ processor1 , $ processor2 ) {
63
- if ('context ' === $ context && 'processor1 ' === $ name ) {
64
- return $ processor1 ;
65
- }
66
- if ('context ' === $ context && 'processor2 ' === $ name ) {
67
- return $ processor2 ;
68
- }
69
- $ this ->fail ('Unexpected get() call ' );
70
- });
78
+ ->willReturnMap ([
79
+ ['context ' , 'processor1 ' , $ processor1 ],
80
+ ['context ' , 'processor2 ' , $ processor2 ],
81
+ ['context ' , 'processor3 ' , $ processor3 ],
82
+ ]);
71
83
72
84
$ processor2 ->expects ($ this ->once ())
73
85
->method ('configure ' )
74
86
->with (['option ' => 'value ' ]);
75
87
76
88
$ result = $ this ->builder ->buildPipeline ('context ' , [
77
- 'processor1 ' ,
89
+ 'processor1 ' => true ,
78
90
'processor2 ' => ['option ' => 'value ' ],
91
+ 'processor3 ' => [],
92
+ ]);
93
+
94
+ $ this ->assertInstanceOf (Pipeline::class, $ result );
95
+ $ this ->assertInstanceOf (ProcessorPipeline::class, $ result );
96
+ }
97
+
98
+ public function testBuildPipelineWithInvalidProcessorSpec (): void
99
+ {
100
+ $ processor = $ this ->createMock (Processor::class);
101
+
102
+ $ this ->registry ->expects ($ this ->once ())
103
+ ->method ('get ' )
104
+ ->with ('context ' , 'validProcessor ' )
105
+ ->willReturn ($ processor );
106
+
107
+ $ result = $ this ->builder ->buildPipeline ('context ' , [
108
+ 'validProcessor ' => true ,
109
+ 'invalidProcessor ' => false ,
110
+ 'anotherInvalidProcessor ' => null ,
79
111
]);
80
112
113
+ $ this ->assertInstanceOf (Pipeline::class, $ result );
114
+ }
115
+
116
+ public function testBuildPipelineWithEmptySpecs (): void
117
+ {
118
+ $ result = $ this ->builder ->buildPipeline ('context ' , []);
119
+
81
120
$ this ->assertInstanceOf (Pipeline::class, $ result );
82
121
$ this ->assertInstanceOf (ProcessorPipeline::class, $ result );
83
122
}
0 commit comments