File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,20 @@ public function asInline(): static
8989 return $ this ->setDisposition ('inline ' );
9090 }
9191
92+ /**
93+ * @return $this
94+ */
95+ public function setContentId (string $ cid ): static
96+ {
97+ if (!str_contains ($ cid , '@ ' )) {
98+ throw new InvalidArgumentException (sprintf ('Invalid cid "%s". ' , $ cid ));
99+ }
100+
101+ $ this ->cid = $ cid ;
102+
103+ return $ this ;
104+ }
105+
92106 public function getContentId (): string
93107 {
94108 return $ this ->cid ?: $ this ->cid = $ this ->generateContentId ();
Original file line number Diff line number Diff line change @@ -166,6 +166,22 @@ public function testHasContentId()
166166 $ this ->assertTrue ($ p ->hasContentId ());
167167 }
168168
169+ public function testSetContentId ()
170+ {
171+ $ p = new DataPart ('content ' );
172+ $ p ->setContentId ('test@test ' );
173+ $ this ->assertTrue ($ p ->hasContentId ());
174+ $ this ->assertSame ('test@test ' , $ p ->getContentId ());
175+ }
176+
177+ public function testSetContentIdInvalid ()
178+ {
179+ $ this ->expectException (InvalidArgumentException::class);
180+
181+ $ p = new DataPart ('content ' );
182+ $ p ->setContentId ('test ' );
183+ }
184+
169185 public function testGetFilename ()
170186 {
171187 $ p = new DataPart ('content ' , null );
You can’t perform that action at this time.
0 commit comments