fix tests

This commit is contained in:
Yuri Kuznetsov
2025-07-09 10:52:07 +03:00
parent ee0bfb5970
commit d29ef9d998
7 changed files with 39 additions and 55 deletions
@@ -104,7 +104,7 @@ class ClassMapTest extends TestCase
{
$expected = [
'Download' => 'tests\unit\testData\EntryPoints\Espo\EntryPoints\Download',
'Test' => 'tests\unit\testData\EntryPoints\Espo\EntryPoints\Test',
'TestEntry' => 'tests\unit\testData\EntryPoints\Espo\EntryPoints\TestEntry',
'InModule' => 'tests\unit\testData\EntryPoints\Espo\Modules\Crm\EntryPoints\InModule'
];
@@ -135,7 +135,7 @@ class ClassMapTest extends TestCase
$result = [
'Download' => 'tests\unit\testData\EntryPoints\Espo\EntryPoints\Download',
'Test' => 'tests\unit\testData\EntryPoints\Espo\EntryPoints\Test',
'TestEntry' => 'tests\unit\testData\EntryPoints\Espo\EntryPoints\TestEntry',
'InModule' => 'tests\unit\testData\EntryPoints\Espo\Modules\Crm\EntryPoints\InModule',
];
@@ -195,7 +195,7 @@ class ClassMapTest extends TestCase
$result = [
'Download' => 'tests\unit\testData\EntryPoints\Espo\EntryPoints\Download',
'Test' => 'tests\unit\testData\EntryPoints\Espo\EntryPoints\Test',
'TestEntry' => 'tests\unit\testData\EntryPoints\Espo\EntryPoints\TestEntry',
'InModule' => 'tests\unit\testData\EntryPoints\Espo\Modules\Crm\EntryPoints\InModule',
];
+11 -19
View File
@@ -29,26 +29,19 @@
namespace tests\unit\Espo\Entities;
use Espo\Core\Repositories\Database;
use Espo\Entities\Attachment;
use Espo\Entities\Email;
use Espo\ORM\EntityManager;
use Espo\ORM\Repository\RDBRepository;
use PHPUnit\Framework\TestCase;
class EmailTest extends \PHPUnit\Framework\TestCase
class EmailTest extends TestCase
{
/**
* @var Email
*/
/** @var Email */
private $email;
/**
* @var EntityManager
*/
private $entityManager;
/**
* @var RDBRepository
*/
/** @var RDBRepository */
private $attachmentRepository;
// TODO defs test helper
@@ -437,29 +430,28 @@ class EmailTest extends \PHPUnit\Framework\TestCase
protected function setUp() : void
{
$this->entityManager = $this->createMock(EntityManager::class);
$entityManager = $this->createMock(EntityManager::class);
$this->attachmentRepository = $this->createMock(RDBRepository::class);
$this->entityManager
$entityManager
->expects($this->any())
->method('getRDBRepositoryByClass')
->willReturnMap([
[Attachment::class, $this->attachmentRepository],
]);
$this->repository =
$this->getMockBuilder('Espo\Core\ORM\Repositories\Database')->disableOriginalConstructor()->getMock();
$repository = $this->createMock(Database::class);
$this->entityManager
$entityManager
->expects($this->any())
->method('getRepository')
->will($this->returnValue($this->repository));
->willReturn($repository);
$this->email = new Email(
entityType: 'Email',
defs: $this->defs,
entityManager: $this->entityManager,
entityManager: $entityManager,
);
}
+4 -3
View File
@@ -32,17 +32,18 @@ namespace tests\unit\Espo\ORM\Repository;
use Espo\Modules\Crm\Entities\CaseObj;
use Espo\Modules\Crm\Entities\Lead;
use tests\unit\testData\Entities\Test;
use PHPUnit\Framework\TestCase;
use tests\unit\testData\Entities\TestEntity;
use Espo\ORM\Repository\Util;
class UtilTest extends \PHPUnit\Framework\TestCase
class UtilTest extends TestCase
{
public function testGetRDBRepositoryByClass(): void
{
$this->assertEquals('Lead', Util::getEntityTypeByClass(Lead::class));
$this->assertEquals('Case', Util::getEntityTypeByClass(CaseObj::class));
$this->assertEquals('Test', Util::getEntityTypeByClass(Test::class));
$this->assertEquals('TestEntity', Util::getEntityTypeByClass(TestEntity::class));
}
public function testGetRDBRepositoryByClassException(): void
+12 -13
View File
@@ -206,7 +206,7 @@ class FieldManagerTest extends TestCase
$this->metadataHelper
->expects($this->once())
->method('getFieldDefsByType')
->will($this->returnValue(json_decode('{
->willReturn(json_decode('{
"params":[
{
"name":"required",
@@ -243,22 +243,22 @@ class FieldManagerTest extends TestCase
"personalData": true,
"textFilter": true,
"fullTextSearch": true
}', true)));
}', true));
$this->metadata
->expects($this->any())
->method('get')
->will($this->returnValueMap($map));
->willReturnMap($map);
$this->metadata
->expects($this->exactly(2))
->method('getObjects')
->will($this->returnValue((object) $data));
->willReturn((object) $data);
$this->metadata
->expects($this->exactly(1))
->method('getCustom')
->will($this->returnValue((object) []));
->willReturn((object) []);
$this->metadata
->expects($this->never())
@@ -286,22 +286,21 @@ class FieldManagerTest extends TestCase
$this->metadata
->expects($this->any())
->method('get')
->will($this->returnValueMap($map));
->willReturnMap($map);
$this->metadata
->expects($this->exactly(2))
->method('getObjects')
->will($this->returnValue((object) $data));
->willReturn((object) $data);
$this->metadata
->expects($this->once())
->method('saveCustom')
->will($this->returnValue(true));
->method('saveCustom');
$this->metadataHelper
->expects($this->once())
->method('getFieldDefsByType')
->will($this->returnValue(json_decode('{
->willReturn(json_decode('{
"params":[
{
"name":"required",
@@ -338,7 +337,7 @@ class FieldManagerTest extends TestCase
"personalData": true,
"textFilter": true,
"fullTextSearch": true
}', true)));
}', true));
$data = [
"type" => "varchar",
@@ -367,12 +366,12 @@ class FieldManagerTest extends TestCase
$this->metadata
->expects($this->once())
->method('getObjects')
->will($this->returnValue((object) $data));
->willReturn((object) $data);
$this->language
->expects($this->once())
->method('translate')
->will($this->returnValue('Var Name'));
->willReturn('Var Name');
$this->assertEquals($data, $this->fieldManager->read('Account', 'varName'));
}
@@ -36,12 +36,13 @@ use Espo\Tools\MassUpdate\Action;
use Espo\ORM\Entity;
use Espo\ORM\Defs as OrmDefs;
use PHPUnit\Framework\TestCase;
class ValueMapPreparatorTest extends \PHPUnit\Framework\TestCase
class ValueMapPreparatorTest extends TestCase
{
public function testPrepare1(): void
{
$preprator = new ValueMapPreparator(
$preparator = new ValueMapPreparator(
$this->createMock(OrmDefs::class)
);
@@ -70,8 +71,7 @@ class ValueMapPreparatorTest extends \PHPUnit\Framework\TestCase
$entity
->expects($this->any())
->method('get')
->will(
$this->returnCallback(
->willReturnCallback(
function ($attribute) {
$map = [
'a1' => ['0'],
@@ -88,10 +88,9 @@ class ValueMapPreparatorTest extends \PHPUnit\Framework\TestCase
return $map[$attribute] ?? null;
}
)
);
$values = $preprator->prepare($entity, $data);
$values = $preparator->prepare($entity, $data);
$this->assertEquals(['0', '1', '2'], $values->a1);
$this->assertEquals(['0'], $values->a2);
@@ -2,10 +2,7 @@
namespace tests\unit\testData\Entities;
use Espo\ORM\Entity;
use Espo\ORM\BaseEntity;
class Test extends BaseEntity
{
}
class TestEntity extends BaseEntity
{}
@@ -2,15 +2,11 @@
namespace tests\unit\testData\EntryPoints\Espo\EntryPoints;
class Test
class TestEntry
{
protected $authRequired = true;
public function run()
{
}
{}
}