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 6
6
7
7
use Closure ;
8
8
use Yokai \Batch \Job \Item \ItemProcessorInterface ;
9
+ use Yokai \Batch \Job \JobExecutionAwareInterface ;
10
+ use Yokai \Batch \Job \JobExecutionAwareTrait ;
9
11
10
12
/**
11
13
* This {@see ItemProcessorInterface} will transform every item
12
14
* with a closure provided at object's construction.
13
15
*/
14
- final class CallbackProcessor implements ItemProcessorInterface
16
+ final class CallbackProcessor implements ItemProcessorInterface, JobExecutionAwareInterface
15
17
{
18
+ use JobExecutionAwareTrait;
19
+
16
20
public function __construct (
17
21
private Closure $ callback ,
18
22
) {
19
23
}
20
24
21
25
public function process (mixed $ item ): mixed
22
26
{
23
- return ($ this ->callback )($ item );
27
+ return ($ this ->callback )($ item, $ this -> jobExecution );
24
28
}
25
29
}
Original file line number Diff line number Diff line change 6
6
7
7
use PHPUnit \Framework \TestCase ;
8
8
use Yokai \Batch \Job \Item \Processor \CallbackProcessor ;
9
+ use Yokai \Batch \JobExecution ;
9
10
10
11
class CallbackProcessorTest extends TestCase
11
12
{
12
13
public function testProcess (): void
13
14
{
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 ' ));
18
20
}
19
21
}
You can’t perform that action at this time.
0 commit comments