4
4
5
5
namespace EdmondsCommerce \DoctrineStaticMeta \Entity \Testing \EntityGenerator ;
6
6
7
+ use DateTimeImmutable ;
7
8
use Doctrine \Common \Collections \Collection ;
8
9
use Doctrine \ORM \EntityManagerInterface ;
10
+ use Edmonds \MarketingEntities \Entity \Fields \Traits \Website \Platform \Search \WebsiteEngineHitLog \TimestampFieldTrait ;
9
11
use EdmondsCommerce \DoctrineStaticMeta \DoctrineStaticMeta ;
10
12
use EdmondsCommerce \DoctrineStaticMeta \Entity \DataTransferObjects \DtoFactory ;
11
13
use EdmondsCommerce \DoctrineStaticMeta \Entity \Factory \EntityFactoryInterface ;
14
+ use EdmondsCommerce \DoctrineStaticMeta \Entity \Fields \Traits \TimeStamp \CreationTimestampFieldTrait ;
12
15
use EdmondsCommerce \DoctrineStaticMeta \Entity \Interfaces \DataTransferObjectInterface ;
13
16
use EdmondsCommerce \DoctrineStaticMeta \Entity \Interfaces \EntityInterface ;
14
17
use EdmondsCommerce \DoctrineStaticMeta \RelationshipHelper ;
@@ -159,6 +162,23 @@ public function generateDto(): DataTransferObjectInterface
159
162
return $ dto ;
160
163
}
161
164
165
+ /**
166
+ * Timestamp columns need to be forcibly updated with dates or they will always reflect the time of test run
167
+ *
168
+ * @param EntityInterface $entity
169
+ * @param DateTimeImmutable $date
170
+ * @param string $propertyName
171
+ *
172
+ * @see CreationTimestampFieldTrait
173
+ */
174
+ public function forceTimestamp (EntityInterface $ entity , DateTimeImmutable $ date , string $ propertyName ): void
175
+ {
176
+ $ property = $ entity ::getDoctrineStaticMeta ()
177
+ ->getReflectionClass ()
178
+ ->getProperty ($ propertyName );
179
+ $ property ->setValue ($ entity , $ date );
180
+ }
181
+
162
182
public function fakerUpdateDto (DataTransferObjectInterface $ dto ): void
163
183
{
164
184
$ this ->fakerDataFiller ->updateDtoWithFakeData ($ dto );
@@ -181,8 +201,8 @@ public function addAssociationEntities(
181
201
if (empty ($ mappings )) {
182
202
return ;
183
203
}
184
- $ methods = array_map ('strtolower ' , get_class_methods ($ generated ));
185
- $ relationHelper = $ this ->relationshipHelper ;
204
+ $ methods = array_map ('strtolower ' , get_class_methods ($ generated ));
205
+ $ relationHelper = $ this ->relationshipHelper ;
186
206
foreach ($ mappings as $ mapping ) {
187
207
$ getter = $ relationHelper ->getGetterFromDoctrineMapping ($ mapping );
188
208
$ isPlural = $ relationHelper ->isPlural ($ mapping );
0 commit comments