EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
Integration tests optimization (#3689)
Yurii Kuznietsovba7e6f62a832
diff --git a/application/Espo/Core/Container.php b/application/Espo/Core/Container.phpindex c596c5f550..96c7125e2f 100644--- a/application/Espo/Core/Container.php+++ b/application/Espo/Core/Container.php@@ -381,4 +381,19 @@ class Container implements ContainerInterface{return new InjectableFactory($this, $this->bindingContainer);}++ /**+ * @internal+ * @param string[] $exceptions+ */+ public function reset(array $exceptions): void+ {+ foreach (array_diff(array_keys($this->data), $exceptions) as $id) {+ unset($this->data[$id]);+ }++ foreach (array_diff(array_keys($this->classCache), $exceptions) as $id) {+ unset($this->classCache[$id]);+ }+ }}diff --git a/application/Espo/ORM/EntityManager.php b/application/Espo/ORM/EntityManager.phpindex 4c8a8acd2a..a3ec089acd 100644--- a/application/Espo/ORM/EntityManager.php+++ b/application/Espo/ORM/EntityManager.php@@ -120,6 +120,11 @@ class EntityManager$this->transactionManager = new TransactionManager($this->pdoProvider->get(), $this->queryComposer);$this->initLocker();++ $eventDispatcher->subscribeToMetadataUpdate(function () {+ $this->repositoryHash = [];+ $this->mappers = [];+ });}private function initQueryComposer(): voiddiff --git a/tests/integration/Core/BaseTestCase.php b/tests/integration/Core/BaseTestCase.phpindex dc91f8e40b..f31364de94 100644--- a/tests/integration/Core/BaseTestCase.php+++ b/tests/integration/Core/BaseTestCase.php@@ -43,8 +43,14 @@ use Espo\Core\Utils\Metadata;use Espo\Entities\User;use Espo\ORM\EntityManager;+use Espo\ORM\TransactionManager;+use Exception;+use integration\Core\NoTransaction;use PHPUnit\Framework\TestCase;+use ReflectionClass;+use ReflectionException;+use ReflectionMethod;use RuntimeException;use Slim\Psr7\Factory\RequestFactory;use Slim\Psr7\Factory\ResponseFactory;@@ -68,6 +74,8 @@ abstract class BaseTestCase extends TestCase/** Password used for authentication. */protected ?string $password = null;+ private ?TransactionManager $transactionManager = null;+/*** @var ?array{* entities?: array<string, array<string, mixed>>,@@ -84,6 +92,16 @@ abstract class BaseTestCase extends TestCase?BindingProcessor $binding = null,): Application {+ if (!$this->isNotCleanTest()) {+ if ($this->transactionManager?->isStarted()) {+ try {+ $this->transactionManager->commit();+ } catch (Exception) {}+ }++ Registry::$isCleanAndReady = false;+ }+return $this->espoTester->getApplication(reload: true,clearCache: $clearCache,@@ -97,21 +115,28 @@ abstract class BaseTestCase extends TestCase$this->espoApplication = $application;}+ /**+ * Set authentication credentials. It does not authenticate.+ */protected function auth(?string $userName = null,?string $password = null,?string $portalId = null,?string $authenticationMethod = null,- ?RequestWrapper $request = null+ ?RequestWrapper $request = null,): void {$this->userName = $userName;$this->password = $password;$this->authenticationMethod = $authenticationMethod;- if (isset($this->espoTester)) {- $this->espoTester->auth($userName, $password, $portalId, $authenticationMethod, $request);- }+ $this->espoTester?->auth(+ userName: $userName,+ password: $password,+ portalId: $portalId,+ authenticationMethod: $authenticationMethod,+ request: $request,+ );}/**@@ -179,7 +204,8 @@ abstract class BaseTestCase extends TestCase$this->beforeSetUp();try {- $this->espoTester->initialize();+ $this->espoTester->install();+ $this->espoTester->loadData();} catch (Error $e) {throw new RuntimeException("Initialization error.", previous: $e);}@@ -187,8 +213,46 @@ abstract class BaseTestCase extends TestCase$this->auth($this->userName, $this->password, null, $this->authenticationMethod);$this->beforeStartApplication();- $this->espoApplication = $this->createApplication();++ $this->espoApplication = $this->espoTester->getApplication(reload: true);+$this->afterStartApplication();++ $this->setUpTransaction();++ $this->espoApplication = $this->espoTester->getApplication();+ }++ /**+ * Authenticates. The user is supposed to be created by the test before.+ *+ * @param ?string $username A username. Null for the system user.+ */+ protected function authenticate(+ ?string $username = null,+ ?string $method = null,+ ?RequestWrapper $request = null,+ ): void {++ $this->auth($username, authenticationMethod: $method, request: $request);++ $this->getEntityManager()->getMetadata()->updateData();++ $this->getContainer()->reset([+ 'entityManager',+ 'config',+ 'module',+ 'fileManager',+ 'applicationParams',+ ]);++ if ($username === null && $method === null) {+ $this->espoApplication->setupSystemUser();++ return;+ }++ $this->espoTester->login();}/**@@ -201,9 +265,26 @@ abstract class BaseTestCase extends TestCaseprotected function tearDown(): void{+ $isNotClean = $this->isNotCleanTest();++ if (+ !$isNotClean &&+ $this->transactionManager?->isStarted()+ ) {+ try {+ $this->transactionManager->rollback();+ } catch (Exception) {}+ }++ $this->transactionManager = null;+$this->espoTester->terminate();$this->espoTester = null;$this->espoApplication = null;++ if ($isNotClean) {+ Registry::$isCleanAndReady = false;+ }}/**@@ -258,11 +339,36 @@ abstract class BaseTestCase extends TestCase);}- /**- * @todo Revise whether needed.- */protected function fullReset(): void{$this->espoTester->setParam('fullReset', true);}++ private function isNotCleanTest(): bool+ {+ if ($this->dataFile || $this->pathToFiles || $this->initData) {+ return true;+ }++ try {+ $reflectionMethod = new ReflectionMethod($this, $this->name());+ $reflectionClass = new ReflectionClass($this);+ } catch (ReflectionException $e) {+ throw new RuntimeException(previous: $e);+ }++ return $reflectionMethod->getAttributes(NoTransaction::class) ||+ $reflectionClass->getAttributes(NoTransaction::class);+ }++ private function setUpTransaction(): void+ {+ $this->transactionManager = null;++ if (!$this->isNotCleanTest()) {+ $this->transactionManager = $this->getEntityManager()->getTransactionManager();++ $this->transactionManager->start();+ }+ }}diff --git a/tests/integration/Core/DataLoader.php b/tests/integration/Core/DataLoader.phpindex e9f9b40c15..a97d4097fe 100644--- a/tests/integration/Core/DataLoader.php+++ b/tests/integration/Core/DataLoader.php@@ -152,7 +152,7 @@ class DataLoadertry {$entityManager->saveEntity($entity);} catch (Exception $e) {- throw new RuntimeException('Error loadEntities: ' . $e->getMessage() . ', ' . print_r($entityData, true));+ throw new RuntimeException('Save entity error.', previous: $e);}}}diff --git a/tests/integration/testData/User/Login.php b/tests/integration/Core/NoTransaction.phpsimilarity index 59%rename from tests/integration/testData/User/Login.phprename to tests/integration/Core/NoTransaction.phpindex e3627d84a0..2519efe04f 100644--- a/tests/integration/testData/User/Login.php+++ b/tests/integration/Core/NoTransaction.php@@ -27,36 +27,10 @@* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.************************************************************************/-return [- 'entities' => [- 'User' => [- [- 'id' => '1',- 'isAdmin' => true,- 'type' => 'admin',- 'userName' => 'admin',- 'password' => '1',- 'salutationName' => '',- 'firstName' => '',- 'lastName' => 'Admin',- 'title' => '',- 'emailAddress' => '[email protected]',- 'phoneNumberData' => [- (object) [- 'phoneNumber' => '111',- 'primary' => true,- 'type' => 'Office',- ],- ],- ],- ],- 'Portal' => [- [- 'id' => 'testPortalId',- 'isActive' => true,- 'name' => 'Test portal',- 'customId' => 'test',- ],- ],- ],-];+namespace integration\Core;++use Attribute;++#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_CLASS)]+class NoTransaction+{}diff --git a/tests/integration/Core/Registry.php b/tests/integration/Core/Registry.phpnew file mode 100644index 0000000000..b0cb4e39f2--- /dev/null+++ b/tests/integration/Core/Registry.php@@ -0,0 +1,35 @@+<?php+/************************************************************************+ * This file is part of EspoCRM.+ *+ * EspoCRM – Open Source CRM application.+ * Copyright (C) 2014-2026 EspoCRM, Inc.+ * Website: https://www.espocrm.com+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as published by+ * the Free Software Foundation, either version 3 of the License, or+ * (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ * The interactive user interfaces in modified source and object code versions+ * of this program must display Appropriate Legal Notices, as required under+ * Section 5 of the GNU Affero General Public License version 3.+ *+ * In accordance with Section 7(b) of the GNU Affero General Public License version 3,+ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word.+ ************************************************************************/++namespace tests\integration\Core;++class Registry+{+ public static $isCleanAndReady = false;+}diff --git a/tests/integration/Core/Tester.php b/tests/integration/Core/Tester.phpindex debf3e04d3..7be2d28ecc 100644--- a/tests/integration/Core/Tester.php+++ b/tests/integration/Core/Tester.php@@ -39,6 +39,7 @@ use Espo\Core\Binding\BindingProcessor;use Espo\Core\Exceptions\Error;use Espo\Core\Exceptions\Forbidden;use Espo\Core\Exceptions\NotFound;+use Espo\Core\Exceptions\ServiceUnavailable;use Espo\Core\InjectableFactory;use Espo\Core\ORM\DatabaseParamsFactory;use Espo\Core\Portal\Application as PortalApplication;@@ -198,52 +199,35 @@ class Tester?BindingProcessor $binding = null,): Application {- $portalId = $portalId ?? $this->portalId ?? null;-- if (!isset($this->application) || $reload) {- if ($clearCache) {- $this->clearCache();- }-- $applicationParams = new Application\ApplicationParams(- noErrorHandler: true,- binding: $binding,- );-- if ($portalId) {- try {- $this->application = new PortalApplication($portalId, $applicationParams);- } catch (Forbidden|NotFound $e) {- throw new RuntimeException(previous: $e);- }- } else {- $this->application = new Application($applicationParams);- }-- $auth = $this->application- ->getContainer()- ->getByClass(InjectableFactory::class)- ->createWith(Authentication::class, ['allowAnyAccess' => false]);-- /** @var Psr7Request $requestWrapped */- $requestWrapped = (new RequestFactory())->createRequest('POST', '');-- $request = $this->request ?? new RequestWrapper($requestWrapped);+ if ($this->application && !$reload) {+ return $this->application;+ }- $response = new ResponseWrapper(new Response());+ $portalId ??= $this->portalId ?? null;- if (isset($this->userName) || $this->authenticationMethod) {- $this->password = $this->password ?? $this->defaultUserPassword;+ if ($clearCache) {+ $this->clearCache();+ }- $authenticationData = AuthenticationData::create()- ->withUsername($this->userName)- ->withPassword($this->password)- ->withMethod($this->authenticationMethod);+ $applicationParams = new Application\ApplicationParams(+ noErrorHandler: true,+ binding: $binding,+ );- $auth->login($authenticationData, $request, $response);- } else {- $this->application->setupSystemUser();+ if ($portalId) {+ try {+ $this->application = new PortalApplication($portalId, $applicationParams);+ } catch (Forbidden|NotFound $e) {+ throw new RuntimeException(previous: $e);}+ } else {+ $this->application = new Application($applicationParams);+ }++ if (isset($this->userName) || $this->authenticationMethod) {+ $this->login();+ } else {+ $this->application->setupSystemUser();}return $this->application;@@ -258,15 +242,6 @@ class Testerreturn $this->dataLoader;}- /**- * @throws Error- */- public function initialize(): void- {- $this->install();- $this->loadData();- }-private function changeDirToBase(): void{$installPath = str_replace('/', DIRECTORY_SEPARATOR, $this->installPath);@@ -289,7 +264,7 @@ class Tester/*** @throws Error*/- protected function install(): void+ public function install(): void{$fileManager = new FileManager();@@ -347,8 +322,8 @@ class Tester$app = new Application($applicationParams);try {- $this->createDatabase($app);- $this->dropTables($app);+ $this->createDatabaseIfDoesNotExist($app);+ $this->prepareDatabase($app);} catch (Exception $e) {throw new RuntimeException("DBAL error.", previous: $e);}@@ -356,6 +331,8 @@ class Tester$installer = new Installer($applicationParams); // reload installer to have all config data$installer->rebuild();$installer->setSuccess();++ Registry::$isCleanAndReady = true;}// PDO can't be instantiated as dbname is set but database does not exist.@@ -363,7 +340,7 @@ class Tester/*** @throws Exception*/- private function createDatabase(Application $app): void+ private function createDatabaseIfDoesNotExist(Application $app): void{$injectableFactory = $app->getContainer()->getByClass(InjectableFactory::class);@@ -401,8 +378,12 @@ class Tester* @throws SchemaException* @throws Exception*/- private function dropTables(Application $app): void+ private function prepareDatabase(Application $app): void{+ if (Registry::$isCleanAndReady) {+ return;+ }+$databaseHelper = $app->getContainer()->getByClass(InjectableFactory::class)->create(DatabaseHelper::class);@@ -459,32 +440,7 @@ class Tester$fileManager->unlink($this->installPath . '/install/config.php');}- /*private function cleanDirectory(string $path, array $ignoreList = []): void- {- if (!file_exists($path)) {- return;- }-- $fileManager = new FileManager();-- $list = $fileManager->getFileList($path);-- foreach ($list as $itemName) {- if (in_array($itemName, $ignoreList)) {- continue;- }-- $itemPath = $path . '/' . $itemName;-- if (is_file($itemPath)) {- $fileManager->unlink($itemPath);- } else {- $fileManager->removeInDir($itemPath, true);- }- }- }*/-- private function loadData(): void+ public function loadData(): void{$applyChanges = false;@@ -494,13 +450,15 @@ class Tester$this->getApplication(true)->run(Rebuild::class);}- if (!empty($this->params['dataFile'])) {+ if (!empty($this->params['dataFile']) && file_exists($this->params['dataFile'])) {$this->getDataLoader()->loadData($this->params['dataFile']);+$applyChanges = true;}if (!empty($this->params['initData'])) {$this->getDataLoader()->setData($this->params['initData']);+$applyChanges = true;}@@ -618,4 +576,31 @@ class Testerreturn true;}++ public function login(): void+ {+ $this->password ??= $this->defaultUserPassword;++ $authenticationData = AuthenticationData::create()+ ->withUsername($this->userName)+ ->withPassword($this->password)+ ->withMethod($this->authenticationMethod);++ $auth = $this->application+ ->getInjectableFactory()+ ->createWith(Authentication::class, ['allowAnyAccess' => false]);++ /** @var Psr7Request $requestWrapped */+ $requestWrapped = (new RequestFactory())->createRequest('POST', '');++ $request = $this->request ?? new RequestWrapper($requestWrapped);++ $response = new ResponseWrapper(new Response());++ try {+ $auth->login($authenticationData, $request, $response);+ } catch (ServiceUnavailable|Forbidden $e) {+ throw new RuntimeException(previous: $e);+ }+ }}diff --git a/tests/integration/Espo/Actions/ActionTest.php b/tests/integration/Espo/Actions/ActionTest.phpindex cc7c874859..eb91469c07 100644--- a/tests/integration/Espo/Actions/ActionTest.php+++ b/tests/integration/Espo/Actions/ActionTest.php@@ -44,13 +44,9 @@ use tests\integration\Core\BaseTestCase;class ActionTest extends BaseTestCase{- /** @var Application */- private $app;-/** @var EntityManager */private $entityManager;-/** @var Merger */private $merger;@@ -58,17 +54,14 @@ class ActionTest extends BaseTestCaseprivate function init(): void{- $this->app = $this->createApplication();-- $this->entityManager = $this->app+ $this->entityManager = $this->getApplication()->getContainer()- ->get('entityManager');+ ->getByClass(EntityManager::class);$this->action = $this->getInjectableFactory()->create(PostProcess::class);- $this->merger = $this->app- ->getContainer()- ->get('injectableFactory')+ $this->merger = $this->getApplication()+ ->getInjectableFactory()->create(Merger::class);}@@ -109,7 +102,7 @@ class ActionTest extends BaseTestCase],]);- $this->auth('tester');+ $this->authenticate('tester');$this->init();@@ -330,7 +323,7 @@ class ActionTest extends BaseTestCase],]);- $this->auth('tester');+ $this->authenticate('tester');$this->init();@@ -358,7 +351,7 @@ class ActionTest extends BaseTestCase],]);- $this->auth('tester');+ $this->authenticate('tester');$this->init();diff --git a/tests/integration/Espo/Actions/MassActionTest.php b/tests/integration/Espo/Actions/MassActionTest.phpindex d1fab86315..7d633b1c91 100644--- a/tests/integration/Espo/Actions/MassActionTest.php+++ b/tests/integration/Espo/Actions/MassActionTest.php@@ -40,10 +40,8 @@ use Espo\Core\MassAction\Jobs\Process as JobProcess;use Espo\Core\Job\Job\Data as JobData;use Espo\Core\Select\SearchParams;-use Espo\Core\InjectableFactory;use Espo\Core\Api\ResponseWrapper;-use Espo\Core\Application;use Espo\Core\Exceptions\Error;use Espo\Core\Exceptions\Forbidden;use Espo\ORM\EntityManager;@@ -51,11 +49,10 @@ use Espo\Modules\Crm\Entities\Contact;use Espo\Modules\Crm\Entities\Opportunity;use Espo\Tools\MassUpdate\Data as MassUpdateData;use Espo\Tools\MassUpdate\Processor;+use tests\integration\Core\BaseTestCase;-class MassActionTest extends \tests\integration\Core\BaseTestCase+class MassActionTest extends BaseTestCase{- /** @var Application */- private $app;/** @var EntityManager */private $entityManager;@@ -63,11 +60,9 @@ class MassActionTest extends \tests\integration\Core\BaseTestCaseprivate function init(): void{- $this->app = $this->createApplication();-- $this->entityManager = $this->app+ $this->entityManager = $this->getApplication()->getContainer()- ->get('entityManager');+ ->getByClass(EntityManager::class);$this->action = $this->getInjectableFactory()->create(PostProcess::class);}@@ -102,8 +97,7 @@ class MassActionTest extends \tests\integration\Core\BaseTestCase'type' => 'admin',]);- $this->auth('admin-test');-+ $this->authenticate('admin-test');$this->init();$account = $this->entityManager->createEntity('Account', [@@ -157,17 +151,16 @@ class MassActionTest extends \tests\integration\Core\BaseTestCasejson_encode($data));- $response = $this->createMock(ResponseWrapper::class);+ $this->createMock(ResponseWrapper::class);$this->expectException(Forbidden::class);$this->action->process($request);}- public function testAcl1()+ public function testAcl1(): void{- /** @var EntityManager $em */- $em = $this->getApplication()->getContainer()->get('entityManager');+ $em = $this->getEntityManager();$user = $this->createUser('tester', ['massUpdatePermission' => 'yes',@@ -190,14 +183,11 @@ class MassActionTest extends \tests\integration\Core\BaseTestCase'name' => '2',]);- $this->auth('tester');-- $app = $this->createApplication();+ $this->authenticate('tester');- /** @var InjectableFactory $injectableFactory */- $injectableFactory = $app->getContainer()->get('injectableFactory');+ $injectableFactory = $this->getInjectableFactory();- $this->assertEquals($user->getId(), $app->getContainer()->get('user')->getId());+ $this->assertEquals($user->getId(), $this->getContainer()->getByClass(User::class)->getId());/** @var Service $service */$service = $injectableFactory->create(Service::class);@@ -221,14 +211,11 @@ class MassActionTest extends \tests\integration\Core\BaseTestCase$massActionId = $serviceResult->getId();- $this->auth(null);+ $this->authenticate(null);- $app1 = $this->getApplication();+ $this->assertEquals('system', $this->getContainer()->getByClass(User::class)->getId());- $this->assertEquals('system', $app1->getContainer()->get('user')->getId());-- /** @var InjectableFactory $injectableFactory1 */- $injectableFactory1 = $app1->getContainer()->get('injectableFactory');+ $injectableFactory1 = $this->getInjectableFactory();$process = $injectableFactory1->create(JobProcess::class);@@ -243,9 +230,6 @@ class MassActionTest extends \tests\integration\Core\BaseTestCasepublic function testAcl2(){- /** @var EntityManager $em */- $em = $this->getApplication()->getContainer()->get('entityManager');-$user = $this->createUser('tester', ['massUpdatePermission' => 'yes','data' => [@@ -258,18 +242,14 @@ class MassActionTest extends \tests\integration\Core\BaseTestCase],]);- $user1 = $this->createUser('tester-1', []);-- $this->auth('tester');+ $this->createUser('tester-1', []);- $app = $this->createApplication();+ $this->authenticate('tester');- /** @var InjectableFactory $injectableFactory */- $injectableFactory = $app->getContainer()->get('injectableFactory');+ $injectableFactory = $this->getInjectableFactory();- $this->assertEquals($user->getId(), $app->getContainer()->get('user')->getId());+ $this->assertEquals($user->getId(), $this->getContainer()->getByClass(User::class)->getId());- /** @var Service $service */$service = $injectableFactory->create(Service::class);$serviceParams = ServiceParams@@ -291,14 +271,11 @@ class MassActionTest extends \tests\integration\Core\BaseTestCase$massActionId = $serviceResult->getId();- $this->auth(null);-- $app1 = $this->getApplication();+ $this->authenticate(null);- $this->assertEquals('system', $app1->getContainer()->get('user')->getId());+ $this->assertEquals('system', $this->getContainer()->getByClass(User::class)->getId());- /** @var InjectableFactory $injectableFactory1 */- $injectableFactory1 = $app1->getContainer()->get('injectableFactory');+ $injectableFactory1 = $this->getInjectableFactory();$process = $injectableFactory1->create(JobProcess::class);@@ -306,12 +283,6 @@ class MassActionTest extends \tests\integration\Core\BaseTestCase$this->expectException(Error::class);$process->run(JobData::create()->withTargetId($massActionId));-- /*$em->refreshEntity($user);- $em->refreshEntity($user1);-- $this->assertEquals('Tester', $user->get('title'));- $this->assertEquals(null, $user1->get('title'));*/}public function testMassUpdateLinkAccess(): void@@ -334,8 +305,8 @@ class MassActionTest extends \tests\integration\Core\BaseTestCase],]);- $this->auth('tester');- $this->setApplication($this->createApplication());++ $this->authenticate('tester');$contact1 = $this->getEntityManager()->createEntity(Contact::ENTITY_TYPE, [diff --git a/tests/integration/Espo/Core/Acl/AclTest.php b/tests/integration/Espo/Core/Acl/AclTest.phpindex 281e87ecef..4328589c15 100644--- a/tests/integration/Espo/Core/Acl/AclTest.php+++ b/tests/integration/Espo/Core/Acl/AclTest.php@@ -36,6 +36,7 @@ use Espo\Modules\Crm\Entities\Account;use Espo\Modules\Crm\Entities\Call;use Espo\Modules\Crm\Entities\Meeting;use Espo\Modules\Crm\Entities\Task;+use integration\Core\NoTransaction;use tests\integration\Core\BaseTestCase;class AclTest extends BaseTestCase@@ -94,8 +95,7 @@ class AclTest extends BaseTestCase],]);- $this->auth('tester');- $this->reCreateApplication();+ $this->authenticate('tester');$acl = $this->getContainer()->getByClass(Acl::class);@@ -136,6 +136,7 @@ class AclTest extends BaseTestCase$this->assertFalse($aclManager->checkField($user, 'Call', 'contacts', Acl\Table::ACTION_EDIT));}+ #[NoTransaction]public function testDisabledField(): void{$metadata = $this->getMetadata();@@ -157,6 +158,7 @@ class AclTest extends BaseTestCase$this->assertTrue($acl->checkField(Account::ENTITY_TYPE, 'name'));}+ #[NoTransaction]public function testDisabledLink(): void{$metadata = $this->getMetadata();diff --git a/tests/integration/Espo/Core/Notification/AssignmentNotificatorTest.php b/tests/integration/Espo/Core/Notification/AssignmentNotificatorTest.phpindex 4edd7baabe..9bbaa2fd68 100644--- a/tests/integration/Espo/Core/Notification/AssignmentNotificatorTest.php+++ b/tests/integration/Espo/Core/Notification/AssignmentNotificatorTest.php@@ -29,13 +29,11 @@namespace tests\integration\Espo\Core\Notification;-use Espo\Core\Container;use Espo\ORM\EntityManager;use Espo\Core\Utils\Config\ConfigWriter;-use Espo\{- Core\InjectableFactory,- Entities\User};+use Espo\Core\InjectableFactory;+use Espo\Entities\User;use tests\integration\Core\BaseTestCase;class AssignmentNotificatorTest extends BaseTestCase@@ -56,18 +54,13 @@ class AssignmentNotificatorTest extends BaseTestCase*/private $user2;-public function setUp(): void{parent::setUp();$this->initTestData();- $application = $this->createApplication();-- $container = $application->getContainer();-- $this->entityManager = $container->getByClass(EntityManager::class);+ $this->entityManager = $this->getEntityManager();}private function initTestData() : void@@ -87,7 +80,7 @@ class AssignmentNotificatorTest extends BaseTestCase$configWriter->save();- $em = $this->getContainer()->get('entityManager');+ $em = $this->getEntityManager();$role = $em->createEntity('Role', ['name' => 'test',@@ -122,7 +115,7 @@ class AssignmentNotificatorTest extends BaseTestCase'emailAddress' => '[email protected]',]);- $preferences2 = $em->getEntity('Preferences', $this->user2->getId());+ $preferences2 = $em->getEntityById('Preferences', $this->user2->getId());$preferences2->set(['assignmentNotificationsIgnoreEntityTypeList' => ['Meeting'],@@ -223,7 +216,7 @@ class AssignmentNotificatorTest extends BaseTestCase]);$notification = $this->entityManager- ->getRepository('Notification')+ ->getRDBRepository('Notification')->where(['userId' => $this->user1->getId(),'type' => 'EmailReceived',diff --git a/tests/integration/Espo/Core/Select/SelectBuilderTest.php b/tests/integration/Espo/Core/Select/SelectBuilderTest.phpindex aac1145c53..00dc9bf3f7 100644--- a/tests/integration/Espo/Core/Select/SelectBuilderTest.php+++ b/tests/integration/Espo/Core/Select/SelectBuilderTest.php@@ -44,6 +44,7 @@ use Espo\Modules\Crm\Entities\Opportunity;use Espo\ORM\EntityManager;use Espo\ORM\Query\Part\Join\JoinType;use Espo\ORM\Query\Select;+use integration\Core\NoTransaction;use tests\integration\Core\BaseTestCase;class SelectBuilderTest extends BaseTestCase@@ -53,7 +54,7 @@ class SelectBuilderTest extends BaseTestCase*/private $factory;- private $user;+ private ?User $user = null;private $contact;private $account;@@ -73,18 +74,16 @@ class SelectBuilderTest extends BaseTestCase]);if (!$skipLogin) {- $this->auth('tester');+ $this->authenticate('tester');}- $app = $this->createApplication();-- $injectableFactory = $app->getContainer()->getByClass(InjectableFactory::class);+ $injectableFactory = $this->getInjectableFactory();$this->factory = $injectableFactory->create(SelectBuilderFactory::class);- $this->user = $app->getContainer()->getByClass(User::class);+ $this->user = $this->getContainer()->getByClass(User::class);- return $app;+ return $this->getApplication();}protected function initTestPortal(array $aclData = [], bool $skipLogin = false) : Application@@ -434,6 +433,7 @@ class SelectBuilderTest extends BaseTestCase$this->assertEquals($expected, $raw);}+ #[NoTransaction]public function testEmailAccessFilterOnlyAccount(){$this->initTestPortal(@@ -485,6 +485,7 @@ class SelectBuilderTest extends BaseTestCase$this->assertEquals($expected['joins'], $raw['joins']);}+ #[NoTransaction]public function testEmailAccessFilterOnlyContact(){$this->initTestPortal(diff --git a/tests/integration/Espo/Core/Utils/Database/AddressFieldTest.php b/tests/integration/Espo/Core/Utils/Database/AddressFieldTest.phpindex 76960e6112..b66f50c56a 100644--- a/tests/integration/Espo/Core/Utils/Database/AddressFieldTest.php+++ b/tests/integration/Espo/Core/Utils/Database/AddressFieldTest.php@@ -29,8 +29,10 @@namespace tests\integration\Espo\Core\Utils\Database;+use integration\Core\NoTransaction;use PHPUnit\Framework\Attributes\DataProvider;+#[NoTransaction]class AddressFieldTest extends Base{static public function fieldList()diff --git a/tests/integration/Espo/Core/Utils/Database/ArrayFieldTest.php b/tests/integration/Espo/Core/Utils/Database/ArrayFieldTest.phpindex 91a595a942..effbe2e094 100644--- a/tests/integration/Espo/Core/Utils/Database/ArrayFieldTest.php+++ b/tests/integration/Espo/Core/Utils/Database/ArrayFieldTest.php@@ -29,6 +29,9 @@namespace tests\integration\Espo\Core\Utils\Database;+use integration\Core\NoTransaction;++#[NoTransaction]class ArrayFieldTest extends Base{public function testColumn()diff --git a/tests/integration/Espo/Core/Utils/Database/AutoIncrementFieldTest.php b/tests/integration/Espo/Core/Utils/Database/AutoIncrementFieldTest.phpindex 96174e0032..6dbc5e8d07 100644--- a/tests/integration/Espo/Core/Utils/Database/AutoIncrementFieldTest.php+++ b/tests/integration/Espo/Core/Utils/Database/AutoIncrementFieldTest.php@@ -29,6 +29,9 @@namespace tests\integration\Espo\Core\Utils\Database;+use integration\Core\NoTransaction;++#[NoTransaction]class AutoIncrementFieldTest extends Base{public function testColumn()diff --git a/tests/integration/Espo/Core/Utils/Database/BooleanFieldTest.php b/tests/integration/Espo/Core/Utils/Database/BooleanFieldTest.phpindex 7044636434..8b86a1362f 100644--- a/tests/integration/Espo/Core/Utils/Database/BooleanFieldTest.php+++ b/tests/integration/Espo/Core/Utils/Database/BooleanFieldTest.php@@ -29,6 +29,9 @@namespace tests\integration\Espo\Core\Utils\Database;+use integration\Core\NoTransaction;++#[NoTransaction]class BooleanFieldTest extends Base{public function testColumn()diff --git a/tests/integration/Espo/Core/Utils/Database/CurrencyFieldTest.php b/tests/integration/Espo/Core/Utils/Database/CurrencyFieldTest.phpindex 9860ed4406..22b71d4c96 100644--- a/tests/integration/Espo/Core/Utils/Database/CurrencyFieldTest.php+++ b/tests/integration/Espo/Core/Utils/Database/CurrencyFieldTest.php@@ -29,8 +29,10 @@namespace tests\integration\Espo\Core\Utils\Database;+use integration\Core\NoTransaction;use PHPUnit\Framework\Attributes\DataProvider;+#[NoTransaction]class CurrencyFieldTest extends Base{static public function fieldList(): arraydiff --git a/tests/integration/Espo/Core/Utils/Database/DateFieldTest.php b/tests/integration/Espo/Core/Utils/Database/DateFieldTest.phpindex 60acc46674..c5225e4ef5 100644--- a/tests/integration/Espo/Core/Utils/Database/DateFieldTest.php+++ b/tests/integration/Espo/Core/Utils/Database/DateFieldTest.php@@ -29,6 +29,9 @@namespace tests\integration\Espo\Core\Utils\Database;+use integration\Core\NoTransaction;++#[NoTransaction]class DateFieldTest extends Base{public function testColumn()diff --git a/tests/integration/Espo/Core/Utils/Database/DateTimeFieldTest.php b/tests/integration/Espo/Core/Utils/Database/DateTimeFieldTest.phpindex a7e9ffc175..8f98d9287d 100644--- a/tests/integration/Espo/Core/Utils/Database/DateTimeFieldTest.php+++ b/tests/integration/Espo/Core/Utils/Database/DateTimeFieldTest.php@@ -29,6 +29,9 @@namespace tests\integration\Espo\Core\Utils\Database;+use integration\Core\NoTransaction;++#[NoTransaction]class DateTimeFieldTest extends Base{public function testColumn()diff --git a/tests/integration/Espo/Core/Utils/Database/FileFieldTest.php b/tests/integration/Espo/Core/Utils/Database/FileFieldTest.phpindex 8bca7816a3..3fdc69611d 100644--- a/tests/integration/Espo/Core/Utils/Database/FileFieldTest.php+++ b/tests/integration/Espo/Core/Utils/Database/FileFieldTest.php@@ -29,6 +29,9 @@namespace tests\integration\Espo\Core\Utils\Database;+use integration\Core\NoTransaction;++#[NoTransaction]class FileFieldTest extends Base{public function testColumn()diff --git a/tests/integration/Espo/Core/Utils/Database/FloatFieldTest.php b/tests/integration/Espo/Core/Utils/Database/FloatFieldTest.phpindex 7409fefcde..45393e07c1 100644--- a/tests/integration/Espo/Core/Utils/Database/FloatFieldTest.php+++ b/tests/integration/Espo/Core/Utils/Database/FloatFieldTest.php@@ -29,6 +29,9 @@namespace tests\integration\Espo\Core\Utils\Database;+use integration\Core\NoTransaction;++#[NoTransaction]class FloatFieldTest extends Base{public function testColumn()diff --git a/tests/integration/Espo/Core/Utils/Database/HelperTest.php b/tests/integration/Espo/Core/Utils/Database/HelperTest.phpindex 4bfb4280db..ddda703856 100644--- a/tests/integration/Espo/Core/Utils/Database/HelperTest.php+++ b/tests/integration/Espo/Core/Utils/Database/HelperTest.php@@ -32,8 +32,9 @@ namespace tests\integration\Espo\Core\Utils\Database;use Espo\Core\Utils\Database\Helper;use Doctrine\DBAL\Connection;use PDO;+use tests\integration\Core\BaseTestCase;-class HelperTest extends \tests\integration\Core\BaseTestCase+class HelperTest extends BaseTestCase{/** @var ?Helper */protected $helper;@@ -45,7 +46,7 @@ class HelperTest extends \tests\integration\Core\BaseTestCaseprivate function getDatabaseInfo(){- $pdo = $this->getContainer()->get('entityManager')->getPDO();+ $pdo = $this->getEntityManager()->getPDO();$sth = $pdo->prepare("select version()");$sth->execute();diff --git a/tests/integration/Espo/Core/Utils/Database/IntegerFieldTest.php b/tests/integration/Espo/Core/Utils/Database/IntegerFieldTest.phpindex eb7664730f..f974bbbfef 100644--- a/tests/integration/Espo/Core/Utils/Database/IntegerFieldTest.php+++ b/tests/integration/Espo/Core/Utils/Database/IntegerFieldTest.php@@ -29,6 +29,9 @@namespace tests\integration\Espo\Core\Utils\Database;+use integration\Core\NoTransaction;++#[NoTransaction]class IntegerFieldTest extends Base{public function testColumn()diff --git a/tests/integration/Espo/Core/Utils/Database/TextFieldTest.php b/tests/integration/Espo/Core/Utils/Database/TextFieldTest.phpindex c3cb042138..e06bab8dbd 100644--- a/tests/integration/Espo/Core/Utils/Database/TextFieldTest.php+++ b/tests/integration/Espo/Core/Utils/Database/TextFieldTest.php@@ -29,6 +29,9 @@namespace tests\integration\Espo\Core\Utils\Database;+use integration\Core\NoTransaction;++#[NoTransaction]class TextFieldTest extends Base{public function testColumn()diff --git a/tests/integration/Espo/Core/Utils/Database/VarcharFieldTest.php b/tests/integration/Espo/Core/Utils/Database/VarcharFieldTest.phpindex 4193c503f9..0d743e2b13 100644--- a/tests/integration/Espo/Core/Utils/Database/VarcharFieldTest.php+++ b/tests/integration/Espo/Core/Utils/Database/VarcharFieldTest.php@@ -30,7 +30,9 @@namespace tests\integration\Espo\Core\Utils\Database;use Espo\Core\Utils\Database\Helper as DatabaseHelper;+use integration\Core\NoTransaction;+#[NoTransaction]class VarcharFieldTest extends Base{public function testColumn()diff --git a/tests/integration/Espo/Core/Utils/FieldManager/EnumTypeTest.php b/tests/integration/Espo/Core/Utils/FieldManager/EnumTypeTest.phpindex 787a4c88d2..cb5eab3553 100644--- a/tests/integration/Espo/Core/Utils/FieldManager/EnumTypeTest.php+++ b/tests/integration/Espo/Core/Utils/FieldManager/EnumTypeTest.php@@ -29,6 +29,7 @@namespace tests\integration\Espo\Core\Utils\FieldManager;+use Espo\Core\Utils\Metadata;use Espo\ORM\EntityManager;use tests\integration\Core\BaseTestCase;@@ -72,11 +73,11 @@ class EnumTypeTest extends BaseTestCase$fieldDefs = get_object_vars(json_decode($this->jsonFieldDefs));$fieldManager->create('Account', 'testEnum', $fieldDefs);- $this->getContainer()->get('dataManager')->rebuild(['Account']);+ $this->getDataManager()->rebuild(['Account']);$app = $this->createApplication();- $metadata = $app->getContainer()->get('metadata');+ $metadata = $app->getContainer()->getByClass(Metadata::class);$savedFieldDefs = $metadata->get('entityDefs.Account.fields.cTestEnum');$this->assertEquals('enum', $savedFieldDefs['type']);@@ -113,7 +114,7 @@ class EnumTypeTest extends BaseTestCase$fieldDefs['readOnly'] = true;$fieldManager->update('Account', 'cTestEnum', $fieldDefs);- $this->getContainer()->get('dataManager')->rebuild(['Account']);+ $this->getDataManager()->rebuild(['Account']);$app = $this->createApplication();diff --git a/tests/integration/Espo/Currency/CurrencyTest.php b/tests/integration/Espo/Currency/CurrencyTest.phpindex b0beaefdd6..13a1fc0b88 100644--- a/tests/integration/Espo/Currency/CurrencyTest.php+++ b/tests/integration/Espo/Currency/CurrencyTest.php@@ -40,6 +40,7 @@ use Espo\Core\Currency\Rates;use Espo\Core\Field\Currency;use Espo\Core\Utils\Config\ConfigWriter;use Espo\Tools\Currency\SyncManager;+use integration\Core\NoTransaction;use tests\integration\Core\BaseTestCase;class CurrencyTest extends BaseTestCase@@ -78,6 +79,7 @@ class CurrencyTest extends BaseTestCase/*** @throws Error*/+ #[NoTransaction]public function testDecimal1(): void{$this->getMetadata()->set('entityDefs', 'Lead', [@@ -183,6 +185,7 @@ class CurrencyTest extends BaseTestCase/*** @noinspection PhpUnhandledExceptionInspection*/+ #[NoTransaction]public function testDefaultCurrencyJoinMode(): void{$configWriter = $this->getInjectableFactory()->create(ConfigWriter::class);@@ -225,6 +228,7 @@ class CurrencyTest extends BaseTestCase/*** @noinspection PhpUnhandledExceptionInspection*/+ #[NoTransaction]public function testDefaultCurrencyNoJoinMode(): void{$configWriter = $this->getInjectableFactory()->create(ConfigWriter::class);diff --git a/tests/integration/Espo/Email/SearchByEmailAddressTest.php b/tests/integration/Espo/Email/SearchByEmailAddressTest.phpindex 667922c1f4..7af58731e6 100644--- a/tests/integration/Espo/Email/SearchByEmailAddressTest.php+++ b/tests/integration/Espo/Email/SearchByEmailAddressTest.php@@ -29,22 +29,29 @@namespace tests\integration\Espo\Email;+use Espo\Core\Record\ServiceContainer;use Espo\Core\Select\SearchParams;+use Espo\Entities\Email;+use integration\Core\NoTransaction;+use tests\integration\Core\BaseTestCase;-class SearchByEmailAddressTest extends \tests\integration\Core\BaseTestCase+class SearchByEmailAddressTest extends BaseTestCase{public function testSearchByEmailAddress(){- $entityManager = $this->getContainer()->get('entityManager');+ $entityManager = $this->getEntityManager();- $email = $entityManager->getEntity('Email');+ $email = $entityManager->getNewEntity('Email');$email->set('from', '[email protected]');$email->set('status', 'Archived');$entityManager->saveEntity($email);- $emailService = $this->getApplication()->getContainer()->get('serviceFactory')->create('Email');+ $emailService = $this->getApplication()+ ->getContainer()+ ->getByClass(ServiceContainer::class)+ ->getByClass(Email::class);$result = $emailService->find(SearchParams::fromRaw([@@ -61,11 +68,15 @@ class SearchByEmailAddressTest extends \tests\integration\Core\BaseTestCase$this->assertEquals(1, count($result->getCollection()));}+ /**+ * Full-text search index is not applied for uncommited data.+ */+ #[NoTransaction]public function testTextSearch(){- $entityManager = $this->getContainer()->get('entityManager');+ $entityManager = $this->getEntityManager();- $email = $entityManager->getEntity('Email');+ $email = $entityManager->getNewEntity('Email');$email->set('from', '[email protected]');$email->set('status', 'Archived');@@ -74,7 +85,10 @@ class SearchByEmailAddressTest extends \tests\integration\Core\BaseTestCase$entityManager->saveEntity($email);- $emailService = $this->getApplication()->getContainer()->get('serviceFactory')->create('Email');+ $emailService = $this->getApplication()+ ->getContainer()+ ->getByClass(ServiceContainer::class)+ ->getByClass(Email::class);$result = $emailService->find(SearchParams::fromRaw([diff --git a/tests/integration/Espo/Extension/GeneralTest.php b/tests/integration/Espo/Extension/GeneralTest.phpindex 67141d4528..1244591668 100644--- a/tests/integration/Espo/Extension/GeneralTest.php+++ b/tests/integration/Espo/Extension/GeneralTest.php@@ -30,26 +30,41 @@namespace tests\integration\Espo\Extension;use Espo\Core\Upgrades\ExtensionManager;+use Espo\Entities\User;+use integration\Core\NoTransaction;+use tests\integration\Core\BaseTestCase;-class GeneralTest extends \tests\integration\Core\BaseTestCase+class GeneralTest extends BaseTestCase{- protected ?string $dataFile = 'InitData.php';-- protected ?string $userName = 'admin';protected ?string $password = '1';protected $packagePath = 'Extension/General.zip';+ protected function setUp(): void+ {+ parent::setUp();++ $this->createUser([+ 'type' => User::TYPE_ADMIN,+ 'userName' => 'admin',+ 'lastName' => 'Admin',+ 'password' => $this->password,+ ]);+ }+protected function beforeSetUp(): void{- //$this->fullReset();+ $this->fullReset();}/*** If this test fails, an instance may become broken for consecutive test runs.*/+ #[NoTransaction]public function testExtensionUploadInstallUninstallDelete(): void{+ $this->authenticate('admin');+$extensionId = $this->testUninstall();$extensionManager = new ExtensionManager($this->getContainer());diff --git a/tests/integration/Espo/GlobalSearch/GlobalSearchTest.php b/tests/integration/Espo/GlobalSearch/GlobalSearchTest.phpindex 1d83c9e666..cf0bebf006 100644--- a/tests/integration/Espo/GlobalSearch/GlobalSearchTest.php+++ b/tests/integration/Espo/GlobalSearch/GlobalSearchTest.php@@ -30,14 +30,14 @@namespace tests\integration\Espo\GlobalSearch;use Espo\Tools\GlobalSearch\Service;+use tests\integration\Core\BaseTestCase;-class GlobalSearchTest extends \tests\integration\Core\BaseTestCase+class GlobalSearchTest extends BaseTestCase{- public function testSearch1()+ public function testSearch1(): void{- $app = $this->createApplication();- $em = $app->getContainer()->get('entityManager');+ $em = $this->getEntityManager();$team = $em->createEntity('Team', ['name' => 'test',@@ -82,11 +82,9 @@ class GlobalSearchTest extends \tests\integration\Core\BaseTestCase],]);- $this->auth('tester');+ $this->authenticate('tester');- $app = $this->createApplication(true);-- $service = $app->getContainer()->get('injectableFactory')->create(Service::class);+ $service = $this->getInjectableFactory()->create(Service::class);$result = $service->find('1', 0, 10);diff --git a/tests/integration/Espo/ORM/MapperTest.php b/tests/integration/Espo/ORM/MapperTest.phpindex 44853eda35..5a43b5d260 100644--- a/tests/integration/Espo/ORM/MapperTest.php+++ b/tests/integration/Espo/ORM/MapperTest.php@@ -36,10 +36,7 @@ class MapperTest extends BaseTestCase{public function testRelate1(){- $app = $this->createApplication();-- /** @var EntityManager $entityManager */- $entityManager = $app->getContainer()->getByClass(EntityManager::class);+ $entityManager = $this->getContainer()->getByClass(EntityManager::class);$account = $entityManager->getNewEntity('Account');$account->set('name', 'Test');@@ -60,10 +57,7 @@ class MapperTest extends BaseTestCasepublic function testRelate2(){- $app = $this->createApplication();-- /** @var EntityManager $entityManager */- $entityManager = $app->getContainer()->getByClass(EntityManager::class);+ $entityManager = $this->getEntityManager();$account = $entityManager->getNewEntity('Account');$account->set('name', 'Test');@@ -87,10 +81,7 @@ class MapperTest extends BaseTestCasepublic function testRelate3WithEntityReFetching(){- $app = $this->createApplication();-- /** @var EntityManager $entityManager */- $entityManager = $app->getContainer()->getByClass(EntityManager::class);+ $entityManager = $this->getEntityManager();$account = $entityManager->getNewEntity('Account');$account->set('name', 'Test');@@ -112,8 +103,7 @@ class MapperTest extends BaseTestCase$this->assertTrue($isRelated);- /** @var EntityManager $entityManager */- $entityManager = $app->getContainer()->getByClass(EntityManager::class);+ $entityManager = $this->getEntityManager();$entityManager->getRDBRepository('Contact')->getRelation($contact, 'account')@@ -131,10 +121,7 @@ class MapperTest extends BaseTestCasepublic function testRelate4(){- $app = $this->createApplication();-- /** @var EntityManager $entityManager */- $entityManager = $app->getContainer()->getByClass(EntityManager::class);+ $entityManager = $this->getEntityManager();$account = $entityManager->getNewEntity('Account');$account->set('name', 'Test');@@ -158,10 +145,7 @@ class MapperTest extends BaseTestCasepublic function testRelateOneToOne1(){- $app = $this->createApplication();-- /** @var EntityManager $em */- $em = $app->getContainer()->getByClass(EntityManager::class);+ $em = $this->getEntityManager();$a1 = $em->createEntity('Account', ['name' => '1',@@ -214,10 +198,7 @@ class MapperTest extends BaseTestCasepublic function testRelateOneToOne2(){- $app = $this->createApplication();-- /** @var EntityManager $em */- $em = $app->getContainer()->getByClass(EntityManager::class);+ $em = $this->getEntityManager();$a1 = $em->createEntity('Account', ['name' => '1',@@ -272,10 +253,7 @@ class MapperTest extends BaseTestCasepublic function testRelateOneToOne3(){- $app = $this->createApplication();-- /** @var EntityManager $em */- $em = $app->getContainer()->getByClass(EntityManager::class);+ $em = $this->getEntityManager();$a1 = $em->createEntity('Account', ['name' => '1',@@ -329,10 +307,7 @@ class MapperTest extends BaseTestCasepublic function testUnrelateOneToOne1(){- $app = $this->createApplication();-- /** @var EntityManager $em */- $em = $app->getContainer()->getByClass(EntityManager::class);+ $em = $this->getEntityManager();$a1 = $em->createEntity('Account', ['name' => '1',diff --git a/tests/integration/Espo/ORM/RelationsTest.php b/tests/integration/Espo/ORM/RelationsTest.phpindex 7c60c02316..42703847b8 100644--- a/tests/integration/Espo/ORM/RelationsTest.php+++ b/tests/integration/Espo/ORM/RelationsTest.php@@ -54,7 +54,9 @@ class RelationsTest extends BaseTestCase]);$metadata->save();- $this->reCreateApplication();+ $this->authenticate(null);++ //$this->reCreateApplication();$em = $this->getEntityManager();@@ -109,7 +111,9 @@ class RelationsTest extends BaseTestCase]);$metadata->save();- $this->reCreateApplication();+ $this->authenticate(null);++ //$this->reCreateApplication();$em = $this->getEntityManager();@@ -140,7 +144,9 @@ class RelationsTest extends BaseTestCase]);$metadata->save();- $this->reCreateApplication();+ $this->authenticate(null);++ //$this->reCreateApplication();$em = $this->getEntityManager();diff --git a/tests/integration/Espo/ORM/RepositoryTest.php b/tests/integration/Espo/ORM/RepositoryTest.phpindex 83c3811c09..2c356c4057 100644--- a/tests/integration/Espo/ORM/RepositoryTest.php+++ b/tests/integration/Espo/ORM/RepositoryTest.php@@ -32,28 +32,27 @@ namespace tests\integration\Espo\ORM;use Espo\Modules\Crm\Entities\Account;use Espo\Modules\Crm\Entities\Contact;use Espo\Modules\Crm\Entities\Opportunity;-use Espo\ORM\EntityManager;+use tests\integration\Core\BaseTestCase;-class RepositoryTest extends \tests\integration\Core\BaseTestCase+class RepositoryTest extends BaseTestCase{public function testModifiedBy(): void{$user1 = $this->createUser('test-1');$user2 = $this->createUser('test-2');- $this->auth('test-1');- $app = $this->createApplication();- /** @var EntityManager $em */- $em = $app->getContainer()->getByClass(EntityManager::class);+ $this->authenticate('test-1');++ $em = $this->getEntityManager();$account = $em->createEntity(Account::ENTITY_TYPE, ['name' => '1']);$this->assertEquals($user1->getId(), $account->get('createdById'));- $this->auth('test-2');- $app = $this->createApplication();- /** @var EntityManager $em */- $em = $app->getContainer()->getByClass(EntityManager::class);+ $this->authenticate('test-2');+++ $em = $this->getEntityManager();$account = $em->getEntityById(Account::ENTITY_TYPE, $account->getId());$account->set('name', '2');@@ -61,10 +60,9 @@ class RepositoryTest extends \tests\integration\Core\BaseTestCase$this->assertEquals($user2->getId(), $account->get('modifiedById'));- $this->auth('test-1');- $app = $this->createApplication();- /** @var EntityManager $em */- $em = $app->getContainer()->getByClass(EntityManager::class);+ $this->authenticate('test-1');++ $em = $this->getEntityManager();$account = $em->getEntityById(Account::ENTITY_TYPE, $account->getId());$account->set('name', '2');diff --git a/tests/integration/Espo/ORM/SthCollectionTest.php b/tests/integration/Espo/ORM/SthCollectionTest.phpindex 15315de14d..418a348774 100644--- a/tests/integration/Espo/ORM/SthCollectionTest.php+++ b/tests/integration/Espo/ORM/SthCollectionTest.php@@ -30,7 +30,6 @@namespace tests\integration\Espo\ORM;use Espo\Modules\Crm\Entities\Account;-use Espo\ORM\EntityManager;use Espo\ORM\SthCollection;use tests\integration\Core\BaseTestCase;@@ -38,10 +37,7 @@ class SthCollectionTest extends BaseTestCase{public function test1(){- $app = $this->createApplication();-- /** @var EntityManager $em */- $em = $app->getContainer()->getByClass(EntityManager::class);+ $em = $this->getEntityManager();$em->createEntity('Account', ['name' => 'test-1',@@ -82,9 +78,7 @@ class SthCollectionTest extends BaseTestCasepublic function test2(): void{- $app = $this->createApplication();-- $em = $app->getContainer()->getByClass(EntityManager::class);+ $em = $this->getEntityManager();$em->createEntity('Account', ['name' => 'test-2',@@ -113,10 +107,7 @@ class SthCollectionTest extends BaseTestCasepublic function testFind1(){- $app = $this->createApplication();-- /** @var EntityManager $em */- $em = $app->getContainer()->getByClass(EntityManager::class);+ $em = $this->getEntityManager();$em->createEntity('Account', ['name' => 'test-1',@@ -152,10 +143,7 @@ class SthCollectionTest extends BaseTestCasepublic function testFindRelatedOneToMany(){- $app = $this->createApplication();-- /** @var EntityManager $em */- $em = $app->getContainer()->getByClass(EntityManager::class);+ $em = $this->getEntityManager();$account = $em->createEntity('Account', ['name' => 'test-1',@@ -198,9 +186,7 @@ class SthCollectionTest extends BaseTestCasepublic function testFindRelatedManyToMany(){- $app = $this->createApplication();-- $em = $app->getContainer()->get('entityManager');+ $em = $this->getEntityManager();$contact = $em->createEntity('Contact', ['lastName' => 'test-1',diff --git a/tests/integration/Espo/ORM/TransactionManagerTest.php b/tests/integration/Espo/ORM/TransactionManagerTest.phpindex 3630174255..18ce7de440 100644--- a/tests/integration/Espo/ORM/TransactionManagerTest.php+++ b/tests/integration/Espo/ORM/TransactionManagerTest.php@@ -29,13 +29,13 @@namespace tests\integration\Espo\ORM;-class TransactionManagerTest extends \tests\integration\Core\BaseTestCase+use tests\integration\Core\BaseTestCase;++class TransactionManagerTest extends BaseTestCase{public function testOne(){- $app = $this->createApplication();-- $em = $app->getContainer()->get('entityManager');+ $em = $this->getEntityManager();$tm = $em->getTransactionManager();@@ -51,16 +51,14 @@ class TransactionManagerTest extends \tests\integration\Core\BaseTestCase$tm->commit();- $account = $em->getEntity('Account', $id);+ $account = $em->getEntityById('Account', $id);$this->assertNotNull($account);}public function testRollbackOne(){- $app = $this->createApplication();-- $em = $app->getContainer()->get('entityManager');+ $em = $this->getEntityManager();$tm = $em->getTransactionManager();@@ -76,16 +74,14 @@ class TransactionManagerTest extends \tests\integration\Core\BaseTestCase$tm->rollback();- $account = $em->getEntity('Account', $id);+ $account = $em->getEntityById('Account', $id);$this->assertNull($account);}public function testRollbackNested(){- $app = $this->createApplication();-- $em = $app->getContainer()->get('entityManager');+ $em = $this->getEntityManager();$tm = $em->getTransactionManager();@@ -109,8 +105,8 @@ class TransactionManagerTest extends \tests\integration\Core\BaseTestCase$tm->commit();- $account1 = $em->getEntity('Account', $id1);- $account2 = $em->getEntity('Account', $id2);+ $account1 = $em->getEntityById('Account', $id1);+ $account2 = $em->getEntityById('Account', $id2);$this->assertNotNull($account1);$this->assertNull($account2);@@ -118,9 +114,7 @@ class TransactionManagerTest extends \tests\integration\Core\BaseTestCasepublic function testRunCommit(){- $app = $this->createApplication();-- $em = $app->getContainer()->get('entityManager');+ $em = $this->getEntityManager();$tm = $em->getTransactionManager();@@ -132,13 +126,13 @@ class TransactionManagerTest extends \tests\integration\Core\BaseTestCase$tm->run(function () use ($em, $id){- $account = $em->getEntity('Account', $id);+ $account = $em->getEntityById('Account', $id);$account->set('name', 'test-1');$em->saveEntity($account);});- $account = $em->getEntity('Account', $id);+ $account = $em->getEntityById('Account', $id);$this->assertNotNull($account);$this->assertEquals('test-1', $account->get('name'));@@ -146,9 +140,7 @@ class TransactionManagerTest extends \tests\integration\Core\BaseTestCasepublic function testRunRollback(){- $app = $this->createApplication();-- $em = $app->getContainer()->get('entityManager');+ $em = $this->getEntityManager();$tm = $em->getTransactionManager();@@ -168,9 +160,9 @@ class TransactionManagerTest extends \tests\integration\Core\BaseTestCasethrow new \Exception();});- } catch (\Exception $e) {}+ } catch (\Exception) {}- $account = $em->getEntity('Account', $id);+ $account = $em->getEntityById('Account', $id);$this->assertNotNull($account);$this->assertEquals('test', $account->get('name'));diff --git a/tests/integration/Espo/Portal/AclTest.php b/tests/integration/Espo/Portal/AclTest.phpindex 3e0a958330..1660f5f436 100644--- a/tests/integration/Espo/Portal/AclTest.php+++ b/tests/integration/Espo/Portal/AclTest.php@@ -35,8 +35,10 @@ use Espo\Core\Record\Service;use Espo\Core\Record\ServiceContainer;use Espo\Core\Select\SearchParams;use Espo\Modules\Crm\Entities\CaseObj;+use integration\Core\NoTransaction;use tests\integration\Core\BaseTestCase;+#[NoTransaction]class AclTest extends BaseTestCase{public function testAccessContact(): voiddiff --git a/tests/integration/Espo/Record/AssignmentTest.php b/tests/integration/Espo/Record/AssignmentTest.phpindex 2faadc12e1..c691f791bf 100644--- a/tests/integration/Espo/Record/AssignmentTest.php+++ b/tests/integration/Espo/Record/AssignmentTest.php@@ -58,8 +58,7 @@ class AssignmentTest extends BaseTestCase'assignmentPermission' => Table::LEVEL_NO,]);- $this->auth('test1');- $this->reCreateApplication();+ $this->authenticate('test1');/*** @noinspection PhpUnhandledExceptionInspectiondiff --git a/tests/integration/Espo/Record/CascadeRemovalTest.php b/tests/integration/Espo/Record/CascadeRemovalTest.phpindex 43829c6fcd..ec8894bedc 100644--- a/tests/integration/Espo/Record/CascadeRemovalTest.php+++ b/tests/integration/Espo/Record/CascadeRemovalTest.php@@ -37,6 +37,7 @@ use Espo\Modules\Crm\Entities\Task;use Espo\ORM\Defs\Params\RelationParam;use Espo\ORM\Name\Attribute;use Espo\ORM\Query\SelectBuilder;+use integration\Core\NoTransaction;use tests\integration\Core\BaseTestCase;class CascadeRemovalTest extends BaseTestCase@@ -44,6 +45,7 @@ class CascadeRemovalTest extends BaseTestCase/*** @noinspection PhpUnhandledExceptionInspection*/+ #[NoTransaction]public function testRemovalAndRestoral(): void{$metadata = $this->getMetadata();diff --git a/tests/integration/Espo/Record/EntityDuplicatorTest.php b/tests/integration/Espo/Record/EntityDuplicatorTest.phpindex 177fe61106..7c3daa36b0 100644--- a/tests/integration/Espo/Record/EntityDuplicatorTest.php+++ b/tests/integration/Espo/Record/EntityDuplicatorTest.php@@ -50,8 +50,7 @@ class EntityDuplicatorTest extends BaseTestCase'type' => User::TYPE_ADMIN,]);- $this->auth('test');- $this->reCreateApplication();+ $this->authenticate('test');$em = $this->getEntityManager();diff --git a/tests/integration/Espo/Record/FieldValidationTest.php b/tests/integration/Espo/Record/FieldValidationTest.phpindex 756f83431e..2cff82438b 100644--- a/tests/integration/Espo/Record/FieldValidationTest.php+++ b/tests/integration/Espo/Record/FieldValidationTest.php@@ -37,6 +37,7 @@ use Espo\Core\Record\CreateParams;use Espo\Core\Record\ServiceContainer;use Espo\Core\Record\UpdateParams;use Espo\Core\Utils\Config\ConfigWriter;+use Espo\Core\Utils\Metadata;use Espo\Entities\User;use Espo\Modules\Crm\Entities\Account;use Espo\Modules\Crm\Entities\Lead;@@ -48,7 +49,7 @@ class FieldValidationTest extends BaseTestCase{private function setFieldsDefs(Application $app, string $entityType, array $data){- $metadata = $app->getContainer()->get('metadata');+ $metadata = $app->getContainer()->getByClass(Metadata::class);$metadata->set('entityDefs', $entityType, ['fields' => $data,@@ -59,9 +60,7 @@ class FieldValidationTest extends BaseTestCasepublic function testRequiredVarchar1(){- $app = $this->createApplication();-- $this->setFieldsDefs($app, 'Account', [+ $this->setFieldsDefs($this->getApplication(), 'Account', ['name' => ['required' => true,],@@ -69,7 +68,7 @@ class FieldValidationTest extends BaseTestCase$this->expectException(BadRequest::class);- $app->getContainer()+ $this->getContainer()->getByClass(ServiceContainer::class)->get('Account')->create((object) [@@ -79,15 +78,13 @@ class FieldValidationTest extends BaseTestCasepublic function testUpdateRequiredVarchar1(){- $app = $this->createApplication();-- $this->setFieldsDefs($app, 'Account', [+ $this->setFieldsDefs($this->getApplication(), 'Account', ['name' => ['required' => true,],]);- $entity = $app->getContainer()+ $entity = $this->getContainer()->getByClass(ServiceContainer::class)->get('Account')->create(@@ -100,7 +97,7 @@ class FieldValidationTest extends BaseTestCase$this->expectException(BadRequest::class);- $app->getContainer()+ $this->getContainer()->getByClass(ServiceContainer::class)->get('Account')->update(@@ -114,9 +111,7 @@ class FieldValidationTest extends BaseTestCasepublic function testRequiredVarchar2(){- $app = $this->createApplication();-- $this->setFieldsDefs($app, 'Account', [+ $this->setFieldsDefs($this->getApplication(), 'Account', ['name' => ['required' => true,],@@ -124,7 +119,7 @@ class FieldValidationTest extends BaseTestCase$this->expectException(BadRequest::class);- $app->getContainer()+ $this->getContainer()->getByClass(ServiceContainer::class)->get('Account')->create(@@ -137,15 +132,13 @@ class FieldValidationTest extends BaseTestCasepublic function testRequiredVarchar3(){- $app = $this->createApplication();-- $this->setFieldsDefs($app, 'Account', [+ $this->setFieldsDefs($this->getApplication(), 'Account', ['name' => ['required' => true,],]);- $app->getContainer()+ $this->getContainer()->getByClass(ServiceContainer::class)->get('Account')->create((object) [@@ -157,9 +150,7 @@ class FieldValidationTest extends BaseTestCasepublic function testMaxLength1(){- $app = $this->createApplication();-- $this->setFieldsDefs($app, 'Account', [+ $this->setFieldsDefs($this->getApplication(), 'Account', ['name' => ['required' => true,'maxLength' => 5,@@ -168,7 +159,7 @@ class FieldValidationTest extends BaseTestCase$this->expectException(BadRequest::class);- $app->getContainer()+ $this->getContainer()->getByClass(ServiceContainer::class)->get('Account')->create((object) [@@ -178,16 +169,14 @@ class FieldValidationTest extends BaseTestCasepublic function testMaxLength2(){- $app = $this->createApplication();-- $this->setFieldsDefs($app, 'Account', [+ $this->setFieldsDefs($this->getApplication(), 'Account', ['name' => ['required' => true,'maxLength' => 5,]]);- $app->getContainer()+ $this->getContainer()->getByClass(ServiceContainer::class)->get('Account')->create((object) [@@ -199,9 +188,7 @@ class FieldValidationTest extends BaseTestCasepublic function testRequiredLink1(){- $app = $this->createApplication();-- $this->setFieldsDefs($app, 'Account', [+ $this->setFieldsDefs($this->getApplication(), 'Account', ['assignedUser' => ['required' => true,]@@ -209,7 +196,7 @@ class FieldValidationTest extends BaseTestCase$this->expectException(BadRequest::class);- $app->getContainer()+ $this->getContainer()->getByClass(ServiceContainer::class)->get('Account')->create((object) [@@ -241,15 +228,13 @@ class FieldValidationTest extends BaseTestCasepublic function testRequiredLink2(){- $app = $this->createApplication();-- $this->setFieldsDefs($app, 'Account', [+ $this->setFieldsDefs($this->getApplication(), 'Account', ['assignedUser' => ['required' => true,]]);- $app->getContainer()+ $this->getContainer()->getByClass(ServiceContainer::class)->get('Account')->create((object) [@@ -262,9 +247,7 @@ class FieldValidationTest extends BaseTestCasepublic function testRequiredLinkMultiple1(){- $app = $this->createApplication();-- $this->setFieldsDefs($app, 'Account', [+ $this->setFieldsDefs($this->getApplication(), 'Account', ['teams' => ['required' => true,]@@ -272,7 +255,7 @@ class FieldValidationTest extends BaseTestCase$this->expectException(BadRequest::class);- $app->getContainer()+ $this->getContainer()->getByClass(ServiceContainer::class)->get('Account')->create((object) [@@ -283,9 +266,7 @@ class FieldValidationTest extends BaseTestCasepublic function testRequiredCurrency1(){- $app = $this->createApplication();-- $this->setFieldsDefs($app, 'Lead', [+ $this->setFieldsDefs($this->getApplication(), 'Lead', ['opportunityAmount' => ['required' => true,]@@ -293,7 +274,7 @@ class FieldValidationTest extends BaseTestCase$this->expectException(BadRequest::class);- $app->getContainer()+ $this->getContainer()->getByClass(ServiceContainer::class)->get('Lead')->create((object) [@@ -304,15 +285,13 @@ class FieldValidationTest extends BaseTestCasepublic function testRequiredCurrency2(){- $app = $this->createApplication();-- $this->setFieldsDefs($app, 'Lead', [+ $this->setFieldsDefs($this->getApplication(), 'Lead', ['opportunityAmount' => ['required' => true,]]);- $app->getContainer()+ $this->getContainer()->getByClass(ServiceContainer::class)->get('Lead')->create((object) [@@ -326,15 +305,13 @@ class FieldValidationTest extends BaseTestCasepublic function testRequiredCurrency3(){- $app = $this->createApplication();-- $this->setFieldsDefs($app, 'Lead', [+ $this->setFieldsDefs($this->getApplication(), 'Lead', ['opportunityAmount' => ['required' => true,]]);- $app->getContainer()+ $this->getContainer()->getByClass(ServiceContainer::class)->get('Lead')->create((object) [@@ -348,20 +325,21 @@ class FieldValidationTest extends BaseTestCasepublic function testRequiredEnum1(){- $app = $this->createApplication();-- $this->setFieldsDefs($app, 'Lead', [+ $this->setFieldsDefs($this->getApplication(), 'Lead', ['status' => ['required' => true,'default' => null,]]);- $app = $this->createApplication();+ $this->getDataManager()->clearCache();+ $this->getDataManager()->rebuildMetadata();++ $this->authenticate(null);$this->expectException(BadRequest::class);- $app->getContainer()+ $this->getContainer()->getByClass(ServiceContainer::class)->get('Lead')->create((object) [@@ -371,9 +349,7 @@ class FieldValidationTest extends BaseTestCasepublic function testRequiredEnum2(){- $app = $this->createApplication();-- $this->setFieldsDefs($app, 'Lead', [+ $this->setFieldsDefs($this->getApplication(), 'Lead', ['status' => ['required' => true,]@@ -381,7 +357,7 @@ class FieldValidationTest extends BaseTestCase$this->expectException(BadRequest::class);- $app->getContainer()+ $this->getContainer()->getByClass(ServiceContainer::class)->get('Lead')->create((object) [@@ -392,15 +368,13 @@ class FieldValidationTest extends BaseTestCasepublic function testRequiredEnum3(){- $app = $this->createApplication();-- $this->setFieldsDefs($app, 'Lead', [+ $this->setFieldsDefs($this->getApplication(), 'Lead', ['status' => ['required' => true,]]);- $app->getContainer()+ $this->getContainer()->getByClass(ServiceContainer::class)->get('Lead')->create((object) [@@ -429,7 +403,7 @@ class FieldValidationTest extends BaseTestCasepublic function testSettings(){- $service = $this->getContainer()->get('injectableFactory')->create(SettingsService::class);+ $service = $this->getInjectableFactory()->create(SettingsService::class);$this->expectException(BadRequest::class);@@ -544,7 +518,8 @@ class FieldValidationTest extends BaseTestCase$metadata->save();- $this->reCreateApplication();+ $this->getDataManager()->clearCache();+ $this->getDataManager()->rebuildMetadata();$service = $this->getContainer()->getByClass(ServiceContainer::class)->getByClass(Account::class);@@ -724,25 +699,21 @@ class FieldValidationTest extends BaseTestCase*/public function testDependsOn(): void{- $app = $this->createApplication();-- $this->setApplication($app);-$em = $this->getEntityManager();$account = $em->createEntity('Account', ['name' => 'Test',]);- $this->setFieldsDefs($app, 'Account', [+ $this->setFieldsDefs($this->getApplication(), 'Account', ['description' => ['required' => true,'validationDependsOnFieldList' => ['name'],],]);- $this->setApplication($app);- $this->reCreateApplication();+ $this->getDataManager()->clearCache();+ $this->getDataManager()->rebuildMetadata();$this->expectException(BadRequest::class);diff --git a/tests/integration/Espo/Record/LinkTest.php b/tests/integration/Espo/Record/LinkTest.phpindex 9500b5610f..8defe3970d 100644--- a/tests/integration/Espo/Record/LinkTest.php+++ b/tests/integration/Espo/Record/LinkTest.php@@ -119,8 +119,7 @@ class LinkTest extends BaseTestCase'name' => '2',]);- $this->auth('test');- $this->reCreateApplication();+ $this->authenticate('test');$oppService = $this->getContainer()->getByClass(ServiceContainer::class)@@ -218,6 +217,7 @@ class LinkTest extends BaseTestCase]]]);+$metadata->save();$this->reCreateApplication();@@ -286,8 +286,7 @@ class LinkTest extends BaseTestCase'parentType' => Lead::ENTITY_TYPE,]);- $this->auth('test');- $this->reCreateApplication();+ $this->authenticate('test');$caseService = $this->getContainer()->getByClass(ServiceContainer::class)diff --git a/tests/integration/Espo/Record/ReadOnlyTest.php b/tests/integration/Espo/Record/ReadOnlyTest.phpindex 34d3934750..c076b95824 100644--- a/tests/integration/Espo/Record/ReadOnlyTest.php+++ b/tests/integration/Espo/Record/ReadOnlyTest.php@@ -34,8 +34,10 @@ use Espo\Core\Record\ServiceContainer;use Espo\Core\Record\UpdateParams;use Espo\Core\Utils\Metadata;use Espo\Modules\Crm\Entities\Account;+use integration\Core\NoTransaction;use tests\integration\Core\BaseTestCase;+#[NoTransaction]class ReadOnlyTest extends BaseTestCase{public function testReadOnly(): voiddiff --git a/tests/integration/Espo/Record/RestoreDeletedTest.php b/tests/integration/Espo/Record/RestoreDeletedTest.phpindex f2d6503481..6649c6de63 100644--- a/tests/integration/Espo/Record/RestoreDeletedTest.php+++ b/tests/integration/Espo/Record/RestoreDeletedTest.php@@ -33,14 +33,13 @@ use Espo\Core\Record\CreateParams;use Espo\Core\Record\ReadParams;use Espo\Core\Record\DeleteParams;use Espo\Core\Record\ServiceContainer;+use tests\integration\Core\BaseTestCase;-class RestoreDeletedTest extends \tests\integration\Core\BaseTestCase+class RestoreDeletedTest extends BaseTestCase{- public function testDeleted()+ public function testDeleted(): void{- $app = $this->createApplication();-- $service = $app->getContainer()+ $service = $this->getContainer()->getByClass(ServiceContainer::class)->get('Account');@@ -59,9 +58,7 @@ class RestoreDeletedTest extends \tests\integration\Core\BaseTestCasepublic function testRestoreDeleted(){- $app = $this->createApplication();-- $service = $app->getContainer()+ $service = $this->getContainer()->getByClass(ServiceContainer::class)->get('Account');diff --git a/tests/integration/Espo/Settings/AccessTest.php b/tests/integration/Espo/Settings/AccessTest.phpindex 0c6bbcc2c9..b1259d5ec7 100644--- a/tests/integration/Espo/Settings/AccessTest.php+++ b/tests/integration/Espo/Settings/AccessTest.php@@ -31,14 +31,13 @@ namespace tests\integration\Espo\Settings;use Espo\Entities\User;use Espo\Tools\App\SettingsService;+use tests\integration\Core\BaseTestCase;-class AccessTest extends \tests\integration\Core\BaseTestCase+class AccessTest extends BaseTestCase{public function testGlobalAccess(){- $app = $this->createApplication();-- $data = $app->getContainer()->get('injectableFactory')+ $data = $this->getInjectableFactory()->create(SettingsService::class)->getConfigData();@@ -62,11 +61,9 @@ class AccessTest extends \tests\integration\Core\BaseTestCase]]);- $this->auth('tester');-- $app = $this->createApplication();+ $this->authenticate('tester');- $data = $app->getContainer()->get('injectableFactory')+ $data = $this->getInjectableFactory()->create(SettingsService::class)->getConfigData();@@ -84,11 +81,9 @@ class AccessTest extends \tests\integration\Core\BaseTestCase]]);- $this->auth('tester');+ $this->authenticate('tester');- $app = $this->createApplication();-- $data = $app->getContainer()->get('injectableFactory')+ $data = $this->getInjectableFactory()->create(SettingsService::class)->getConfigData();@@ -102,12 +97,9 @@ class AccessTest extends \tests\integration\Core\BaseTestCase'type' => 'admin',]);- $this->auth('admin-tester');-- $app = $this->createApplication();+ $this->authenticate('admin-tester');- $data = $app->getContainer()- ->get('injectableFactory')+ $data = $this->getInjectableFactory()->create(SettingsService::class)->getConfigData();@@ -124,8 +116,7 @@ class AccessTest extends \tests\integration\Core\BaseTestCase'type' => User::TYPE_ADMIN,]);- $this->auth('admin-tester');- $this->setApplication($this->createApplication());+ $this->authenticate('admin-tester');$this->getInjectableFactory()->create(SettingsService::class)diff --git a/tests/integration/Espo/Stream/AuditTest.php b/tests/integration/Espo/Stream/AuditTest.phpindex 0aa8d7cfd3..c686806ddd 100644--- a/tests/integration/Espo/Stream/AuditTest.php+++ b/tests/integration/Espo/Stream/AuditTest.php@@ -83,8 +83,6 @@ class AuditTest extends BaseTestCase]);$this->getMetadata()->save();- $this->reCreateApplication();-$service = $this->getContainer()->getByClass(ServiceContainer::class)->getByClass(KnowledgeBaseArticle::class);@@ -115,8 +113,7 @@ class AuditTest extends BaseTestCase$searchParams = SearchParams::create();- $this->auth('test1');- $this->reCreateApplication();+ $this->authenticate('test1');$service = $this->getInjectableFactory()->create(RecordService::class);/** @noinspection PhpUnhandledExceptionInspection */@@ -124,8 +121,7 @@ class AuditTest extends BaseTestCase$this->assertCount(1, $recordCollection->getCollection()->getValueMapList());- $this->auth('test2');- $this->reCreateApplication();+ $this->authenticate('test2');$isThrown = false;@@ -139,8 +135,7 @@ class AuditTest extends BaseTestCase$this->assertTrue($isThrown);- $this->auth('test3');- $this->reCreateApplication();+ $this->authenticate('test3');$isThrown = false;diff --git a/tests/integration/Espo/Stream/ReactionsTest.php b/tests/integration/Espo/Stream/ReactionsTest.phpindex f385e4e6dd..6ab32b9b42 100644--- a/tests/integration/Espo/Stream/ReactionsTest.php+++ b/tests/integration/Espo/Stream/ReactionsTest.php@@ -78,8 +78,7 @@ class ReactionsTest extends BaseTestCase->setPost('Test');$em->saveEntity($note2);- $this->auth('test');- $this->reCreateApplication();+ $this->authenticate('test');// Has access.diff --git a/tests/integration/Espo/Tools/App/LanguageTest.php b/tests/integration/Espo/Tools/App/LanguageTest.phpindex 9b65a73f8d..dd31bb364d 100644--- a/tests/integration/Espo/Tools/App/LanguageTest.php+++ b/tests/integration/Espo/Tools/App/LanguageTest.php@@ -49,8 +49,7 @@ class LanguageTest extends BaseTestCase]]);- $this->auth('tester');- $this->setApplication($this->createApplication());+ $this->authenticate('tester');$data = $this->getInjectableFactory()->create(LanguageService::class)->getDataForFrontend();diff --git a/tests/integration/Espo/Tools/App/MetadataTest.php b/tests/integration/Espo/Tools/App/MetadataTest.phpindex 14e3a63b00..64a3bc4692 100644--- a/tests/integration/Espo/Tools/App/MetadataTest.php+++ b/tests/integration/Espo/Tools/App/MetadataTest.php@@ -49,8 +49,6 @@ class MetadataTest extends BaseTestCase$metadata->save();- $this->reCreateApplication();-$this->createUser('tester', ['data' => ['Lead' => false,@@ -64,8 +62,7 @@ class MetadataTest extends BaseTestCase]]);- $this->auth('tester');- $this->setApplication($this->createApplication());+ $this->authenticate('tester');$data = $this->getInjectableFactory()->create(MetadataService::class)->getDataForFrontend();diff --git a/tests/integration/Espo/Tools/Pipeline/PipelineTest.php b/tests/integration/Espo/Tools/Pipeline/PipelineTest.phpindex f16f49c7f9..3eec6ea577 100644--- a/tests/integration/Espo/Tools/Pipeline/PipelineTest.php+++ b/tests/integration/Espo/Tools/Pipeline/PipelineTest.php@@ -44,6 +44,7 @@ use Espo\Entities\Role;use Espo\Entities\Team;use Espo\Modules\Crm\Entities\Opportunity;use Espo\Tools\EntityManager\EntityManager as EntityManagerTool;+use integration\Core\NoTransaction;use tests\integration\Core\BaseTestCase;class PipelineTest extends BaseTestCase@@ -51,6 +52,7 @@ class PipelineTest extends BaseTestCase/*** @noinspection PhpUnhandledExceptionInspection*/+ #[NoTransaction]public function testPipeline1(): void{$this->initPipeline(Opportunity::ENTITY_TYPE);diff --git a/tests/integration/Espo/User/AccessTest.php b/tests/integration/Espo/User/AccessTest.phpindex 8c4850b3af..b01431797a 100644--- a/tests/integration/Espo/User/AccessTest.php+++ b/tests/integration/Espo/User/AccessTest.php@@ -48,8 +48,7 @@ class AccessTest extends BaseTestCaseUser::ATTR_TYPE => User::TYPE_ADMIN,]);- $this->auth('admin-test');- $this->reCreateApplication();+ $this->authenticate('admin-test');$service = $this->getContainer()->getByClass(ServiceContainer::class)diff --git a/tests/integration/Espo/User/AclAdminTest.php b/tests/integration/Espo/User/AclAdminTest.phpindex 5491b99df8..b2a2d465bb 100644--- a/tests/integration/Espo/User/AclAdminTest.php+++ b/tests/integration/Espo/User/AclAdminTest.php@@ -31,8 +31,9 @@ namespace tests\integration\Espo\User;use Espo\Core\Api\ControllerActionProcessor;use Espo\Core\Api\ResponseWrapper;+use tests\integration\Core\BaseTestCase;-class AclAdminTest extends \tests\integration\Core\BaseTestCase+class AclAdminTest extends BaseTestCase{public function testCreateUser(){@@ -41,12 +42,9 @@ class AclAdminTest extends \tests\integration\Core\BaseTestCase'type' => 'admin',]);- $this->auth('admin-test');+ $this->authenticate('admin-test');- $app = $this->createApplication();-- $processor = $app->getContainer()- ->get('injectableFactory')+ $processor = $this->getInjectableFactory()->create(ControllerActionProcessor::class);$data = [@@ -78,13 +76,9 @@ class AclAdminTest extends \tests\integration\Core\BaseTestCase'type' => 'admin',]);- $this->auth('admin-test');-- $app = $this->createApplication();+ $this->authenticate('admin-test');- $processor = $app->getContainer()- ->get('injectableFactory')- ->create(ControllerActionProcessor::class);+ $processor = $this->getInjectableFactory()->create(ControllerActionProcessor::class);$data = ['name' => 'test',@@ -113,13 +107,9 @@ class AclAdminTest extends \tests\integration\Core\BaseTestCase'type' => 'admin',]);- $this->auth('admin-test');+ $this->authenticate('admin-test');- $app = $this->createApplication();-- $processor = $app->getContainer()- ->get('injectableFactory')- ->create(ControllerActionProcessor::class);+ $processor = $this->getInjectableFactory()->create(ControllerActionProcessor::class);$data = ['name' => 'test',@@ -148,13 +138,9 @@ class AclAdminTest extends \tests\integration\Core\BaseTestCase'type' => 'admin',]);- $this->auth('admin-test');-- $app = $this->createApplication();+ $this->authenticate('admin-test');- $processor = $app->getContainer()- ->get('injectableFactory')- ->create(ControllerActionProcessor::class);+ $processor = $this->getInjectableFactory()->create(ControllerActionProcessor::class);$data = ['name' => 'test',diff --git a/tests/integration/Espo/User/AclTest.php b/tests/integration/Espo/User/AclTest.phpindex 8869cd36a5..aac4d0d9e0 100644--- a/tests/integration/Espo/User/AclTest.php+++ b/tests/integration/Espo/User/AclTest.php@@ -33,6 +33,7 @@ use Espo\Core\Acl\Table;use Espo\Core\AclManager;use Espo\Core\Api\ControllerActionProcessor;use Espo\Core\Api\ResponseWrapper;+use Espo\Core\Application;use Espo\Core\DataManager;use Espo\Core\Exceptions\BadRequest;use Espo\Core\Field\Date;@@ -42,10 +43,10 @@ use Espo\Core\Record\UpdateParams;use Espo\Core\Select\SearchParams;use Espo\Core\Select\SelectBuilderFactory;use Espo\Core\Select\Where\Item as WhereItem;-use Espo\Core\Exceptions\Forbidden;-use Espo\Core\Utils\Config\ConfigWriter;+use Espo\Core\Utils\Metadata;+use Espo\Entities\Portal;use Espo\Entities\Role;use Espo\Entities\Team;use Espo\Entities\User;@@ -58,17 +59,39 @@ use Espo\Modules\Crm\Entities\Opportunity;use Espo\Modules\Crm\Entities\Task;use Espo\Tools\EntityManager\EntityManager as EntityManagerTool;use Exception;+use integration\Core\NoTransaction;+use tests\integration\Core\BaseTestCase;-class AclTest extends \tests\integration\Core\BaseTestCase+class AclTest extends BaseTestCase{- protected ?string $dataFile = 'User/Login.php';-- protected ?string $userName = 'admin';protected ?string $password = '1';- private function setFieldsDefs($app, $entityType, $data)+ protected function setUp(): void{- $metadata = $app->getContainer()->get('metadata');+ parent::setUp();++ $this->createUser([+ 'type' => User::TYPE_ADMIN,+ 'userName' => 'admin',+ 'lastName' => 'Admin',+ 'password' => $this->password,+ ]);++ $portal = $this->getEntityManager()->getRDBRepositoryByClass(Portal::class)->getNew();+ $portal->setMultiple([+ 'id' => 'testPortalId',+ 'isActive' => true,+ 'name' => 'Test portal',+ 'customId' => 'test',+ ]);+ $this->getEntityManager()->saveEntity($portal);++ $this->authenticate('admin');+ }++ private function setFieldsDefs(Application $app, $entityType, $data)+ {+ $metadata = $app->getContainer()->getByClass(Metadata::class);$metadata->set('entityDefs', $entityType, ['fields' => $data@@ -77,7 +100,7 @@ class AclTest extends \tests\integration\Core\BaseTestCase$metadata->save();}- public function testUserAccess0()+ public function testUserAccess0(): void{$this->expectException(Forbidden::class);@@ -105,11 +128,9 @@ class AclTest extends \tests\integration\Core\BaseTestCase]]);- $this->auth('tester');-- $app = $this->createApplication();+ $this->authenticate('tester');- $processor = $app->getContainer()->get('injectableFactory')->create(ControllerActionProcessor::class);+ $processor = $this->getInjectableFactory()->create(ControllerActionProcessor::class);$request = $this->createRequest('POST',@@ -121,11 +142,11 @@ class AclTest extends \tests\integration\Core\BaseTestCase$processor->process('Account', 'create', $request, $this->createResponse());}- public function testPortalUserAccess()+ public function testPortalUserAccess(): void{$this->expectException(Forbidden::class);- $newUser = $this->createUser([+ $this->createUser(['userName' => 'tester','lastName' => 'tester','portalsIds' => [@@ -152,19 +173,19 @@ class AclTest extends \tests\integration\Core\BaseTestCase$app = $this->createApplication();- $processor = $app->getContainer()->get('injectableFactory')->create(ControllerActionProcessor::class);+ $processor = $app->getInjectableFactory()->create(ControllerActionProcessor::class);- $data = json_decode('{"name":"Test Account"}');+ json_decode('{"name":"Test Account"}');$request = $this->createRequest('POST', [], ['Content-Type' => 'application/json'], '{"name":"Test Account"}');$processor->process('Account', 'create', $request, $this->createResponse());}- public function testUserAccessEditOwn1()+ public function testUserAccessEditOwn1(): void{$user1 = $this->createUser('test-1', [- "id" => "test-1",+ 'id' => "test-1",'data' => ['User' => ['read' => 'all',@@ -175,11 +196,10 @@ class AclTest extends \tests\integration\Core\BaseTestCase$user2 = $this->createUser('test-2', []);- $this->auth('test-1');- $app = $this->createApplication();+ $this->authenticate('test-1');- $processor = $app->getContainer()->get('injectableFactory')->create(ControllerActionProcessor::class);+ $processor = $this->getInjectableFactory()->create(ControllerActionProcessor::class);$params = ['id' => $user1->getId(),@@ -238,8 +258,7 @@ class AclTest extends \tests\integration\Core\BaseTestCase$processor->process('User', 'update', $request, $this->createResponse());- $service = $app->getContainer()- ->getByClass(ServiceContainer::class)+ $service = $this->getContainer()->getByClass(ServiceContainer::class)->getByClass(User::class);$resultData = $service->update($user1->getId(), $data, UpdateParams::create());@@ -252,7 +271,7 @@ class AclTest extends \tests\integration\Core\BaseTestCase);}- public function testUserAccessEditOwn2()+ public function testUserAccessEditOwn2(): void{$user1 = $this->createUser('test-1', ["id" => "test-1",@@ -264,11 +283,10 @@ class AclTest extends \tests\integration\Core\BaseTestCase]]);- $this->auth('test-1');+ $this->authenticate('test-1');- $app = $this->createApplication();- $processor = $app->getContainer()->get('injectableFactory')->create(ControllerActionProcessor::class);+ $processor = $this->getInjectableFactory()->create(ControllerActionProcessor::class);$params = ['id' => $user1->getId()@@ -290,20 +308,18 @@ class AclTest extends \tests\integration\Core\BaseTestCasetry {$processor->process('User', 'update', $request, $response);- } catch (Exception $e) {};+ } catch (Exception) {};}- protected function prepareTestUser()+ protected function prepareTestUser(): void{- $app = $this->createApplication();+ $entityManager = $this->getEntityManager();- $entityManager = $app->getContainer()->get('entityManager');-- $team = $entityManager->getEntity('Team');+ $team = $entityManager->getNewEntity('Team');$team->set('id', 'testTeamId');$entityManager->saveEntity($team);- $team = $entityManager->getEntity('Team');+ $team = $entityManager->getNewEntity('Team');$team->set('id', 'testOtherTeamId');$entityManager->saveEntity($team);@@ -347,46 +363,42 @@ class AclTest extends \tests\integration\Core\BaseTestCase);}- public function testUserAccessCreateNo1()+ public function testUserAccessCreateNo1(): void{$this->prepareTestUser();- $this->auth('test');- $app = $this->createApplication();+ $this->authenticate('test');$this->expectException(Forbidden::class);- $service = $app->getContainer()+ $service = $this->getContainer()->getByClass(ServiceContainer::class)->getByClass(Account::class);$service->create((object) ['name' => 'Test'], CreateParams::create());}- public function testUserAccessCreateNo2()+ public function testUserAccessCreateNo2(): void{$this->prepareTestUser();- $this->auth('test');- $app = $this->createApplication();+ $this->authenticate('test');$this->expectException(Forbidden::class);- $service = $app->getContainer()+ $service = $this->getContainer()->getByClass(ServiceContainer::class)->getByClass(Lead::class);$service->create((object) ['lastName' => 'Test'], CreateParams::create());}- public function testUserAccessAclStrictCreateNo()+ public function testUserAccessAclStrictCreateNo(): void{$this->prepareTestUser();-- $this->auth('test');- $app = $this->createApplication(true);+ $this->authenticate('test');$this->expectException(Forbidden::class);- $service = $app->getContainer()+ $service = $this->getContainer()->getByClass(ServiceContainer::class)->getByClass(CaseObj::class);@@ -396,11 +408,9 @@ class AclTest extends \tests\integration\Core\BaseTestCasepublic function testUserAccessAclStrictCreateYes(){$this->prepareTestUser();+ $this->authenticate('test');- $this->auth('test');- $app = $this->createApplication(true);-- $service = $app->getContainer()+ $service = $this->getContainer()->getByClass(ServiceContainer::class)->getByClass(Meeting::class);@@ -414,21 +424,20 @@ class AclTest extends \tests\integration\Core\BaseTestCase$this->assertNotNull($e);}- public function testUserAccessCreateAssignedPermissionNo1()+ #[NoTransaction]+ public function testUserAccessCreateAssignedPermissionNo1(): void{$this->prepareTestUser();- $app = $this->createApplication();- $this->setFieldsDefs($app, 'Meeting', [+ $this->setFieldsDefs($this->getApplication(), 'Meeting', ['assignedUser' => ['required' => false]]);- $this->auth('test');- $app = $this->createApplication();+ $this->authenticate('test');- $service = $app->getContainer()+ $service = $this->getContainer()->getByClass(ServiceContainer::class)->getByClass(Meeting::class);@@ -445,10 +454,9 @@ class AclTest extends \tests\integration\Core\BaseTestCase{$this->prepareTestUser();- $this->auth('test');- $app = $this->createApplication();+ $this->authenticate('test');- $service = $app->getContainer()+ $service = $this->getContainer()->getByClass(ServiceContainer::class)->getByClass(Meeting::class);@@ -467,10 +475,9 @@ class AclTest extends \tests\integration\Core\BaseTestCase{$this->prepareTestUser();- $this->auth('test');- $app = $this->createApplication();+ $this->authenticate('test');- $service = $app->getContainer()+ $service = $this->getContainer()->getByClass(ServiceContainer::class)->getByClass(Meeting::class);@@ -489,18 +496,17 @@ class AclTest extends \tests\integration\Core\BaseTestCase{$this->prepareTestUser();- $this->auth('test');- $app = $this->createApplication();+ $this->authenticate('test');- $entityManager = $app->getContainer()->get('entityManager');+ $entityManager = $this->getEntityManager();- $lead = $entityManager->getEntity('Lead');+ $lead = $entityManager->getNewEntity('Lead');$lead->set(['id' => 'testLeadId']);$entityManager->saveEntity($lead);- $service = $app->getContainer()+ $service = $this->getContainer()->getByClass(ServiceContainer::class)->getByClass(Lead::class);@@ -513,12 +519,11 @@ class AclTest extends \tests\integration\Core\BaseTestCase{$this->prepareTestUser();- $this->auth('test');- $app = $this->createApplication();+ $this->authenticate('test');- $entityManager = $app->getContainer()->get('entityManager');+ $entityManager = $this->getEntityManager();- $meeting = $entityManager->getEntity('Meeting');+ $meeting = $entityManager->getNewEntity('Meeting');$meeting->set(['id' => 'testMeetingId','teamsIds' => ['testOtherTeamId']@@ -526,7 +531,7 @@ class AclTest extends \tests\integration\Core\BaseTestCase$entityManager->saveEntity($meeting);- $service = $app->getContainer()+ $service = $this->getContainer()->getByClass(ServiceContainer::class)->getByClass(Meeting::class);@@ -539,12 +544,11 @@ class AclTest extends \tests\integration\Core\BaseTestCase{$this->prepareTestUser();- $this->auth('test');- $app = $this->createApplication();+ $this->authenticate('test');- $entityManager = $app->getContainer()->get('entityManager');+ $entityManager = $this->getEntityManager();- $lead = $entityManager->getEntity('Lead');+ $lead = $entityManager->getNewEntity('Lead');$lead->set(['id' => 'testLeadId','assignedUserId' => 'testUserId'@@ -552,7 +556,7 @@ class AclTest extends \tests\integration\Core\BaseTestCase$entityManager->saveEntity($lead);- $service = $app->getContainer()+ $service = $this->getContainer()->getByClass(ServiceContainer::class)->getByClass(Lead::class);@@ -565,12 +569,11 @@ class AclTest extends \tests\integration\Core\BaseTestCase{$this->prepareTestUser();- $this->auth('test');- $app = $this->createApplication();+ $this->authenticate('test');- $entityManager = $app->getContainer()->get('entityManager');+ $entityManager = $this->getEntityManager();- $meeting = $entityManager->getEntity('Meeting');+ $meeting = $entityManager->getNewEntity('Meeting');$meeting->set(['id' => 'testMeetingId','teamsIds' => ['testTeamId']@@ -578,7 +581,7 @@ class AclTest extends \tests\integration\Core\BaseTestCase$entityManager->saveEntity($meeting);- $service = $app->getContainer()+ $service = $this->getContainer()->getByClass(ServiceContainer::class)->getByClass(Meeting::class);@@ -587,21 +590,20 @@ class AclTest extends \tests\integration\Core\BaseTestCase$this->assertNotNull($e);}- public function testUserAccessEditNo1()+ public function testUserAccessEditNo1(): void{$this->prepareTestUser();- $this->auth('test');- $app = $this->createApplication();+ $this->authenticate('test');- $entityManager = $app->getContainer()->get('entityManager');+ $entityManager = $this->getEntityManager();$entityManager->createEntity('Meeting', ['id' => 'testMeetingId','teamsIds' => ['testTeamId']]);- $service = $app->getContainer()+ $service = $this->getContainer()->getByClass(ServiceContainer::class)->getByClass(Meeting::class);@@ -610,15 +612,13 @@ class AclTest extends \tests\integration\Core\BaseTestCase$service->update('testMeetingId', (object) [], UpdateParams::create());}- public function testUserAccessSearchByInternalField()+ public function testUserAccessSearchByInternalField(): void{$this->prepareTestUser();- $this->auth('test');-- $app = $this->createApplication();+ $this->authenticate('test');- $service = $app->getContainer()+ $service = $this->getContainer()->getByClass(ServiceContainer::class)->getByClass(User::class);@@ -641,9 +641,8 @@ class AclTest extends \tests\integration\Core\BaseTestCase$userId = 'testUserId';$this->prepareTestUser();- $this->auth('test');- $this->setApplication($this->createApplication());+ $this->authenticate('test');$contact1 = $this->getEntityManager()->createEntity(Contact::ENTITY_TYPE, ['lastName' => 'Contact 1',@@ -655,7 +654,6 @@ class AclTest extends \tests\integration\Core\BaseTestCase'lastName' => 'Contact 2',]);- $recordServiceContainer = $this->getContainer()->get('recordServiceContainer');$service = $this->getContainer()->getByClass(ServiceContainer::class)->getByClass(Opportunity::class);@@ -891,8 +889,8 @@ class AclTest extends \tests\integration\Core\BaseTestCase$this->prepareTestUser();- $this->auth('test');- $this->reCreateApplication();+ $this->authenticate('test');+$user = $this->getContainer()->getByClass(User::class);diff --git a/tests/integration/Espo/User/CreateUserTest.php b/tests/integration/Espo/User/CreateUserTest.phpindex 8fa52ea1cb..1c8ebd71de 100644--- a/tests/integration/Espo/User/CreateUserTest.php+++ b/tests/integration/Espo/User/CreateUserTest.php@@ -29,14 +29,23 @@namespace tests\integration\Espo\User;+use Espo\Entities\User;use tests\integration\Core\BaseTestCase;class CreateUserTest extends BaseTestCase{- protected ?string $dataFile = 'User/Login.php';+ protected function setUp(): void+ {+ parent::setUp();++ $this->createUser([+ 'type' => User::TYPE_ADMIN,+ 'userName' => 'admin',+ 'lastName' => 'Admin',+ ]);- protected ?string $userName = 'admin';- protected ?string $password = '1';+ $this->authenticate('admin');+ }public function testCreateUser(){diff --git a/tests/integration/Espo/User/LoginTest.php b/tests/integration/Espo/User/LoginTest.phpindex 5198645ff0..d9994c2644 100644--- a/tests/integration/Espo/User/LoginTest.php+++ b/tests/integration/Espo/User/LoginTest.php@@ -29,21 +29,39 @@namespace tests\integration\Espo\User;-class LoginTest extends \tests\integration\Core\BaseTestCase+use Espo\Entities\User;+use integration\Core\NoTransaction;+use tests\integration\Core\BaseTestCase;++class LoginTest extends BaseTestCase{- protected ?string $userName = 'admin';protected ?string $password = '1';- public function testLogin()+ protected function setUp(): void{- $user = $this->getContainer()->get('user');+ parent::setUp();++ $this->createUser([+ 'type' => User::TYPE_ADMIN,+ 'userName' => 'admin',+ 'lastName' => 'Admin',+ ]);++ $this->authenticate('admin');+ }++ public function testLogin(): void+ {+ $this->authenticate('admin');++ $user = $this->getContainer()->getByClass(User::class);- $this->assertEquals('Espo\\Entities\\User', get_class($user));- $this->assertEquals('1', $user->get('id'));- $this->assertEquals('admin', $user->get('userName'));+ $this->assertInstanceOf(User::class, $user);+ $this->assertEquals('admin', $user->getUserName());}- public function testWrongCredentials()+ #[NoTransaction]+ public function testWrongCredentials(): void{$this->auth('admin', 'wrong-password');diff --git a/tests/integration/Espo/Webhook/AclTest.php b/tests/integration/Espo/Webhook/AclTest.phpindex 83173ff201..533226f093 100644--- a/tests/integration/Espo/Webhook/AclTest.php+++ b/tests/integration/Espo/Webhook/AclTest.php@@ -32,17 +32,16 @@ namespace tests\integration\Espo\Webhook;use Espo\Core\Api\ControllerActionProcessor;use Espo\Core\Api\ResponseWrapper;use Espo\Core\Utils\Config\ConfigWriter;-use Espo\ORM\EntityManager;use Espo\Core\Exceptions\Forbidden;+use tests\integration\Core\BaseTestCase;-class AclTest extends \tests\integration\Core\BaseTestCase+class AclTest extends BaseTestCase{- public function testRegularUserNoAccess()+ public function testRegularUserNoAccess(): void{$this->createUser(['userName' => 'test',- 'password' => '1',],['data' => [@@ -52,11 +51,9 @@ class AclTest extends \tests\integration\Core\BaseTestCase]);- $this->auth('test', '1');+ $this->authenticate('test');- $app = $this->createApplication();-- $processor = $app->getContainer()->get('injectableFactory')->create(ControllerActionProcessor::class);+ $processor = $this->getInjectableFactory()->create(ControllerActionProcessor::class);$this->expectException(Forbidden::class);@@ -82,6 +79,8 @@ class AclTest extends \tests\integration\Core\BaseTestCase]);+ $this->getDataManager()->clearCache();+$request = $this->createRequest('POST',[],@@ -92,11 +91,9 @@ class AclTest extends \tests\integration\Core\BaseTestCase'{"event":"Account.create", "url": "https://test.com"}');- $this->auth(null, null, null, 'ApiKey', $request);+ $this->authenticate(method: 'ApiKey', request: $request);- $app = $this->createApplication();-- $processor = $app->getContainer()->get('injectableFactory')->create(ControllerActionProcessor::class);+ $processor = $this->getInjectableFactory()->create(ControllerActionProcessor::class);$this->expectException(Forbidden::class);@@ -120,6 +117,8 @@ class AclTest extends \tests\integration\Core\BaseTestCase]);+ $this->getDataManager()->clearCache();+$request = $this->createRequest('POST',[],@@ -130,11 +129,9 @@ class AclTest extends \tests\integration\Core\BaseTestCase'{"event":"Account.create", "url": "https://test.com"}');- $this->auth(null, null, null, 'ApiKey', $request);+ $this->authenticate(method: 'ApiKey', request: $request);- $app = $this->createApplication();-- $processor = $app->getContainer()->get('injectableFactory')->create(ControllerActionProcessor::class);+ $processor = $this->getInjectableFactory()->create(ControllerActionProcessor::class);$this->expectException(Forbidden::class);@@ -172,11 +169,9 @@ class AclTest extends \tests\integration\Core\BaseTestCase'{"event":"Account.create", "url": "https://test.com"}');- $this->auth(null, null, null, 'ApiKey', $request);-- $app = $this->createApplication();+ $this->authenticate(method: 'ApiKey', request: $request);- $processor = $app->getContainer()->get('injectableFactory')->create(ControllerActionProcessor::class);+ $processor = $this->getInjectableFactory()->create(ControllerActionProcessor::class);$response = $this->createMock(ResponseWrapper::class);@@ -204,8 +199,7 @@ class AclTest extends \tests\integration\Core\BaseTestCase]);- /* @var $em EntityManager */- $em = $this->getContainer()->get('entityManager');+ $em = $this->getEntityManager();$webhook = $em->createEntity('Webhook', ['event' => 'Account.create',@@ -226,19 +220,17 @@ class AclTest extends \tests\integration\Core\BaseTestCase]);- $this->auth(null, null, null, 'ApiKey', $request);-- $app = $this->createApplication();+ $this->authenticate(method: 'ApiKey', request: $request);- $em = $app->getContainer()->get('entityManager');+ $em = $this->getEntityManager();$response = $this->createMock(ResponseWrapper::class);- $processor = $app->getContainer()->get('injectableFactory')->create(ControllerActionProcessor::class);+ $processor = $this->getInjectableFactory()->create(ControllerActionProcessor::class);$processor->process('Webhook', 'delete', $request, $response);- $fetchedWebhook = $em->getEntity('Webhook', $webhook->getId());+ $fetchedWebhook = $em->getEntityById('Webhook', $webhook->getId());$this->assertNull($fetchedWebhook);}diff --git a/tests/integration/Espo/Webhook/ProcessingTest.php b/tests/integration/Espo/Webhook/ProcessingTest.phpindex 8d44816210..284efd77f7 100644--- a/tests/integration/Espo/Webhook/ProcessingTest.php+++ b/tests/integration/Espo/Webhook/ProcessingTest.php@@ -74,9 +74,11 @@ class ProcessingTest extends BaseTestCase'skipOwn' => true,]);- $app = $this->createApplication();+ $this->getDataManager()->clearCache();- $em = $app->getContainer()->getByClass(EntityManager::class);+ $this->authenticate(null);++ $em = $this->getEntityManager();$account1 = $em->createEntity(Account::ENTITY_TYPE, ['name' => 'test1',@@ -119,8 +121,7 @@ class ProcessingTest extends BaseTestCase$sender = $this->createMock(Sender::class);- /** @var Queue $queue */- $queue = $app->getContainer()+ $queue = $this->getContainer()->getByClass(InjectableFactory::class)->createWith(Queue::class, ['sender' => $sender,@@ -185,10 +186,11 @@ class ProcessingTest extends BaseTestCase]);- $app = $this->createApplication();+ $this->getDataManager()->clearCache();++ $this->authenticate(null);- /* @var $em EntityManager */- $em = $app->getContainer()->get('entityManager');+ $em = $this->getEntityManager();$account1 = $em->createEntity(Account::ENTITY_TYPE, ['name' => 'test1',@@ -207,18 +209,18 @@ class ProcessingTest extends BaseTestCase'skipOwn' => true,]);- $app = $this->createApplication();+ $this->getDataManager()->clearCache();- $em = $app->getContainer()->get('entityManager');+ $this->authenticate(null);++ $em = $this->getEntityManager();$em->removeEntity($account1);$em->removeEntity($account2, [SaveOption::MODIFIED_BY_ID => $user->getId()]);$sender = $this->createMock(Sender::class);- /* @var $queue Queue */- $queue = $app->getContainer()- ->get('injectableFactory')+ $queue = $this->getInjectableFactory()->createWith(Queue::class, ['sender' => $sender,]);@@ -276,10 +278,8 @@ class ProcessingTest extends BaseTestCase]);- $app = $this->createApplication();- /* @var $em EntityManager */- $em = $app->getContainer()->get('entityManager');+ $em = $this->getEntityManager();$account1 = $em->createEntity(Account::ENTITY_TYPE, ['name' => 'test1',@@ -292,9 +292,11 @@ class ProcessingTest extends BaseTestCase'url' => 'https://test.com',]);- $app = $this->createApplication();+ $this->getDataManager()->clearCache();++ $this->authenticate(null);- $em = $app->getContainer()->get('entityManager');+ $em = $this->getEntityManager();$account1->set('name', 'test-1-changed');@@ -309,9 +311,7 @@ class ProcessingTest extends BaseTestCase$sender = $this->createMock(Sender::class);- /* @var $queue Queue */- $queue = $app->getContainer()- ->get('injectableFactory')+ $queue = $this->getInjectableFactory()->createWith(Queue::class, ['sender' => $sender,]);