77use In2code \Lux \Domain \Model \Categoryscoring ;
88use In2code \Lux \Domain \Model \Pagevisit ;
99use In2code \Lux \Domain \Model \Visitor ;
10+ use In2code \Lux \Domain \Repository \PagevisitRepository ;
1011use In2code \Lux \Tests \Helper \TestingHelper ;
1112use PHPUnit \Framework \Attributes \CoversClass ;
1213use PHPUnit \Framework \Attributes \CoversMethod ;
1314use PHPUnit \Framework \Attributes \DataProvider ;
1415use PHPUnit \Framework \Attributes \Test ;
16+ use TYPO3 \CMS \Core \Utility \GeneralUtility ;
1517use TYPO3 \CMS \Extbase \Persistence \ObjectStorage ;
1618use TYPO3 \TestingFramework \Core \Unit \UnitTestCase ;
1719
@@ -133,22 +135,6 @@ public function testGetCategoryscoringsSortedByScoring(array $sortings, array $e
133135 self ::assertSame ($ expectedSortings , $ newScoringArray );
134136 }
135137
136- #[Test]
137- public function getLastPagevisitReturnsLastVisit (): void
138- {
139- $ visitor = new Visitor ();
140- $ pagevisit = new Pagevisit ();
141-
142- $ pagevisit ->setCrdate (new DateTime ('2026-01-01 10:00:00 ' ));
143- $ visitor ->addPagevisit ($ pagevisit );
144-
145- $ newerPagevisit = new Pagevisit ();
146- $ newerPagevisit ->setCrdate (new DateTime ('2026-01-02 10:00:00 ' ));
147- $ visitor ->addPagevisit ($ newerPagevisit );
148-
149- self ::assertSame ($ newerPagevisit , $ visitor ->getLastPagevisit ());
150- }
151-
152138 #[Test]
153139 public function setPagevisitLastPreventsLoadingOfTheRelation (): void
154140 {
@@ -192,6 +178,18 @@ public function pagevisitsAreNotSharedBetweenVisitors(): void
192178 $ secondPagevisit ->setCrdate (new DateTime ('2026-01-01 10:00:00 ' ));
193179 $ secondVisitor ->addPagevisit ($ secondPagevisit );
194180
181+ $ pagevisitRepository = $ this ->createMock (PagevisitRepository::class);
182+ $ pagevisitRepository ->method ('findOneByVisitor ' )
183+ ->willReturnCallback (function (Visitor $ visitor ) use ($ firstVisitor , $ firstPagevisit , $ secondPagevisit ) {
184+ if ($ visitor === $ firstVisitor ) {
185+ return $ firstPagevisit ;
186+ }
187+
188+ return $ secondPagevisit ;
189+ });
190+
191+ GeneralUtility ::setSingletonInstance (PagevisitRepository::class, $ pagevisitRepository );
192+
195193 self ::assertSame ($ firstPagevisit , $ firstVisitor ->getPagevisitLast ());
196194 self ::assertSame ($ secondPagevisit , $ secondVisitor ->getPagevisitLast ());
197195 }
@@ -204,6 +202,11 @@ public function getLastPagevisitCachesResultPerVisitor(): void
204202 $ pagevisit ->setCrdate (new DateTime ('2026-01-01 10:00:00 ' ));
205203 $ visitor ->addPagevisit ($ pagevisit );
206204
205+ $ pagevisitRepository = $ this ->createMock (PagevisitRepository::class);
206+ $ pagevisitRepository ->method ('findOneByVisitor ' )
207+ ->willReturn ($ pagevisit );
208+ GeneralUtility ::setSingletonInstance (PagevisitRepository::class, $ pagevisitRepository );
209+
207210 self ::assertSame ($ pagevisit , $ visitor ->getLastPagevisit ());
208211
209212 $ newerPagevisit = new Pagevisit ();
@@ -224,6 +227,18 @@ public function getLastPagevisitIsNotSharedBetweenVisitors(): void
224227 $ secondVisitor = new Visitor ();
225228 $ secondVisitor ->addPagevisit ($ secondPagevisit );
226229
230+ $ pagevisitRepository = $ this ->createMock (PagevisitRepository::class);
231+ $ pagevisitRepository ->method ('findOneByVisitor ' )
232+ ->willReturnCallback (function (Visitor $ visitor ) use ($ firstVisitor , $ firstPagevisit , $ secondPagevisit ) {
233+ if ($ visitor === $ firstVisitor ) {
234+ return $ firstPagevisit ;
235+ }
236+
237+ return $ secondPagevisit ;
238+ });
239+
240+ GeneralUtility ::setSingletonInstance (PagevisitRepository::class, $ pagevisitRepository );
241+
227242 self ::assertSame ($ firstPagevisit , $ firstVisitor ->getLastPagevisit ());
228243 self ::assertSame ($ secondPagevisit , $ secondVisitor ->getLastPagevisit ());
229244 }
0 commit comments