File tree Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change 66
77use Closure ;
88use Yokai \Batch \Job \Item \ItemProcessorInterface ;
9+ use Yokai \Batch \Job \JobExecutionAwareInterface ;
10+ use Yokai \Batch \Job \JobExecutionAwareTrait ;
911
1012/**
1113 * This {@see ItemProcessorInterface} will transform every item
1214 * with a closure provided at object's construction.
1315 */
14- final class CallbackProcessor implements ItemProcessorInterface
16+ final class CallbackProcessor implements ItemProcessorInterface, JobExecutionAwareInterface
1517{
18+ use JobExecutionAwareTrait;
19+
1620 public function __construct (
1721 private Closure $ callback ,
1822 ) {
1923 }
2024
2125 public function process (mixed $ item ): mixed
2226 {
23- return ($ this ->callback )($ item );
27+ return ($ this ->callback )($ item, $ this -> jobExecution );
2428 }
2529}
Original file line number Diff line number Diff line change 66
77use PHPUnit \Framework \TestCase ;
88use Yokai \Batch \Job \Item \Processor \CallbackProcessor ;
9+ use Yokai \Batch \JobExecution ;
910
1011class CallbackProcessorTest extends TestCase
1112{
1213 public function testProcess (): void
1314 {
14- $ processor = new CallbackProcessor (fn ($ item ) => \mb_strtolower ($ item ));
15-
16- self ::assertSame ('john ' , $ processor ->process ('John ' ));
17- self ::assertSame ('doe ' , $ processor ->process ('DOE ' ));
15+ $ processor = new CallbackProcessor (fn ($ item , JobExecution $ jobExecution )
16+ => \mb_strtolower ($ item . '- ' . $ jobExecution ->getJobName ()));
17+ $ processor ->setJobExecution (JobExecution::createRoot (id: '123 ' , jobName: 'test ' ));
18+ self ::assertSame ('john-test ' , $ processor ->process ('John ' ));
19+ self ::assertSame ('doe-test ' , $ processor ->process ('DOE ' ));
1820 }
1921}
You can’t perform that action at this time.
0 commit comments