Skip to content

EspoCRM – Open Source CRM Application

integration test changes

Yuri Kuznetsov1bcf6647d6b9
diff --git a/tests/integration/Core/BaseTestCase.php b/tests/integration/Core/BaseTestCase.php
index 52fbc1765e..31091704b2 100644
--- a/tests/integration/Core/BaseTestCase.php
+++ b/tests/integration/Core/BaseTestCase.php
@@ -32,6 +32,7 @@ namespace tests\integration\Core;
use Espo\Core\Api\RequestWrapper;
use Espo\Core\Api\ResponseWrapper;
use Espo\Core\Application;
+use Espo\Core\ApplicationRunners\Rebuild;
use Espo\Core\Container;
use Espo\Core\DataManager;
use Espo\Core\InjectableFactory;
@@ -116,32 +117,32 @@ abstract class BaseTestCase extends TestCase
protected function getFileManager(): FileManager
{
- return $this->getApplication()->getContainer()->get('fileManager');
+ return $this->getApplication()->getContainer()->getByClass(FileManager::class);
}
protected function getDataManager(): DataManager
{
- return $this->getApplication()->getContainer()->get('dataManager');
+ return $this->getApplication()->getContainer()->getByClass(DataManager::class);
}
protected function getInjectableFactory(): InjectableFactory
{
- return $this->getApplication()->getContainer()->get('injectableFactory');
+ return $this->getApplication()->getContainer()->getByClass(InjectableFactory::class);
}
protected function getMetadata(): Metadata
{
- return $this->getApplication()->getContainer()->get('metadata');
+ return $this->getApplication()->getContainer()->getByClass(Metadata::class);
}
protected function getEntityManager(): EntityManager
{
- return $this->getApplication()->getContainer()->get('entityManager');
+ return $this->getApplication()->getContainer()->getByClass(EntityManager::class);
}
protected function getConfig(): Config
{
- return $this->getApplication()->getContainer()->get('config');
+ return $this->getApplication()->getContainer()->getByClass(Config::class);
}
protected function normalizePath(string $path): string
@@ -149,11 +150,6 @@ abstract class BaseTestCase extends TestCase
return $this->espoTester->normalizePath($path);
}
- /*protected function sendRequest($method, $action, $data = null)
- {
- return $this->espoTester->sendRequest($method, $action, $data);
- }*/
-
protected function setUp(): void
{
$params = [
@@ -165,9 +161,13 @@ abstract class BaseTestCase extends TestCase
$this->espoTester = new Tester($params);
+ $this->espoTester->getApplication(true)->run(Rebuild::class);
+
$this->beforeSetUp();
+
$this->espoTester->initialize();
$this->auth($this->userName, $this->password, null, $this->authenticationMethod);
+
$this->beforeStartApplication();
$this->espoApplication = $this->createApplication();
$this->afterStartApplication();
@@ -186,6 +186,9 @@ abstract class BaseTestCase extends TestCase
$this->espoTester->terminate();
$this->espoTester = null;
$this->espoApplication = null;
+
+ //restore_error_handler();
+ //restore_exception_handler();
}
/**
@@ -237,10 +240,10 @@ abstract class BaseTestCase extends TestCase
);
}
- protected function setData(array $data): void
+ /*protected function setData(array $data): void
{
$this->espoTester->setData($data);
- }
+ }*/
/**
* @todo Revise whether needed.
diff --git a/tests/integration/Core/DataLoader.php b/tests/integration/Core/DataLoader.php
index a74e318fca..b5b19558b8 100644
--- a/tests/integration/Core/DataLoader.php
+++ b/tests/integration/Core/DataLoader.php
@@ -31,15 +31,14 @@ namespace tests\integration\Core;
use Espo\Core\Application;
use Espo\Core\Container;
-use Espo\Core\InjectableFactory;
use Espo\Core\Utils\Config;
-use Espo\Core\Utils\Database\Helper as DatabaseHelper;
use Espo\Core\Utils\File\Manager as FileManager;
use Espo\Core\Utils\PasswordHash;
use Espo\Entities\Preferences;
use Espo\Entities\User;
use Espo\ORM\EntityManager;
use Exception;
+use RuntimeException;
class DataLoader
{
@@ -84,13 +83,38 @@ class DataLoader
protected function handleData(array $fullData): void
{
foreach ($fullData as $type => $data) {
- $methodName = 'load' . ucfirst($type);
+ if ($type === 'files') {
+ $this->loadFiles($data);
- if (!method_exists($this, $methodName)) {
- throw new Exception('DataLoader: Data type is not supported in dataFile.');
+ continue;
}
- $this->$methodName($data);
+ if ($type === 'entities') {
+ $this->loadEntities($data);
+
+ continue;
+ }
+
+ if ($type === 'data') {
+ $this->loadData($data);
+
+ continue;
+ }
+
+ if ($type === 'config') {
+ $this->loadConfig($data);
+
+ continue;
+ }
+
+ if ($type === 'preferences') {
+ $this->loadPreferences($data);
+
+ continue;
+ }
+
+
+ throw new RuntimeException('DataLoader: Data type is not supported in dataFile.');
}
}
@@ -101,7 +125,7 @@ class DataLoader
$fileManager->copy($path, '.', true);
} catch (Exception $e) {
- throw new Exception('Error loadFiles: ' . $e->getMessage());
+ throw new RuntimeException('Error loadFiles: ' . $e->getMessage());
}
}
@@ -128,7 +152,7 @@ class DataLoader
try {
$entityManager->saveEntity($entity);
} catch (Exception $e) {
- throw new Exception('Error loadEntities: ' . $e->getMessage() . ', ' . print_r($entityData, true));
+ throw new RuntimeException('Error loadEntities: ' . $e->getMessage() . ', ' . print_r($entityData, true));
}
}
}
@@ -146,7 +170,7 @@ class DataLoader
try {
$config->save();
} catch (Exception $e) {
- throw new Exception('Error loadConfig: ' . $e->getMessage());
+ throw new RuntimeException('Error loadConfig: ' . $e->getMessage());
}
}
@@ -163,29 +187,8 @@ class DataLoader
try {
$entityManager->saveEntity($preferences);
} catch (Exception $e) {
- throw new Exception('Error loadPreferences: ' . $e->getMessage());
+ throw new RuntimeException('Error loadPreferences: ' . $e->getMessage());
}
}
}
-
- /*private function loadSql(array $data): void
- {
- if (empty($data)) {
- return;
- }
-
- $helper = $this->getContainer()
- ->getByClass(InjectableFactory::class)
- ->create(DatabaseHelper::class);
-
- $pdo = $helper->getPDO();
-
- foreach ($data as $sql) {
- try {
- $pdo->query($sql);
- } catch (Exception $e) {
- throw new Exception('Error loadSql: ' . $e->getMessage() . ', sql: ' . $sql);
- }
- }
- }*/
}
diff --git a/tests/integration/Core/Tester.php b/tests/integration/Core/Tester.php
index 4df131d09a..a99c501ff2 100644
--- a/tests/integration/Core/Tester.php
+++ b/tests/integration/Core/Tester.php
@@ -470,11 +470,11 @@ class Tester
}
}
- public function setData(array $data): void
+ /*public function setData(array $data): void
{
$this->getDataLoader()->setData($data);
$this->getApplication(true, true)->run(Rebuild::class);
- }
+ }*/
public function clearCache(): void
{
diff --git a/tests/integration/Espo/Core/Utils/Database/Base.php b/tests/integration/Espo/Core/Utils/Database/Base.php
index 65a0fd1fd3..ab561b667c 100644
--- a/tests/integration/Espo/Core/Utils/Database/Base.php
+++ b/tests/integration/Espo/Core/Utils/Database/Base.php
@@ -33,16 +33,15 @@ use Espo\Core\Utils\Config;
use Espo\Core\Utils\Database\Helper;
use Espo\Core\Utils\Metadata;
use Espo\Core\Utils\Util;
+use tests\integration\Core\BaseTestCase;
-abstract class Base extends \tests\integration\Core\BaseTestCase
+abstract class Base extends BaseTestCase
{
protected ?string $dataFile = 'InitData.php';
protected ?string $pathToFiles = 'Core/Database/customFiles';
protected function beforeSetUp(): void
- {
- //$this->fullReset();
- }
+ {}
protected function getColumnInfo($entityName, $fieldName)
{
diff --git a/tests/integration/Espo/Record/ReadOnlyTest.php b/tests/integration/Espo/Record/ReadOnlyTest.php
index 1baa635124..305e13732c 100644
--- a/tests/integration/Espo/Record/ReadOnlyTest.php
+++ b/tests/integration/Espo/Record/ReadOnlyTest.php
@@ -29,7 +29,6 @@
namespace tests\integration\Espo\Record;
-use Espo\Core\FieldValidation\Type;
use Espo\Core\Record\CreateParams;
use Espo\Core\Record\ServiceContainer;
use Espo\Core\Record\UpdateParams;