From fc919e9547bee546dbaae7d8335c739a1553e00f Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Tue, 19 Sep 2023 10:19:51 +0200 Subject: [PATCH] add tests for MainScope and UserJob getters/setters --- src/Bundle/ChillMainBundle/Entity/User.php | 10 +++ .../ChillMainBundle/Tests/Entity/UserTest.php | 72 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 src/Bundle/ChillMainBundle/Tests/Entity/UserTest.php diff --git a/src/Bundle/ChillMainBundle/Entity/User.php b/src/Bundle/ChillMainBundle/Entity/User.php index f6f9d55f6..e0aa43d9a 100644 --- a/src/Bundle/ChillMainBundle/Entity/User.php +++ b/src/Bundle/ChillMainBundle/Entity/User.php @@ -288,6 +288,11 @@ class User implements UserInterface, \Stringable return null; } + public function getMainScopeHistories(): Collection + { + return $this->scopeHistories; + } + /** * @return string */ @@ -332,6 +337,11 @@ class User implements UserInterface, \Stringable return null; } + public function getUserJobHistories(): Collection + { + return $this->jobHistories; + } + /** * @return string */ diff --git a/src/Bundle/ChillMainBundle/Tests/Entity/UserTest.php b/src/Bundle/ChillMainBundle/Tests/Entity/UserTest.php new file mode 100644 index 000000000..17bb38d11 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Tests/Entity/UserTest.php @@ -0,0 +1,72 @@ +setMainScope($scopeA); + $user->setMainScope($scopeB); + + // 1. check getMainScope get now scopeB, not scopeA + self::assertSame($scopeB, $user->getMainScope()); + + // 2. get scopeA history, check endDate is not null + $histories = $user->getMainScopeHistories(); + $scopeHistoryA = null; + foreach ($histories as $row) { + /** @var User\UserScopeHistory $row */ + if ($scopeA === $row->getScope()) { + $scopeHistoryA = $row; + } + } + self::assertNotNull($scopeHistoryA->getEndDate()); + } + + public function testUserJobHistory() + { + $user = new User(); + $jobA = new UserJob(); + $jobB = new UserJob(); + + $user->setUserJob($jobA); + $user->setUserJob($jobB); + + // 1. check getUserJob get now jobB, not jobA + self::assertSame($jobB, $user->getUserJob()); + + // 2. get jobA history, check endDate is not null + $histories = $user->getUserJobHistories(); + $jobHistoryA = null; + foreach ($histories as $row) { + /** @var User\UserJobHistory $row */ + if ($jobA === $row->getJob()) { + $jobHistoryA = $row; + } + } + self::assertNotNull($jobHistoryA->getEndDate()); + } + +}