Skip to content

EspoCRM – Open Source CRM Application

Integration tests optimization. Reuse.

Yurii017a8d3c381b
diff --git a/application/Espo/Core/Application/ApplicationParams.php b/application/Espo/Core/Application/ApplicationParams.php
index 486c80eee4..98c263c4b8 100644
--- a/application/Espo/Core/Application/ApplicationParams.php
+++ b/application/Espo/Core/Application/ApplicationParams.php
@@ -37,11 +37,15 @@ use Espo\Core\Binding\BindingProcessor;
readonly class ApplicationParams
{
/**
+ * Important. Use named parameters. Backward compatibility for parameter order is not guaranteed.
+ *
* @param bool $noErrorHandler Disable error handling for tests.
* @param ?BindingProcessor $binding Additional DI binding for integration tests. Since v9.3.
+ * @param ?array<string, object> $services Instances of services. Since 10.0.
*/
public function __construct(
public bool $noErrorHandler = false,
public ?BindingProcessor $binding = null,
+ public ?array $services = null,
) {}
}
diff --git a/application/Espo/Core/Container/ContainerBuilder.php b/application/Espo/Core/Container/ContainerBuilder.php
index 7d623c7cc1..c92be133d5 100644
--- a/application/Espo/Core/Container/ContainerBuilder.php
+++ b/application/Espo/Core/Container/ContainerBuilder.php
@@ -206,6 +206,10 @@ class ContainerBuilder
$this->services['module'] = $module;
$this->services['systemConfig'] = $systemConfig;
+ if ($this->params?->services) {
+ $this->services = array_merge($this->services, $this->params->services);
+ }
+
$bindingLoader = $this->bindingLoader ?? (
new EspoBindingLoader(
module: $module,
diff --git a/tests/integration/Core/BaseTestCase.php b/tests/integration/Core/BaseTestCase.php
index f31364de94..c1b971bea5 100644
--- a/tests/integration/Core/BaseTestCase.php
+++ b/tests/integration/Core/BaseTestCase.php
@@ -90,9 +90,10 @@ abstract class BaseTestCase extends TestCase
bool $clearCache = true,
?string $portalId = null,
?BindingProcessor $binding = null,
+ bool $reuse = false,
): Application {
- if (!$this->isNotCleanTest()) {
+ if (!$this->isNotCleanTest() && !$reuse) {
if ($this->transactionManager?->isStarted()) {
try {
$this->transactionManager->commit();
@@ -107,6 +108,7 @@ abstract class BaseTestCase extends TestCase
clearCache: $clearCache,
portalId: $portalId,
binding: $binding,
+ reuse: $reuse,
);
}
@@ -240,6 +242,9 @@ abstract class BaseTestCase extends TestCase
$this->getContainer()->reset([
'entityManager',
+ 'ormMetadataData',
+ 'ormDefs',
+ 'metadata',
'config',
'module',
'fileManager',
@@ -258,9 +263,11 @@ abstract class BaseTestCase extends TestCase
/**
* Re-create an application.
*/
- protected function reCreateApplication(): void
+ protected function reCreateApplication(bool $reuse = false): void
{
- $this->espoApplication = $this->createApplication();
+ $this->espoApplication = $this->createApplication(
+ reuse: $reuse,
+ );
}
protected function tearDown(): void
diff --git a/tests/integration/Core/Tester.php b/tests/integration/Core/Tester.php
index 7be2d28ecc..cab713ba79 100644
--- a/tests/integration/Core/Tester.php
+++ b/tests/integration/Core/Tester.php
@@ -197,6 +197,7 @@ class Tester
bool $clearCache = true,
?string $portalId = null,
?BindingProcessor $binding = null,
+ bool $reuse = false,
): Application {
if ($this->application && !$reload) {
@@ -205,15 +206,16 @@ class Tester
$portalId ??= $this->portalId ?? null;
- if ($clearCache) {
- $this->clearCache();
- }
-
$applicationParams = new Application\ApplicationParams(
noErrorHandler: true,
binding: $binding,
+ services: $this->prepareServices($reuse),
);
+ if ($clearCache) {
+ $this->clearCache();
+ }
+
if ($portalId) {
try {
$this->application = new PortalApplication($portalId, $applicationParams);
@@ -603,4 +605,35 @@ class Tester
throw new RuntimeException(previous: $e);
}
}
+
+ /**
+ * @return array<string, object>
+ */
+ private function prepareServices(bool $reuse): array
+ {
+ $services = [];
+
+ if ($reuse && $this->application) {
+ $this->application
+ ->getContainer()
+ ->getByClass(EntityManager::class)
+ ->getMetadata()
+ ->updateData();
+
+ $serviceList = [
+ 'entityManager',
+ 'ormMetadataData',
+ 'ormDefs',
+ 'metadata',
+ ];
+
+ foreach ($serviceList as $service) {
+ $instance = $this->application->getContainer()->get($service);
+
+ $services[$service] = $instance;
+ }
+ }
+
+ return $services;
+ }
}
diff --git a/tests/integration/Espo/Core/Acl/AclTest.php b/tests/integration/Espo/Core/Acl/AclTest.php
index 4328589c15..e4f6a2a1ec 100644
--- a/tests/integration/Espo/Core/Acl/AclTest.php
+++ b/tests/integration/Espo/Core/Acl/AclTest.php
@@ -36,15 +36,13 @@ 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
{
public function testGetReadOwnerUserField()
{
- /* @var $aclManager AclManager */
- $aclManager = $this->getContainer()->get('aclManager');
+ $aclManager = $this->getContainer()->getByClass(AclManager::class);
$this->assertEquals(
'assignedUser',
@@ -128,15 +126,13 @@ class AclTest extends BaseTestCase
/** @var User $user */
$user = $this->getEntityManager()->getEntityById(User::ENTITY_TYPE, $user->getId());
- /* @var $aclManager AclManager */
- $aclManager = $this->getContainer()->get('aclManager');
+ $aclManager = $this->getContainer()->getByClass(AclManager::class);
$this->assertFalse($aclManager->checkField($user, 'Call', 'direction'));
$this->assertTrue($aclManager->checkField($user, 'Call', 'contacts'));
$this->assertFalse($aclManager->checkField($user, 'Call', 'contacts', Acl\Table::ACTION_EDIT));
}
- #[NoTransaction]
public function testDisabledField(): void
{
$metadata = $this->getMetadata();
@@ -150,7 +146,7 @@ class AclTest extends BaseTestCase
]);
$metadata->save();
- $this->reCreateApplication();
+ $this->reCreateApplication(reuse: true);
$acl = $this->getContainer()->getByClass(Acl::class);
@@ -158,7 +154,6 @@ class AclTest extends BaseTestCase
$this->assertTrue($acl->checkField(Account::ENTITY_TYPE, 'name'));
}
- #[NoTransaction]
public function testDisabledLink(): void
{
$metadata = $this->getMetadata();
@@ -172,7 +167,7 @@ class AclTest extends BaseTestCase
]);
$metadata->save();
- $this->reCreateApplication();
+ $this->reCreateApplication(reuse: true);
$acl = $this->getContainer()->getByClass(Acl::class);
diff --git a/tests/integration/Espo/Core/Authentication/FailedLoginAttemptsTest.php b/tests/integration/Espo/Core/Authentication/FailedLoginAttemptsTest.php
index 1c5fefa125..c7956c4115 100644
--- a/tests/integration/Espo/Core/Authentication/FailedLoginAttemptsTest.php
+++ b/tests/integration/Espo/Core/Authentication/FailedLoginAttemptsTest.php
@@ -70,6 +70,7 @@ class FailedLoginAttemptsTest extends BaseTestCase
$binder->bindInstance(DelayUtil::class, $this->delayUtil);
}
},
+ reuse: true,
);
$this->setApplication($app);
diff --git a/tests/integration/Espo/Core/Select/SelectBuilderTest.php b/tests/integration/Espo/Core/Select/SelectBuilderTest.php
index 00dc9bf3f7..d4efa19f49 100644
--- a/tests/integration/Espo/Core/Select/SelectBuilderTest.php
+++ b/tests/integration/Espo/Core/Select/SelectBuilderTest.php
@@ -44,7 +44,6 @@ 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
@@ -86,11 +85,9 @@ class SelectBuilderTest extends BaseTestCase
return $this->getApplication();
}
- protected function initTestPortal(array $aclData = [], bool $skipLogin = false) : Application
+ protected function initTestPortal(array $aclData = [], bool $skipLogin = false): Application
{
- $app = $this->createApplication();
-
- $em = $app->getContainer()->getByClass(EntityManager::class);
+ $em = $this->getEntityManager();
$this->contact = $em->createEntity('Contact', []);
$this->account = $em->createEntity('Account', []);
@@ -112,18 +109,15 @@ class SelectBuilderTest extends BaseTestCase
);
if (!$skipLogin) {
- $this->auth('tester', null, $portal->getId());
+ $this->auth(userName: 'tester', portalId: $portal->getId());
}
- $app = $this->createApplication();
-
- $injectableFactory = $app->getContainer()->getByClass(InjectableFactory::class);
+ $app = $this->createApplication(reuse: true);
- $this->factory = $injectableFactory->create(SelectBuilderFactory::class);
-
- $container = $app->getContainer();
+ $this->setApplication($app);
- $this->user = $container->getByClass(User::class);
+ $this->factory = $this->getInjectableFactory()->create(SelectBuilderFactory::class);
+ $this->user = $this->getContainer()->getByClass(User::class);
return $app;
}
@@ -433,8 +427,7 @@ class SelectBuilderTest extends BaseTestCase
$this->assertEquals($expected, $raw);
}
- #[NoTransaction]
- public function testEmailAccessFilterOnlyAccount()
+ public function testEmailAccessFilterOnlyAccount(): void
{
$this->initTestPortal(
[
@@ -485,8 +478,7 @@ class SelectBuilderTest extends BaseTestCase
$this->assertEquals($expected['joins'], $raw['joins']);
}
- #[NoTransaction]
- public function testEmailAccessFilterOnlyContact()
+ public function testEmailAccessFilterOnlyContact(): void
{
$this->initTestPortal(
[
diff --git a/tests/integration/Espo/Core/Utils/MetadataTest.php b/tests/integration/Espo/Core/Utils/MetadataTest.php
index 3bc3fb0611..f78634a877 100644
--- a/tests/integration/Espo/Core/Utils/MetadataTest.php
+++ b/tests/integration/Espo/Core/Utils/MetadataTest.php
@@ -46,7 +46,7 @@ class MetadataTest extends BaseTestCase
parent::tearDown();
}
- public function testAppend1()
+ public function testAppend1(): void
{
$initial = $this->getMetadata()->get(['app', 'rebuild', 'actionClassNameList']);
@@ -70,11 +70,11 @@ class MetadataTest extends BaseTestCase
$this->getFileManager()->putContents($this->filePath1, $contents1);
$this->getFileManager()->putContents($this->filePath2, $contents2);
$this->getDataManager()->clearCache();
+ $this->getDataManager()->rebuildMetadata();
- $app = $this->createApplication();
+ $this->reCreateApplication(reuse: true);
- /** @var Metadata $metadata */
- $metadata = $app->getContainer()->get('metadata');
+ $metadata = $this->getContainer()->getByClass(Metadata::class);
$this->assertSame(
array_merge(
diff --git a/tests/integration/Espo/Currency/CurrencyTest.php b/tests/integration/Espo/Currency/CurrencyTest.php
index 13a1fc0b88..109f35ab3d 100644
--- a/tests/integration/Espo/Currency/CurrencyTest.php
+++ b/tests/integration/Espo/Currency/CurrencyTest.php
@@ -157,7 +157,7 @@ class CurrencyTest extends BaseTestCase
$configWriter->set('currencyList', ['USD', 'EUR']);
$configWriter->set('defaultCurrency', 'USD');
$configWriter->set('baseCurrency', 'USD');
- $configWriter->save();;
+ $configWriter->save();
$syncManager = $this->getInjectableFactory()->create(SyncManager::class);
@@ -170,7 +170,6 @@ class CurrencyTest extends BaseTestCase
$em->saveEntity($rate);
-
$syncManager->refreshCache();
$script = "ext\\currency\\convert('0.5', 'EUR')";
@@ -185,7 +184,6 @@ class CurrencyTest extends BaseTestCase
/**
* @noinspection PhpUnhandledExceptionInspection
*/
- #[NoTransaction]
public function testDefaultCurrencyJoinMode(): void
{
$configWriter = $this->getInjectableFactory()->create(ConfigWriter::class);
@@ -203,8 +201,8 @@ class CurrencyTest extends BaseTestCase
'USD' => 0.5,
], 'EUR'));
- $this->getDataManager()->rebuild();
- $this->reCreateApplication();
+ $this->getDataManager()->rebuild([]);
+ $this->reCreateApplication(reuse: true);
$em = $this->getEntityManager();
@@ -228,7 +226,6 @@ class CurrencyTest extends BaseTestCase
/**
* @noinspection PhpUnhandledExceptionInspection
*/
- #[NoTransaction]
public function testDefaultCurrencyNoJoinMode(): void
{
$configWriter = $this->getInjectableFactory()->create(ConfigWriter::class);
@@ -246,8 +243,8 @@ class CurrencyTest extends BaseTestCase
'USD' => 0.5,
], 'EUR'));
- $this->getDataManager()->rebuild();
- $this->reCreateApplication();
+ $this->getDataManager()->rebuild([]);
+ $this->reCreateApplication(reuse: true);
$em = $this->getEntityManager();
diff --git a/tests/integration/Espo/ORM/EntityManagerTest.php b/tests/integration/Espo/ORM/EntityManagerTest.php
index bde4c75777..38283320b2 100644
--- a/tests/integration/Espo/ORM/EntityManagerTest.php
+++ b/tests/integration/Espo/ORM/EntityManagerTest.php
@@ -31,17 +31,13 @@ namespace tests\integration\Espo\ORM;
use Espo\Entities\Team;
use Espo\Modules\Crm\Entities\Account;
-use Espo\ORM\EntityManager;
use tests\integration\Core\BaseTestCase;
class EntityManagerTest extends BaseTestCase
{
public function testRefreshEntity(): void
{
- $app = $this->createApplication();
-
- /** @var EntityManager $em */
- $em = $app->getContainer()->getByClass(EntityManager::class);
+ $em = $this->getEntityManager();
$team1 = $em->createEntity(Team::ENTITY_TYPE);
$team2 = $em->createEntity(Team::ENTITY_TYPE);
diff --git a/tests/integration/Espo/ORM/FunctionConverterTest.php b/tests/integration/Espo/ORM/FunctionConverterTest.php
index f10f4f403d..bd6df31d71 100644
--- a/tests/integration/Espo/ORM/FunctionConverterTest.php
+++ b/tests/integration/Espo/ORM/FunctionConverterTest.php
@@ -29,18 +29,14 @@
namespace tests\integration\Espo\ORM;
-use Espo\ORM\EntityManager;
-
use Espo\ORM\Query\Part\Selection;
+use tests\integration\Core\BaseTestCase;
-class FunctionConverterTest extends \tests\integration\Core\BaseTestCase
+class FunctionConverterTest extends BaseTestCase
{
public function testAbs(): void
{
- $app = $this->createApplication();
-
- /** @var EntityManager $entityManager */
- $entityManager = $app->getContainer()->get('entityManager');
+ $entityManager = $this->getEntityManager();
$query = $entityManager->getQueryBuilder()
->select(Selection::fromString('ABS:(-1)')->withAlias('value'))
diff --git a/tests/integration/Espo/ORM/QueryTest.php b/tests/integration/Espo/ORM/QueryTest.php
index 225237955b..404d50c18f 100644
--- a/tests/integration/Espo/ORM/QueryTest.php
+++ b/tests/integration/Espo/ORM/QueryTest.php
@@ -29,15 +29,16 @@
namespace tests\integration\Espo\ORM;
-class QueryTest extends \tests\integration\Core\BaseTestCase
+use PDO;
+use tests\integration\Core\BaseTestCase;
+
+class QueryTest extends BaseTestCase
{
public function testQuery1()
{
- $app = $this->createApplication();
-
- $entityManager = $app->getContainer()->get('entityManager');
+ $entityManager = $this->getEntityManager();
- $account = $entityManager->getEntity('Account');
+ $account = $entityManager->getNewEntity('Account');
$account->set('name', 'Test');
$entityManager->saveEntity($account);
@@ -52,7 +53,7 @@ class QueryTest extends \tests\integration\Core\BaseTestCase
$sth = $entityManager->getQueryExecutor()->execute($query);
- while ($row = $sth->fetch(\PDO::FETCH_ASSOC)) {
+ while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
$rowList[] = $row;
}
diff --git a/tests/integration/Espo/ORM/RelationsTest.php b/tests/integration/Espo/ORM/RelationsTest.php
index 42703847b8..391eaa7fd7 100644
--- a/tests/integration/Espo/ORM/RelationsTest.php
+++ b/tests/integration/Espo/ORM/RelationsTest.php
@@ -54,9 +54,7 @@ class RelationsTest extends BaseTestCase
]);
$metadata->save();
- $this->authenticate(null);
-
- //$this->reCreateApplication();
+ $this->authenticate();
$em = $this->getEntityManager();
@@ -111,9 +109,7 @@ class RelationsTest extends BaseTestCase
]);
$metadata->save();
- $this->authenticate(null);
-
- //$this->reCreateApplication();
+ $this->authenticate();
$em = $this->getEntityManager();
@@ -268,7 +264,9 @@ class RelationsTest extends BaseTestCase
]);
$metadata->save();
- $this->reCreateApplication();
+ $this->getDataManager()->rebuildMetadata();
+
+ $this->reCreateApplication(reuse: true);
$em = $this->getEntityManager();
@@ -294,7 +292,10 @@ class RelationsTest extends BaseTestCase
]);
$metadata->save();
- $this->reCreateApplication();
+ $this->getDataManager()->clearCache();
+ $this->getDataManager()->rebuildMetadata();
+
+ $this->reCreateApplication(reuse: true);
$em = $this->getEntityManager();
diff --git a/tests/integration/Espo/Portal/AclTest.php b/tests/integration/Espo/Portal/AclTest.php
index 1660f5f436..e8b848852c 100644
--- a/tests/integration/Espo/Portal/AclTest.php
+++ b/tests/integration/Espo/Portal/AclTest.php
@@ -29,23 +29,20 @@
namespace tests\integration\Espo\Portal;
+use Espo\Core\Acl;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Record\CreateParams;
-use Espo\Core\Record\Service;
use Espo\Core\Record\ServiceContainer;
use Espo\Core\Select\SearchParams;
+use Espo\Entities\User;
use Espo\Modules\Crm\Entities\CaseObj;
-use integration\Core\NoTransaction;
use tests\integration\Core\BaseTestCase;
-#[NoTransaction]
class AclTest extends BaseTestCase
{
public function testAccessContact(): void
{
- $app = $this->createApplication();
-
- $em = $app->getContainer()->get('entityManager');
+ $em = $this->getEntityManager();
$contact = $em->createEntity('Contact', []);
$portal = $em->createEntity('Portal', [
@@ -68,13 +65,21 @@ class AclTest extends BaseTestCase
],
], true);
- $this->auth('tester', null, $portal->getId());
+ $this->auth(
+ userName: 'tester',
+ portalId: $portal->getId(),
+ );
- $app = $this->createApplication(true, $portal->getId());
+ $app = $this->createApplication(
+ portalId: $portal->getId(),
+ reuse: true
+ );
- $em = $app->getContainer()->get('entityManager');
+ $this->setApplication($app);
+
+ $em = $this->getEntityManager();
- $acl = $app->getContainer()->get('acl');
+ $acl = $this->getContainer()->getByClass(Acl::class);
$case1 = $em->createEntity('Case', [
'contactId' => $contact->getId(),
@@ -98,7 +103,7 @@ class AclTest extends BaseTestCase
$this->assertFalse($acl->check($case3, 'read'));
$this->assertFalse($acl->check($case4, 'read'));
- $service = $app->getContainer()->get('recordServiceContainer')->get('Case');
+ $service = $app->getContainer()->getByClass(ServiceContainer::class)->get('Case');
$result = $service->find(SearchParams::create());
@@ -115,9 +120,7 @@ class AclTest extends BaseTestCase
public function testAccessAccount(): void
{
- $app = $this->createApplication();
-
- $em = $app->getContainer()->get('entityManager');
+ $em = $this->getEntityManager();
$contact = $em->createEntity('Contact', []);
$account = $em->createEntity('Account', []);
@@ -142,13 +145,21 @@ class AclTest extends BaseTestCase
],
], true);
- $this->auth('tester', null, $portal->getId());
+ $this->auth(
+ userName: 'tester',
+ portalId: $portal->getId(),
+ );
+
+ $app = $this->createApplication(
+ portalId: $portal->getId(),
+ reuse: true
+ );
- $app = $this->createApplication(true, $portal->getId());
+ $this->setApplication($app);
- $em = $app->getContainer()->get('entityManager');
+ $em = $this->getEntityManager();
- $acl = $app->getContainer()->get('acl');
+ $acl = $this->getContainer()->getByClass(Acl::class);
$case1 = $em->createEntity('Case', [
'contactId' => $contact->getId(),
@@ -176,7 +187,8 @@ class AclTest extends BaseTestCase
$this->assertTrue($acl->check($case4, 'read'));
$this->assertFalse($acl->check($case5, 'read'));
- $service = $app->getContainer()->get('recordServiceContainer')->get('Case');
+ $service = $app->getContainer()->getByClass(ServiceContainer::class)->get('Case');
+
$result = $service->find(SearchParams::create());
$idList = [];
@@ -191,11 +203,12 @@ class AclTest extends BaseTestCase
$this->assertFalse(in_array($case5->getId(), $idList));
}
+ /**
+ * @noinspection PhpUnhandledExceptionInspection
+ */
public function testAccessOwn(): void
{
- $app = $this->createApplication();
-
- $em = $app->getContainer()->get('entityManager');
+ $em = $this->getEntityManager();
$contact = $em->createEntity('Contact', []);
$account = $em->createEntity('Account', []);
@@ -220,14 +233,22 @@ class AclTest extends BaseTestCase
],
], true);
- $this->auth('tester', null, $portal->getId());
+ $this->auth(
+ userName: 'tester',
+ portalId: $portal->getId(),
+ );
- $app = $this->createApplication(true, $portal->getId());
+ $app = $this->createApplication(
+ portalId: $portal->getId(),
+ reuse: true
+ );
- $em = $app->getContainer()->get('entityManager');
+ $this->setApplication($app);
- $acl = $app->getContainer()->get('acl');
- $user = $app->getContainer()->get('user');
+ $em = $this->getEntityManager();
+
+ $acl = $this->getContainer()->getByClass(Acl::class);
+ $user = $this->getContainer()->getByClass(User::class);
$case1 = $em->createEntity('Case', [
'contactId' => $contact->getId(),
@@ -259,7 +280,7 @@ class AclTest extends BaseTestCase
$this->assertTrue($acl->check($case5, 'read'));
$this->assertFalse($acl->check($case6, 'read'));
- $service = $app->getContainer()->get('recordServiceContainer')->get('Case');
+ $service = $this->getContainer()->getByClass(ServiceContainer::class)->get('Case');
$result = $service->find(SearchParams::create());
@@ -308,12 +329,19 @@ class AclTest extends BaseTestCase
],
], true);
- $this->auth('tester', null, $portal->getId());
+ $this->auth(
+ userName: 'tester',
+ portalId: $portal->getId(),
+ );
+
+ $app = $this->createApplication(
+ portalId: $portal->getId(),
+ reuse: true,
+ );
- $app = $this->createApplication(true, $portal->getId());
+ $this->setApplication($app);
- /** @var Service<CaseObj> $caseService */
- $caseService = $app->getContainer()
+ $caseService = $this->getContainer()
->getByClass(ServiceContainer::class)
->getByClass(CaseObj::class);
@@ -329,7 +357,7 @@ class AclTest extends BaseTestCase
try {
/** @noinspection PhpUnhandledExceptionInspection */
- $caseService->create((object)[
+ $caseService->create((object) [
'name' => 'Test 1',
'accountId' => $accountNotOwn->getId(),
'contactId' => $contactNotOwn->getId(),
diff --git a/tests/integration/Espo/Record/CascadeRemovalTest.php b/tests/integration/Espo/Record/CascadeRemovalTest.php
index ec8894bedc..c8af414faa 100644
--- a/tests/integration/Espo/Record/CascadeRemovalTest.php
+++ b/tests/integration/Espo/Record/CascadeRemovalTest.php
@@ -37,7 +37,6 @@ 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
@@ -45,7 +44,6 @@ class CascadeRemovalTest extends BaseTestCase
/**
* @noinspection PhpUnhandledExceptionInspection
*/
- #[NoTransaction]
public function testRemovalAndRestoral(): void
{
$metadata = $this->getMetadata();
@@ -65,8 +63,9 @@ class CascadeRemovalTest extends BaseTestCase
]);
$metadata->save();
$this->getDataManager()->clearCache();
+ $this->getDataManager()->rebuildMetadata();
- $this->reCreateApplication();
+ $this->reCreateApplication(reuse: true);
$em = $this->getEntityManager();
diff --git a/tests/integration/Espo/Record/DefaultsPopulatorTest.php b/tests/integration/Espo/Record/DefaultsPopulatorTest.php
index 42d4b85f4c..8931143729 100644
--- a/tests/integration/Espo/Record/DefaultsPopulatorTest.php
+++ b/tests/integration/Espo/Record/DefaultsPopulatorTest.php
@@ -76,8 +76,8 @@ class DefaultsPopulatorTest extends BaseTestCase
],
], true);
- $this->auth('tester', null, $portal->getId());
- $this->reCreateApplication();
+ $this->auth(userName: 'tester', portalId: $portal->getId());
+ $this->reCreateApplication(reuse: true);
$service = $this->getContainer()->getByClass(ServiceContainer::class)->getByClass(CaseObj::class);
diff --git a/tests/integration/Espo/Record/LinkTest.php b/tests/integration/Espo/Record/LinkTest.php
index 8defe3970d..dbbd72d154 100644
--- a/tests/integration/Espo/Record/LinkTest.php
+++ b/tests/integration/Espo/Record/LinkTest.php
@@ -60,7 +60,7 @@ class LinkTest extends BaseTestCase
]);
$metadata->save();
- $this->reCreateApplication();
+ $this->reCreateApplication(reuse: true);
$em = $this->getContainer()->getByClass(EntityManager::class);
diff --git a/tests/integration/Espo/Record/ReadOnlyTest.php b/tests/integration/Espo/Record/ReadOnlyTest.php
index c076b95824..49a190db54 100644
--- a/tests/integration/Espo/Record/ReadOnlyTest.php
+++ b/tests/integration/Espo/Record/ReadOnlyTest.php
@@ -34,10 +34,8 @@ 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(): void
@@ -55,7 +53,7 @@ class ReadOnlyTest extends BaseTestCase
]);
$metadata->save();
- $this->reCreateApplication();
+ $this->reCreateApplication(reuse: true);
$service = $this->getContainer()
->getByClass(ServiceContainer::class)
@@ -103,7 +101,7 @@ class ReadOnlyTest extends BaseTestCase
$metadata->save();
- $this->reCreateApplication();
+ $this->reCreateApplication(reuse: true);
$service = $this->getContainer()->getByClass(ServiceContainer::class)->getByClass(Account::class);
diff --git a/tests/integration/Espo/Stream/FollowTest.php b/tests/integration/Espo/Stream/FollowTest.php
index f55b64538f..b77a5c7f14 100644
--- a/tests/integration/Espo/Stream/FollowTest.php
+++ b/tests/integration/Espo/Stream/FollowTest.php
@@ -81,7 +81,9 @@ class FollowTest extends BaseTestCase
/** @noinspection PhpArrayKeyDoesNotMatchArrayShapeInspection */
$tool->update(Contact::ENTITY_TYPE, ['assignedUsers' => true]);
- $this->reCreateApplication();
+ $this->getDataManager()->rebuildMetadata();
+
+ $this->reCreateApplication(reuse: true);
$streamService = $this->getInjectableFactory()->create(Service::class);
diff --git a/tests/integration/Espo/Stream/RecordTest.php b/tests/integration/Espo/Stream/RecordTest.php
index eb3d0edb9e..93eab044d1 100644
--- a/tests/integration/Espo/Stream/RecordTest.php
+++ b/tests/integration/Espo/Stream/RecordTest.php
@@ -89,9 +89,16 @@ class RecordTest extends BaseTestCase
$noteInternalPinned->setIsInternal(true);
$em->saveEntity($noteInternalPinned);
- $this->auth('test', portalId: $portal->getId());
+ $this->auth(
+ userName: 'test',
+ portalId: $portal->getId(),
+ );
+
+ $app = $this->createApplication(
+ portalId: $portal->getId(),
+ reuse: true,
+ );
- $app = $this->createApplication(portalId: $portal->getId());
$this->setApplication($app);
$service = $this->getInjectableFactory()->create(RecordService::class);
diff --git a/tests/integration/Espo/Tools/Pipeline/PipelineTest.php b/tests/integration/Espo/Tools/Pipeline/PipelineTest.php
index 3eec6ea577..a6748b7c1d 100644
--- a/tests/integration/Espo/Tools/Pipeline/PipelineTest.php
+++ b/tests/integration/Espo/Tools/Pipeline/PipelineTest.php
@@ -44,7 +44,6 @@ 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
@@ -52,7 +51,6 @@ class PipelineTest extends BaseTestCase
/**
* @noinspection PhpUnhandledExceptionInspection
*/
- #[NoTransaction]
public function testPipeline1(): void
{
$this->initPipeline(Opportunity::ENTITY_TYPE);
@@ -188,8 +186,8 @@ class PipelineTest extends BaseTestCase
Opportunity::FIELD_AMOUNT => 1000,
], CreateParams::create());
- $this->assertEquals($pipeline1->getId(), $opp->get(Field::PIPELINE . 'Id'));
- $this->assertEquals($pipeline1->getStages()[0]->getId(), $opp->get(Field::PIPELINE_STAGE . 'Id'));
+ $this->assertEquals($pipeline1->getId(), $opp->getEntity()->get(Field::PIPELINE . 'Id'));
+ $this->assertEquals($pipeline1->getStages()[0]->getId(), $opp->getEntity()->get(Field::PIPELINE_STAGE . 'Id'));
//
@@ -202,7 +200,7 @@ class PipelineTest extends BaseTestCase
//
$this->auth($user1->getUserName());
- $this->reCreateApplication();
+ $this->reCreateApplication(reuse: true);
$pipelinesParam = $this->getInjectableFactory()->create(Pipelines::class);
diff --git a/tests/integration/Espo/User/AclTest.php b/tests/integration/Espo/User/AclTest.php
index aac4d0d9e0..08f220086c 100644
--- a/tests/integration/Espo/User/AclTest.php
+++ b/tests/integration/Espo/User/AclTest.php
@@ -59,7 +59,6 @@ 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 BaseTestCase
@@ -169,11 +168,13 @@ class AclTest extends BaseTestCase
]
], true);
- $this->auth('tester', null, 'testPortalId');
+ $this->auth(userName: 'tester', portalId: 'testPortalId');
- $app = $this->createApplication();
+ $app = $this->createApplication(reuse: true);
- $processor = $app->getInjectableFactory()->create(ControllerActionProcessor::class);
+ $this->setApplication($app);
+
+ $processor = $this->getInjectableFactory()->create(ControllerActionProcessor::class);
json_decode('{"name":"Test Account"}');
@@ -424,7 +425,6 @@ class AclTest extends BaseTestCase
$this->assertNotNull($e);
}
- #[NoTransaction]
public function testUserAccessCreateAssignedPermissionNo1(): void
{
$this->prepareTestUser();
@@ -450,7 +450,7 @@ class AclTest extends BaseTestCase
], CreateParams::create());
}
- public function testUserAccessCreateAssignedPermissionNo2()
+ public function testUserAccessCreateAssignedPermissionNo2(): void
{
$this->prepareTestUser();
diff --git a/tests/integration/Espo/User/LoginTest.php b/tests/integration/Espo/User/LoginTest.php
index d9994c2644..e53e9253db 100644
--- a/tests/integration/Espo/User/LoginTest.php
+++ b/tests/integration/Espo/User/LoginTest.php
@@ -30,7 +30,6 @@
namespace tests\integration\Espo\User;
use Espo\Entities\User;
-use integration\Core\NoTransaction;
use tests\integration\Core\BaseTestCase;
class LoginTest extends BaseTestCase
@@ -60,12 +59,11 @@ class LoginTest extends BaseTestCase
$this->assertEquals('admin', $user->getUserName());
}
- #[NoTransaction]
public function testWrongCredentials(): void
{
$this->auth('admin', 'wrong-password');
- $application = $this->createApplication();
+ $application = $this->createApplication(reuse: true);
$this->assertFalse($application->getContainer()->has('user'));
}