File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Elastica \Processor ;
4+
5+ class BytesProcessor extends AbstractProcessor
6+ {
7+ use Traits \IgnoreFailureTrait;
8+ use Traits \IgnoreMissingTrait;
9+
10+
11+ public function __construct (string $ field )
12+ {
13+ $ this ->setField ($ field );
14+ }
15+
16+ /**
17+ * Set field.
18+ *
19+ * @return $this
20+ */
21+ public function setField (string $ field ): self
22+ {
23+ return $ this ->setParam ('field ' , $ field );
24+ }
25+
26+ /**
27+ * Set target_field.
28+ *
29+ * @return $this
30+ */
31+ public function setTargetField (string $ targetField ): self
32+ {
33+ return $ this ->setParam ('target_field ' , $ targetField );
34+ }
35+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Elastica \Test \Processor ;
4+
5+ use Elastica \Processor \BytesProcessor ;
6+ use Elastica \Test \BasePipeline as BasePipelineTest ;
7+
8+ class BytesProcessorTest extends BasePipelineTest
9+ {
10+ /**
11+ * @group unit
12+ */
13+ public function testBytes (): void
14+ {
15+ $ processor = new BytesProcessor ('foo ' );
16+
17+ $ expected = [
18+ 'bytes ' => [
19+ 'field ' => 'foo ' ,
20+ ],
21+ ];
22+
23+ $ this ->assertEquals ($ expected , $ processor ->toArray ());
24+ }
25+
26+ /**
27+ * @group unit
28+ */
29+ public function testBytesWithTargetField (): void
30+ {
31+ $ processor = (new BytesProcessor ('foo ' ))
32+ ->setTargetField ('bar ' )
33+ ;
34+
35+ $ expected = [
36+ 'bytes ' => [
37+ 'field ' => 'foo ' ,
38+ 'target_field ' => 'bar ' ,
39+ ],
40+ ];
41+
42+ $ this ->assertEquals ($ expected , $ processor ->toArray ());
43+ }
44+
45+ /**
46+ * @group unit
47+ */
48+ public function testBytesWithNonDefaultOptions (): void
49+ {
50+ $ processor = (new BytesProcessor ('foo ' ))
51+ ->setIgnoreFailure (true )
52+ ->setIgnoreMissing (true )
53+ ;
54+
55+ $ expected = [
56+ 'bytes ' => [
57+ 'field ' => 'foo ' ,
58+ 'ignore_failure ' => true ,
59+ 'ignore_missing ' => true ,
60+ ],
61+ ];
62+
63+ $ this ->assertEquals ($ expected , $ processor ->toArray ());
64+ }
65+ }
You can’t perform that action at this time.
0 commit comments