diff --git a/app/Http/Middleware/TrackRequestMiddleware.php b/app/Http/Middleware/TrackRequestMiddleware.php index c5f69b3e1..1700460a8 100644 --- a/app/Http/Middleware/TrackRequestMiddleware.php +++ b/app/Http/Middleware/TrackRequestMiddleware.php @@ -46,6 +46,10 @@ public function __construct(LogManager $logger) */ public function handle(Request $request, Closure $next) { + if(env('APP_ENV') === 'testing') { + // Skip tracking in testing environment + return $next($request); + } try { // generating dynamic id for span with configurable prefix $spanId = env('TRACE_SPAN_PREFIX', 'SPAN') . '_' . Str::uuid(); @@ -73,6 +77,10 @@ public function handle(Request $request, Closure $next) */ public function terminate(Request $request, Response $response): void { + if(env('APP_ENV') === 'testing') { + // Skip tracking in testing environment + return; + } try { $endTime = microtime(true); $responseTime = intval(($endTime - $this->startTime) * 1000); diff --git a/tests/SetupEntityMananger.php b/tests/SetupEntityMananger.php new file mode 100644 index 000000000..2ab79f5ab --- /dev/null +++ b/tests/SetupEntityMananger.php @@ -0,0 +1,57 @@ +isOpen()) { + self::$em = Registry::resetManager(SilverstripeBaseModel::EntityManager); + } + } + + protected static function tearDownEntityManager() + { + try { + if (!self::$em->isOpen()) { + self::$em = Registry::resetManager(SilverstripeBaseModel::EntityManager); + } + + self::$em->flush(); + + } catch (\Exception $ex) { + + } + } +} \ No newline at end of file diff --git a/tests/Unit/Companies/CompanyTest.php b/tests/Unit/Companies/CompanyTest.php new file mode 100644 index 000000000..be2c74c71 --- /dev/null +++ b/tests/Unit/Companies/CompanyTest.php @@ -0,0 +1,67 @@ +setName('Test Company'); + $company->setDescription('Test Company desc'); + $company->setCity('Test City'); + $company->setCountry('Test Country'); + $company->setUrl('www.google.com'); + + self::$em->persist($company); + self::$em->flush(); + + $repo = self::$em->getRepository(Company::class); + $found = $repo->find($company->getId()); + + $this->assertInstanceOf(Company::class, $found); + $this->assertEquals($company->getName(), $found->getName()); + $this->assertEquals($company->getDescription(), $found->getDescription()); + $this->assertEquals($company->getCity(), $found->getCity()); + $this->assertEquals($company->getCountry(), $found->getCountry()); + $this->assertEquals($company->getUrl(), $found->getUrl()); + + self::$em->remove($found); + } +} \ No newline at end of file diff --git a/tests/Unit/Companies/ProjectSponsorshipTypeTest.php b/tests/Unit/Companies/ProjectSponsorshipTypeTest.php new file mode 100644 index 000000000..8b9d02039 --- /dev/null +++ b/tests/Unit/Companies/ProjectSponsorshipTypeTest.php @@ -0,0 +1,71 @@ +setName('Child Company Test'); + + self::$em->persist($child_entity); + + $entity = new ProjectSponsorshipType(); + $entity->setName('Test Sponsorship Type'); + $entity->setDescription('Test Sponsorship Type desc'); + $entity->setIsActive(true); + $entity->setOrder(1); + $supporting_company = $entity->addSupportingCompany($child_entity); + + self::$em->persist($entity); + self::$em->flush(); + + $repo = self::$em->getRepository(ProjectSponsorshipType::class); + $found = $repo->find($entity->getId()); + + $this->assertInstanceOf(ProjectSponsorshipType::class, $found); + $this->assertEquals($entity->getName(), $found->getName()); + $this->assertEquals($entity->getDescription(), $found->getDescription()); + $this->assertEquals($supporting_company, $found->getSupportingCompanyByCompany($child_entity)); + + self::$em->remove($found); + } +} \ No newline at end of file diff --git a/tests/Unit/Companies/SponsoredProjectTest.php b/tests/Unit/Companies/SponsoredProjectTest.php new file mode 100644 index 000000000..f770361d3 --- /dev/null +++ b/tests/Unit/Companies/SponsoredProjectTest.php @@ -0,0 +1,65 @@ +setName('Test Sponsorship Type'); + $entity->setDescription('Test Sponsorship Type desc'); + $entity->setIsActive(true); + + self::$em->persist($entity); + self::$em->flush(); + + $repo = self::$em->getRepository(SponsoredProject::class); + $found = $repo->find($entity->getId()); + + $this->assertInstanceOf(SponsoredProject::class, $found); + $this->assertEquals($entity->getName(), $found->getName()); + $this->assertEquals($entity->getDescription(), $found->getDescription()); + + self::$em->remove($found); + } +} \ No newline at end of file diff --git a/tests/Unit/Companies/SupportingCompanyTest.php b/tests/Unit/Companies/SupportingCompanyTest.php new file mode 100644 index 000000000..1de6eaeeb --- /dev/null +++ b/tests/Unit/Companies/SupportingCompanyTest.php @@ -0,0 +1,73 @@ +setName('Test Company'); + self::$em->persist($child_entity); + + $child_entity_2 = new ProjectSponsorshipType(); + $child_entity_2->setName('Test Project Type'); + $child_entity_2->setOrder(1); + self::$em->persist($child_entity_2); + + $entity = new SupportingCompany(); + $entity->setOrder(1); + $entity->setCompany($child_entity); + $entity->setSponsorshipType($child_entity_2); + + self::$em->persist($entity); + self::$em->flush(); + + $repo = self::$em->getRepository(SupportingCompany::class); + $found = $repo->find($entity->getId()); + + $this->assertInstanceOf(SupportingCompany::class, $found); + $this->assertEquals($entity->getCompany(), $found->getCompany()); + $this->assertEquals($entity->getSponsorshipType(), $found->getSponsorshipType()); + + self::$em->remove($found); + } +} \ No newline at end of file