diff --git a/Gruntfile.js b/Gruntfile.js index 90be173ab4..1ea77f9f43 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -315,11 +315,11 @@ module.exports = function (grunt) { }); grunt.registerTask("unit-tests-run", function() { - cp.execSync("vendor/bin/phpunit --bootstrap=./vendor/autoload.php ./tests/unit", {stdio: 'inherit'}); + cp.execSync("vendor/bin/phpunit ./tests/unit", {stdio: 'inherit'}); }); grunt.registerTask("integration-tests-run", function() { - cp.execSync("vendor/bin/phpunit --bootstrap=./vendor/autoload.php ./tests/integration", {stdio: 'inherit'}); + cp.execSync("vendor/bin/phpunit ./tests/integration", {stdio: 'inherit'}); }); grunt.registerTask("zip", function() { diff --git a/application/Espo/Core/Loaders/EntityManager.php b/application/Espo/Core/Loaders/EntityManager.php index a990e0616a..d9dc496d27 100644 --- a/application/Espo/Core/Loaders/EntityManager.php +++ b/application/Espo/Core/Loaders/EntityManager.php @@ -30,73 +30,21 @@ namespace Espo\Core\Loaders; use Espo\Core\{ - Utils\Config, - InjectableFactory, + ORM\EntityManagerFactory, ORM\EntityManager as EntityManagerService, - ORM\RepositoryFactory, - ORM\EntityFactory, - ORM\Helper, - ORM\MetadataDataProvider, -}; - -use Espo\{ - ORM\Metadata as OrmMetadata, }; class EntityManager implements Loader { - protected $config; - protected $injectableFactory; - protected $metadataDataProvider; + protected $entityManagerFactory; - public function __construct( - Config $config, - InjectableFactory $injectableFactory, - MetadataDataProvider $metadataDataProvider - ) { - $this->config = $config; - $this->injectableFactory = $injectableFactory; - $this->metadataDataProvider = $metadataDataProvider; + public function __construct(EntityManagerFactory $entityManagerFactory) + { + $this->entityManagerFactory = $entityManagerFactory; } public function load() : EntityManagerService { - $entityFactory = $this->injectableFactory->create(EntityFactory::class); - - $repositoryFactory = $this->injectableFactory->createWith(RepositoryFactory::class, [ - 'entityFactory' => $entityFactory, - ]); - - $helper = $this->injectableFactory->create(Helper::class); - - $config = $this->config; - - $params = [ - 'host' => $config->get('database.host'), - 'port' => $config->get('database.port'), - 'dbname' => $config->get('database.dbname'), - 'user' => $config->get('database.user'), - 'charset' => $config->get('database.charset', 'utf8'), - 'password' => $config->get('database.password'), - 'driver' => $config->get('database.driver'), - 'platform' => $config->get('database.platform'), - 'sslCA' => $config->get('database.sslCA'), - 'sslCert' => $config->get('database.sslCert'), - 'sslKey' => $config->get('database.sslKey'), - 'sslCAPath' => $config->get('database.sslCAPath'), - 'sslCipher' => $config->get('database.sslCipher'), - ]; - - $metadata = new OrmMetadata($this->metadataDataProvider); - - $entityManager = $this->injectableFactory->createWith(EntityManagerService::class, [ - 'params' => $params, - 'metadata' => $metadata, - 'repositoryFactory' => $repositoryFactory, - 'entityFactory' => $entityFactory, - 'helper' => $helper, - ]); - - return $entityManager; + return $this->entityManagerFactory->create(); } } diff --git a/application/Espo/Core/Loaders/OrmMetadata.php b/application/Espo/Core/Loaders/OrmMetadata.php deleted file mode 100644 index 4623bb10df..0000000000 --- a/application/Espo/Core/Loaders/OrmMetadata.php +++ /dev/null @@ -1,50 +0,0 @@ -entityManager = $entityManager; - } - - public function load() : Metadata - { - return $this->entityManager->getMetadata(); - } -} diff --git a/application/Espo/Core/ORM/EntityManagerFactory.php b/application/Espo/Core/ORM/EntityManagerFactory.php new file mode 100644 index 0000000000..67ef69d876 --- /dev/null +++ b/application/Espo/Core/ORM/EntityManagerFactory.php @@ -0,0 +1,97 @@ +config = $config; + $this->injectableFactory = $injectableFactory; + $this->metadataDataProvider = $metadataDataProvider; + } + + public function create() : EntityManager + { + $entityFactory = $this->injectableFactory->create(EntityFactory::class); + + $repositoryFactory = $this->injectableFactory->createWith(RepositoryFactory::class, [ + 'entityFactory' => $entityFactory, + ]); + + $helper = $this->injectableFactory->create(Helper::class); + + $config = $this->config; + + $params = [ + 'host' => $config->get('database.host'), + 'port' => $config->get('database.port'), + 'dbname' => $config->get('database.dbname'), + 'user' => $config->get('database.user'), + 'charset' => $config->get('database.charset', 'utf8'), + 'password' => $config->get('database.password'), + 'driver' => $config->get('database.driver'), + 'platform' => $config->get('database.platform'), + 'sslCA' => $config->get('database.sslCA'), + 'sslCert' => $config->get('database.sslCert'), + 'sslKey' => $config->get('database.sslKey'), + 'sslCAPath' => $config->get('database.sslCAPath'), + 'sslCipher' => $config->get('database.sslCipher'), + ]; + + $metadata = new Metadata($this->metadataDataProvider); + + $entityManager = $this->injectableFactory->createWith(EntityManager::class, [ + 'params' => $params, + 'metadata' => $metadata, + 'repositoryFactory' => $repositoryFactory, + 'entityFactory' => $entityFactory, + 'helper' => $helper, + ]); + + return $entityManager; + } +} diff --git a/application/Espo/ORM/QueryParams/SelectBuilder.php b/application/Espo/ORM/QueryParams/SelectBuilder.php index f810ac9f84..b9cea30cb5 100644 --- a/application/Espo/ORM/QueryParams/SelectBuilder.php +++ b/application/Espo/ORM/QueryParams/SelectBuilder.php @@ -30,6 +30,7 @@ namespace Espo\ORM\QueryParams; use InvalidArgumentException; +use RuntimeException; class SelectBuilder implements Builder {