Skip to content

Commit

Permalink
Fix test Factory entity manager initialisation
Browse files Browse the repository at this point in the history
Tests were failing when one Factory object instance, created by the test
code, attempted to create and use another Factory object.
With out this change, the Factory entity manager initialisation tries to use
a bootstrap_doctrine.php file which does not exist in the test environment
  • Loading branch information
Ian Neilson committed Jun 15, 2022
1 parent 2a753f1 commit 2bccf16
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/Gocdb_Services/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ public static function getEntityManager(){
return self::$em;
}

/**
* Set an externally provided Entity Manager.
* ++ONLY++ used for initialising phpunit tests. Allows Factory services to
* create and use other Factory services.
* Without this, the include paths inside Gocdb_Services code require the
* presence of a second bootstrap_doctrine.php file.
* @param \Doctrine\ORM\EntityManager $entityManager
*/
public static function setEntityManager($entityManager){
self::$em = $entityManager;
}

/**
* Sinlgeton Site service
* @return org\gocdb\services\Site
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ protected function getTearDownOperation() {
protected function setUp() {
parent::setUp();
$this->entityManager = $this->createEntityManager();
// Pass the Entity Manager into the Factory to allow Gocdb_Services
// to use other Gocdb_Services.
\Factory::setEntityManager($this->entityManager);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/lib/Gocdb_Services/SiteServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ protected function setUp() {
parent::setUp();
$this->entityManager = $this->createEntityManager();
$this->testUtil = new TestUtil();
// Pass the Entity Manager into the Factory to allow Gocdb_Services
// to use other Gocdb_Service.
\Factory::setEntityManager($this->entityManager);
}

/**
Expand Down

0 comments on commit 2bccf16

Please sign in to comment.