diff --git a/tests/unit/Espo/Core/Acl/Map/MapTest.php b/tests/unit/Espo/Core/Acl/Map/MapTest.php index 4923f6228c..6f74c40393 100644 --- a/tests/unit/Espo/Core/Acl/Map/MapTest.php +++ b/tests/unit/Espo/Core/Acl/Map/MapTest.php @@ -50,6 +50,7 @@ class MapTest extends TestCase private $table; private $metadataProvider; private $cacheKeyProvider; + private $dataCache; protected function setUp(): void { diff --git a/tests/unit/Espo/Core/AclManagerTest.php b/tests/unit/Espo/Core/AclManagerTest.php index 6cf1532a42..2144c5078b 100644 --- a/tests/unit/Espo/Core/AclManagerTest.php +++ b/tests/unit/Espo/Core/AclManagerTest.php @@ -29,73 +29,48 @@ namespace tests\unit\Espo\Core; -use Espo\Core\{ - Acl\Permission, - AclManager, - Acl\Table, - Acl\AccessChecker\AccessCheckerFactory, - Acl\OwnershipChecker\OwnershipCheckerFactory, - Acl\OwnerUserFieldProvider, - Acl\Table\TableFactory, - Acl\GlobalRestriction, - Acl\Map\MapFactory, - ORM\EntityManager}; +use Espo\Core\Acl\AccessChecker\AccessCheckerFactory; +use Espo\Core\Acl\GlobalRestriction; +use Espo\Core\Acl\Map\MapFactory; +use Espo\Core\Acl\OwnershipChecker\OwnershipCheckerFactory; +use Espo\Core\Acl\OwnerUserFieldProvider; +use Espo\Core\Acl\Permission; +use Espo\Core\Acl\Table; +use Espo\Core\Acl\Table\TableFactory; +use Espo\Core\AclManager; +use Espo\Core\ORM\EntityManager; -use Espo\Entities\{ - User, -}; +use Espo\Entities\User; +use PHPUnit\Framework\TestCase; -class AclManagerTest extends \PHPUnit\Framework\TestCase +class AclManagerTest extends TestCase { - /** - * @var AclManager - */ + /** @var AclManager */ private $aclManager; - - /** - * @var AccessCheckerFactory - */ - private $accessCheckerFactory; - - /** - * @var OwnershipCheckerFactory - */ - private $ownershipCheckerFactory; - - /** - * @var TableFactory - */ + /** @var TableFactory */ private $tableFactory; - - /** - * @var GlobalRestriction - */ - private $globalRestriction; - - /** - * @var User - */ + /** @var User */ private $user; - private $mapFactory; + private $table; protected function setUp(): void { $this->user = $this->createMock(User::class); $this->table = $this->createMock(Table::class); - $this->accessCheckerFactory = $this->createMock(AccessCheckerFactory::class); - $this->ownershipCheckerFactory = $this->createMock(OwnershipCheckerFactory::class); + $accessCheckerFactory = $this->createMock(AccessCheckerFactory::class); + $ownershipCheckerFactory = $this->createMock(OwnershipCheckerFactory::class); $this->tableFactory = $this->createMock(TableFactory::class); - $this->mapFactory = $this->createMock(MapFactory::class); - $this->globalRestriction = $this->createMock(GlobalRestriction::class); + $mapFactory = $this->createMock(MapFactory::class); + $globalRestriction = $this->createMock(GlobalRestriction::class); $this->aclManager = new AclManager( - $this->accessCheckerFactory, - $this->ownershipCheckerFactory, + $accessCheckerFactory, + $ownershipCheckerFactory, $this->tableFactory, - $this->mapFactory, - $this->globalRestriction, + $mapFactory, + $globalRestriction, $this->createMock(OwnerUserFieldProvider::class), $this->createMock(EntityManager::class) ); diff --git a/tests/unit/Espo/Core/Api/RequestTest.php b/tests/unit/Espo/Core/Api/RequestTest.php index aa2047a2d2..1c6ca0125d 100644 --- a/tests/unit/Espo/Core/Api/RequestTest.php +++ b/tests/unit/Espo/Core/Api/RequestTest.php @@ -29,19 +29,17 @@ namespace tests\unit\Espo\Core\Api; -use Psr\Http\Message\{ - ServerRequestInterface as Psr7Request, - StreamInterface, -}; - +use PHPUnit\Framework\TestCase; +use Psr\Http\Message\ServerRequestInterface as Psr7Request; +use Psr\Http\Message\StreamInterface; use Slim\Psr7\Factory\RequestFactory; - use Espo\Core\Api\RequestWrapper; -class RequestTest extends \PHPUnit\Framework\TestCase +class RequestTest extends TestCase { + private $request; - protected function setUp() : void + protected function setUp(): void { $this->request = $this->getMockBuilder(Psr7Request::class)->disableOriginalConstructor()->getMock(); } diff --git a/tests/unit/Espo/Core/Binding/BindingContainerTest.php b/tests/unit/Espo/Core/Binding/BindingContainerTest.php index 2137f473d5..2990875d04 100644 --- a/tests/unit/Espo/Core/Binding/BindingContainerTest.php +++ b/tests/unit/Espo/Core/Binding/BindingContainerTest.php @@ -39,6 +39,7 @@ use Espo\Core\Binding\ContextualBinder; use Espo\Core\Binding\Key\NamedClassKey; use Espo\Core\Binding\Key\NamedKey; +use PHPUnit\Framework\TestCase; use ReflectionClass; use ReflectionParameter; use ReflectionNamedType; @@ -50,25 +51,24 @@ use tests\unit\testClasses\Core\Binding\SomeInterface2; use tests\unit\testClasses\Core\Binding\SomeClass1; use tests\unit\testClasses\Core\Binding\SomeClass2; -class BindingContainerTest extends \PHPUnit\Framework\TestCase +class BindingContainerTest extends TestCase { - /** - * @var Binder - */ + /** @var Binder */ private $binder; + private $loader; protected function setUp(): void { $this->loader = $this->createMock(BindingLoader::class); - $this->data = new BindingData(); + $data = new BindingData(); - $this->binder = new Binder($this->data); + $this->binder = new Binder($data); $this->loader ->expects($this->any()) ->method('load') - ->willReturn($this->data); + ->willReturn($data); } protected function createClassMock(string $className) : ReflectionClass diff --git a/tests/unit/Espo/Core/Console/CommandManagerTest.php b/tests/unit/Espo/Core/Console/CommandManagerTest.php index 6bbda5cc8d..e95d452b60 100644 --- a/tests/unit/Espo/Core/Console/CommandManagerTest.php +++ b/tests/unit/Espo/Core/Console/CommandManagerTest.php @@ -45,6 +45,8 @@ class CommandManagerTest extends TestCase private ?Metadata $metadata = null; private ?CommandManager $manager = null; + private $command; + protected function setUp() : void { $this->injectableFactory = $this->createMock(InjectableFactory::class); diff --git a/tests/unit/Espo/Core/Field/Currency/CurrencyConfigDataProviderTest.php b/tests/unit/Espo/Core/Field/Currency/CurrencyConfigDataProviderTest.php index 4a3528d67d..5159169fde 100644 --- a/tests/unit/Espo/Core/Field/Currency/CurrencyConfigDataProviderTest.php +++ b/tests/unit/Espo/Core/Field/Currency/CurrencyConfigDataProviderTest.php @@ -36,6 +36,9 @@ use RuntimeException; class CurrencyConfigDataProviderTest extends TestCase { + private $config; + private $provider; + protected function setUp() : void { $this->config = $this->createMock(Config::class); diff --git a/tests/unit/Espo/Core/Field/EmailAddress/EmailAddressGroupFactoryTest.php b/tests/unit/Espo/Core/Field/EmailAddress/EmailAddressGroupFactoryTest.php index 3c91bc26eb..4633a40ab0 100644 --- a/tests/unit/Espo/Core/Field/EmailAddress/EmailAddressGroupFactoryTest.php +++ b/tests/unit/Espo/Core/Field/EmailAddress/EmailAddressGroupFactoryTest.php @@ -29,32 +29,24 @@ namespace tests\unit\Espo\Core\Field\EmailAddress; -use Espo\Core\{ - Field\EmailAddress\EmailAddressGroupFactory, - Utils\Metadata, -}; +use Espo\Core\Field\EmailAddress\EmailAddressGroupFactory; +use Espo\Core\Utils\Metadata; -use Espo\ORM\{ - EntityManager, - Entity, -}; +use Espo\ORM\Entity; +use Espo\ORM\EntityManager; use Espo\Repositories\EmailAddress as EmailAddressRepository; +use PHPUnit\Framework\TestCase; use RuntimeException; -class EmailAddressGroupFactoryTest extends \PHPUnit\Framework\TestCase +class EmailAddressGroupFactoryTest extends TestCase { /** * @var Metadata */ private $metadata; - /** - * @var EntityManager - */ - private $entityManager; - /** * @var EmailAddressRepository */ @@ -69,13 +61,13 @@ class EmailAddressGroupFactoryTest extends \PHPUnit\Framework\TestCase { $this->metadata = $this->createMock(Metadata::class); - $this->entityManager = $this->createMock(EntityManager::class); + $entityManager = $this->createMock(EntityManager::class); $this->emailAddressRepository = $this->createMock(EmailAddressRepository::class); - $this->factory = new EmailAddressGroupFactory($this->metadata, $this->entityManager); + $this->factory = new EmailAddressGroupFactory($this->metadata, $entityManager); - $this->entityManager + $entityManager ->expects($this->any()) ->method('getRepository') ->with('EmailAddress') @@ -175,20 +167,20 @@ class EmailAddressGroupFactoryTest extends \PHPUnit\Framework\TestCase $entity ->method('has') - ->will( - $this->returnValueMap([ + ->willReturnMap( + [ ['testData', false], ['test', true], - ]) + ] ); $entity ->method('get') - ->will( - $this->returnValueMap([ + ->willReturnMap( + [ ['testData', null], ['test', 'ONE@test.com'], - ]) + ] ); $group = $this->factory->createFromEntity($entity, 'test'); @@ -294,20 +286,20 @@ class EmailAddressGroupFactoryTest extends \PHPUnit\Framework\TestCase $entity ->method('has') - ->will( - $this->returnValueMap([ + ->willReturnMap( + [ ['testData', false], ['test', true], - ]) + ] ); $entity ->method('get') - ->will( - $this->returnValueMap([ + ->willReturnMap( + [ ['testData', null], ['test', null], - ]) + ] ); $group = $this->factory->createFromEntity($entity, 'test'); diff --git a/tests/unit/Espo/Core/Field/PhoneNumber/PhoneNumberGroupFactoryTest.php b/tests/unit/Espo/Core/Field/PhoneNumber/PhoneNumberGroupFactoryTest.php index 9ecdf07f64..338fae2c6e 100644 --- a/tests/unit/Espo/Core/Field/PhoneNumber/PhoneNumberGroupFactoryTest.php +++ b/tests/unit/Espo/Core/Field/PhoneNumber/PhoneNumberGroupFactoryTest.php @@ -175,20 +175,20 @@ class PhoneNumberGroupFactoryTest extends \PHPUnit\Framework\TestCase $entity ->method('has') - ->will( - $this->returnValueMap([ + ->willReturnMap( + [ ['testData', false], ['test', true], - ]) + ] ); $entity ->method('get') - ->will( - $this->returnValueMap([ + ->willReturnMap( + [ ['testData', null], ['test', '+1'], - ]) + ] ); $group = $this->factory->createFromEntity($entity, 'test'); @@ -296,20 +296,20 @@ class PhoneNumberGroupFactoryTest extends \PHPUnit\Framework\TestCase $entity ->method('has') - ->will( - $this->returnValueMap([ + ->willReturnMap( + [ ['testData', false], ['test', true], - ]) + ] ); $entity ->method('get') - ->will( - $this->returnValueMap([ + ->willReturnMap( + [ ['testData', null], ['test', null], - ]) + ] ); $group = $this->factory->createFromEntity($entity, 'test'); diff --git a/tests/unit/Espo/Core/Formula/FormulaTest.php b/tests/unit/Espo/Core/Formula/FormulaTest.php index 2ef0ae5ac6..fcb17ad1a9 100644 --- a/tests/unit/Espo/Core/Formula/FormulaTest.php +++ b/tests/unit/Espo/Core/Formula/FormulaTest.php @@ -1,4 +1,5 @@ -entity = $this->getEntityMock(); - $this->entityManager = $this->getMockBuilder(EntityManager::class)->disableOriginalConstructor()->getMock(); - $this->repository = $this->getMockBuilder(DatabaseRepository::class)->disableOriginalConstructor()->getMock(); + $this->entityManager = $this->createMock(EntityManager::class); date_default_timezone_set('UTC'); - $this->dateTime = new DateTime(); + $dateTime = new DateTime(); - $this->number = new NumberUtil(); + $number = new NumberUtil(); - $this->config = $this->createMock(Config::class); - $this->config + $config = $this->createMock(Config::class); + $config ->expects($this->any()) ->method('get') - ->will($this->returnValueMap([ + ->willReturnMap([ ['timeZone', null, 'UTC'] - ])); + ]); $this->applicationConfig = $this->createMock(Config\ApplicationConfig::class); $this->applicationConfig @@ -83,29 +89,27 @@ class FormulaTest extends TestCase ->method('getTimeZone') ->willReturn('UTC'); - $this->user = $this->getMockBuilder(User::class)->disableOriginalConstructor()->getMock(); + $user = $this->createMock(User::class); + $log = $this->createMock(Log::class); - $this->log = $this->getMockBuilder(Log::class)->disableOriginalConstructor()->getMock(); + $user->set('id', '1'); - $this->user->set('id', '1'); - - $this->user + $user ->expects($this->any()) ->method('get') - ->will($this->returnValueMap([ + ->willReturnMap([ ['id', '1'] - ])); - + ]); $containerMocker = new ContainerMocker($this); $this->container = $containerMocker->create([ 'entityManager' => $this->entityManager, - 'dateTime' => $this->dateTime, - 'number' => $this->number, - 'config' => $this->config, - 'user' => $this->user, - 'log' => $this->log, + 'dateTime' => $dateTime, + 'number' => $number, + 'config' => $config, + 'user' => $user, + 'log' => $log, ]); } @@ -173,7 +177,7 @@ class FormulaTest extends TestCase $entity ->expects($this->any()) ->method('get') - ->will($this->returnValueMap($map)); + ->willReturnMap($map); } protected function setEntityFetchedAttributes($entity, $attributes) @@ -186,7 +190,7 @@ class FormulaTest extends TestCase $entity ->expects($this->any()) ->method('getFetched') - ->will($this->returnValueMap($map)); + ->willReturnMap($map); } function testAttribute() @@ -274,7 +278,7 @@ class FormulaTest extends TestCase $this->entity ->expects($this->once()) ->method('isAttributeChanged') - ->will($this->returnValue(true)); + ->willReturn(true); $result = $this->createProcessor()->process($item); @@ -302,7 +306,7 @@ class FormulaTest extends TestCase $this->entity ->expects($this->once()) ->method('isAttributeChanged') - ->will($this->returnValue(false)); + ->willReturn(false); $result = $this->createProcessor()->process($item); diff --git a/tests/unit/Espo/Core/Formula/ParserTest.php b/tests/unit/Espo/Core/Formula/ParserTest.php index b1cac3dda3..6373e2fb56 100644 --- a/tests/unit/Espo/Core/Formula/ParserTest.php +++ b/tests/unit/Espo/Core/Formula/ParserTest.php @@ -27,20 +27,26 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ +/** @noinspection PhpUnhandledExceptionInspection */ + namespace tests\unit\Espo\Core\Formula; use Espo\Core\Formula\Exceptions\SyntaxError; +use Espo\Core\Formula\Parser; use Espo\Core\Formula\Parser\Ast\Attribute; use Espo\Core\Formula\Parser\Ast\Node; use Espo\Core\Formula\Parser\Ast\Value; use Espo\Core\Formula\Parser\Ast\Variable; +use PHPUnit\Framework\TestCase; use stdClass; -class ParserTest extends \PHPUnit\Framework\TestCase +class ParserTest extends TestCase { + private $parser; + protected function setUp() : void { - $this->parser = new \Espo\Core\Formula\Parser(); + $this->parser = new Parser(); } private function parse(string $expression): stdClass diff --git a/tests/unit/Espo/Core/HookManagerTest.php b/tests/unit/Espo/Core/HookManagerTest.php index 35d0c8cd01..d51e94768e 100644 --- a/tests/unit/Espo/Core/HookManagerTest.php +++ b/tests/unit/Espo/Core/HookManagerTest.php @@ -44,12 +44,14 @@ use Espo\Core\Utils\Module\PathProvider; class HookManagerTest extends TestCase { - private $hookManager; - private $filesPath = 'tests/unit/testData/Hooks'; private ?Config\SystemConfig $systemConfig = null; + private $pathProvider; + private $reflection; + private $metadata; + protected function setUp(): void { $this->metadata = $this->createMock(Metadata::class); @@ -57,24 +59,24 @@ class HookManagerTest extends TestCase $this->systemConfig = $this->createMock(Config\SystemConfig::class); - $this->injectableFactory = $this->createMock(InjectableFactory::class); - $this->dataCache = $this->createMock(DataCache::class); - $this->fileManager = new FileManager(); + $injectableFactory = $this->createMock(InjectableFactory::class); + $dataCache = $this->createMock(DataCache::class); + $fileManager = new FileManager(); $this->pathProvider = $this->createMock(PathProvider::class); - $this->generalInvoker = $this->createMock(GeneralInvoker::class); + $generalInvoker = $this->createMock(GeneralInvoker::class); - $this->hookManager = new HookManager( - $this->injectableFactory, - $this->fileManager, + $hookManager = new HookManager( + $injectableFactory, + $fileManager, $this->metadata, - $this->dataCache, + $dataCache, $this->createMock(Log::class), $this->pathProvider, - $this->generalInvoker, + $generalInvoker, $this->systemConfig, ); - $this->reflection = new ReflectionHelper($this->hookManager); + $this->reflection = new ReflectionHelper($hookManager); } private function initPathProvider(string $folder): void @@ -260,21 +262,21 @@ class HookManagerTest extends TestCase $this->systemConfig ->expects($this->exactly(2)) ->method('useCache') - ->will($this->returnValue(false)); + ->willReturn(false); $this->metadata ->expects($this->once()) ->method('getModuleList') - ->will($this->returnValue(array( + ->willReturn([ 'Crm', 'Test', - ))); + ]); $this->reflection->invokeMethod('loadHooks'); - $result = array ( + $result = [ 'Note' => - array ( + [ 'beforeSave' => [ [ @@ -282,8 +284,8 @@ class HookManagerTest extends TestCase 'order' => 7, ], ], - ), - ); + ], + ]; $this->assertEquals($result, $this->reflection->getProperty('data')); } @@ -295,31 +297,31 @@ class HookManagerTest extends TestCase $this->systemConfig ->expects($this->exactly(2)) ->method('useCache') - ->will($this->returnValue(false)); + ->willReturn(false); $this->metadata ->expects($this->once()) ->method('getModuleList') - ->will($this->returnValue(array( + ->willReturn([ 'Crm', 'Test', - ))); + ]); $this->reflection->invokeMethod('loadHooks'); - $result = array ( + $result = [ 'Note' => - array ( + [ 'beforeSave' => - array ( - array ( + [ + [ 'className' => 'tests\\unit\\testData\\Hooks\\testCase2\\application\\Espo\\Modules\\Crm\\Hooks\\Note\\Mentions', 'order' => 9, - ), - ), - ), - ); + ], + ], + ], + ]; $this->assertEquals($result, $this->reflection->getProperty('data')); } @@ -331,31 +333,31 @@ class HookManagerTest extends TestCase $this->systemConfig ->expects($this->exactly(2)) ->method('useCache') - ->will($this->returnValue(false)); + ->willReturn(false); $this->metadata ->expects($this->once()) ->method('getModuleList') - ->will($this->returnValue(array( + ->willReturn([ 'Test', 'Crm', - ))); + ]); $this->reflection->invokeMethod('loadHooks'); - $result = array ( + $result = [ 'Note' => - array ( + [ 'beforeSave' => - array ( - array ( + [ + [ 'className' => 'tests\\unit\\testData\\Hooks\\testCase2\\application\\Espo\\Modules\\Test\\Hooks\\Note\\Mentions', 'order' => 9, - ), - ), - ), - ); + ], + ], + ], + ]; $this->assertEquals($result, $this->reflection->getProperty('data')); } @@ -367,13 +369,12 @@ class HookManagerTest extends TestCase $this->systemConfig ->expects($this->exactly(2)) ->method('useCache') - ->will($this->returnValue(false)); + ->willReturn(false); $this->metadata ->expects($this->once()) ->method('getModuleList') - ->will($this->returnValue(array( - ))); + ->willReturn([]); $this->reflection->invokeMethod('loadHooks'); diff --git a/tests/unit/Espo/Core/Job/QueuePortionNumberProviderTest.php b/tests/unit/Espo/Core/Job/QueuePortionNumberProviderTest.php index 6c1d7ec665..ab6b7e7613 100644 --- a/tests/unit/Espo/Core/Job/QueuePortionNumberProviderTest.php +++ b/tests/unit/Espo/Core/Job/QueuePortionNumberProviderTest.php @@ -29,13 +29,12 @@ namespace tests\unit\Espo\Core\Job; -use Espo\Core\{ - Job\QueuePortionNumberProvider, - Job\QueueName, - Utils\Config, -}; +use Espo\Core\Job\QueueName; +use Espo\Core\Job\QueuePortionNumberProvider; +use Espo\Core\Utils\Config; +use PHPUnit\Framework\TestCase; -class QueuePortionNumberProviderTest extends \PHPUnit\Framework\TestCase +class QueuePortionNumberProviderTest extends TestCase { private $config; @@ -58,13 +57,13 @@ class QueuePortionNumberProviderTest extends \PHPUnit\Framework\TestCase { $this->config ->method('get') - ->will( - $this->returnValueMap([ + ->willReturnMap( + [ ['jobQ0MaxPortion', null, 201], ['jobQ1MaxPortion', null, 501], ['jobE0MaxPortion', null, 101], ['jobTestDefaultMaxPortion', null, 301] - ]) + ] ); $provider = new QueuePortionNumberProvider($this->config); diff --git a/tests/unit/Espo/Core/Log/HandlerListLoaderTest.php b/tests/unit/Espo/Core/Log/HandlerListLoaderTest.php index e57bbd7752..53197a467b 100644 --- a/tests/unit/Espo/Core/Log/HandlerListLoaderTest.php +++ b/tests/unit/Espo/Core/Log/HandlerListLoaderTest.php @@ -36,10 +36,11 @@ use Espo\Core\Log\Handler\EspoRotatingFileHandler; use Espo\Core\Log\HandlerListLoader; use PHPUnit\Framework\TestCase; -use Psr\Log\LogLevel; class HandlerListLoaderTest extends TestCase { + private $injectableFactory; + protected function setUp() : void { $this->injectableFactory = $this->getMockBuilder(InjectableFactory::class) diff --git a/tests/unit/Espo/Core/Mail/FiltersMatcherTest.php b/tests/unit/Espo/Core/Mail/FiltersMatcherTest.php index e46274c71a..54fa2f184d 100644 --- a/tests/unit/Espo/Core/Mail/FiltersMatcherTest.php +++ b/tests/unit/Espo/Core/Mail/FiltersMatcherTest.php @@ -33,15 +33,18 @@ use Espo\Entities\Email; use Espo\Entities\EmailFilter; use Espo\Core\Mail\FiltersMatcher; use Espo\ORM\EntityManager; +use PHPUnit\Framework\TestCase; -class FiltersMatcherTest extends \PHPUnit\Framework\TestCase +class FiltersMatcherTest extends TestCase { private $object; + private $entityManager; + private $emailDefs; + private $filterDefs; protected function setUp() : void { $this->object = new FiltersMatcher(); - $this->entityManager = $this->createMock(EntityManager::class); $this->emailDefs = [ diff --git a/tests/unit/Espo/Core/Mail/ImporterTest.php b/tests/unit/Espo/Core/Mail/ImporterTest.php index 11fb039e1a..0d5fa0d3de 100644 --- a/tests/unit/Espo/Core/Mail/ImporterTest.php +++ b/tests/unit/Espo/Core/Mail/ImporterTest.php @@ -29,11 +29,11 @@ namespace tests\unit\Espo\Core\Mail; -use Espo\Entities\Attachment; use Espo\Entities\Email; use Espo\Core\Notification\AssignmentNotificator; +use Espo\ORM\Metadata; use Espo\ORM\Value\ValueAccessor; use Espo\ORM\Value\ValueAccessorFactory; use Espo\Core\FieldProcessing\Relation\LinkMultipleSaver; @@ -47,14 +47,23 @@ use Espo\Core\Notification\AssignmentNotificatorFactory; use Espo\Core\ORM\EntityManager; use Espo\Core\Repositories\Database; use Espo\Core\Utils\Config; -use Espo\Core\Utils\Metadata; use Espo\ORM\Repository\RDBSelectBuilder; use PHPUnit\Framework\TestCase; class ImporterTest extends TestCase { - protected $emailRepository; + private $emailRepository; + private $config; + private $assignmentNotificatorFactory; + private $parserFactory; + private $linkMultipleSaver; + private $parentFinder; + private $jobSchedulerFactory; + private $duplicateFinder; + private $email; + private $repositoryMap; + private $entityManager; protected function setUp(): void { @@ -78,38 +87,36 @@ class ImporterTest extends TestCase $this->parserFactory ->expects($this->any()) ->method('create') - ->will( - $this->returnCallback( - function () { - return new MailMimeParser($this->entityManager); - } - ) + ->willReturnCallback( + function () { + return new MailMimeParser($this->entityManager); + } ); $emailRepository ->expects($this->any()) ->method('where') - ->will($this->returnValue($selectBuilder)); + ->willReturn($selectBuilder); $emailRepository ->expects($this->any()) ->method('select') - ->will($this->returnValue($selectBuilder)); + ->willReturn($selectBuilder); $entityManager ->expects($this->any()) ->method('getMetadata') - ->will($this->returnValue($metadata)); + ->willReturn($metadata); $metadata ->expects($this->any()) ->method('get') - ->will($this->returnValue(null)); + ->willReturn(null); $emptyRepository ->expects($this->any()) ->method('where') - ->will($this->returnValue($selectBuilder)); + ->willReturn($selectBuilder); $this->emailRepository = $emailRepository; @@ -131,12 +138,10 @@ class ImporterTest extends TestCase ); $emailDefs = require('tests/unit/testData/Core/Mail/email_defs.php'); - $attachmentDefs = require('tests/unit/testData/Core/Mail/attachment_defs.php'); + //$attachmentDefs = require('tests/unit/testData/Core/Mail/attachment_defs.php'); $this->email = new Email('Email', $emailDefs, $entityManager, $valueAccessorFactory); - $attachment = new Attachment('Attachment', $attachmentDefs, $entityManager, $valueAccessorFactory); - - $this->attachment = $attachment; + //$attachment = new Attachment('Attachment', $attachmentDefs, $entityManager, $valueAccessorFactory); $this->assignmentNotificatorFactory ->expects($this->any()) @@ -160,7 +165,7 @@ class ImporterTest extends TestCase $entityManager ->expects($this->any()) ->method('getRDBRepositoryByClass') - ->will($this->returnValueMap($this->repositoryMap)); + ->willReturnMap($this->repositoryMap); $entityManager ->expects($this->exactly(2)) @@ -173,15 +178,15 @@ class ImporterTest extends TestCase $this->emailRepository ->expects($this->once()) ->method('getNew') - ->will($this->returnValue($email)); + ->willReturn($email); $config ->expects($this->any()) ->method('get') - ->will( - $this->returnValueMap([ + ->willReturnMap( + [ ['b2cMode', false] - ]) + ] ); $contents = file_get_contents('tests/unit/testData/Core/Mail/test_email_1.eml'); @@ -208,10 +213,6 @@ class ImporterTest extends TestCase $this->assertEquals('test 3', $email->get('name')); - //$teamIdList = $email->getLinkMultipleIdList('teams'); - - //$this->assertTrue(in_array('teamTestId', $teamIdList)); - $userIdList = $email->getLinkMultipleIdList('users'); $this->assertTrue(in_array('userTestId', $userIdList)); diff --git a/tests/unit/Espo/Core/Record/CreateParamsFetcherTest.php b/tests/unit/Espo/Core/Record/CreateParamsFetcherTest.php index 46cf43c73d..330d44bdec 100644 --- a/tests/unit/Espo/Core/Record/CreateParamsFetcherTest.php +++ b/tests/unit/Espo/Core/Record/CreateParamsFetcherTest.php @@ -31,8 +31,9 @@ namespace tests\unit\Espo\Core\Record; use Espo\Core\Record\CreateParamsFetcher; use Espo\Core\Api\RequestWrapper; +use PHPUnit\Framework\TestCase; -class CreateParamsFetcherTest extends \PHPUnit\Framework\TestCase +class CreateParamsFetcherTest extends TestCase { public function test1(): void { @@ -45,11 +46,11 @@ class CreateParamsFetcherTest extends \PHPUnit\Framework\TestCase $request ->method('getHeader') - ->will( - $this->returnValueMap([ + ->willReturnMap( + [ ['X-Skip-Duplicate-Check', 'true'], ['X-Duplicate-Source-Id', null], - ]) + ] ); $params = (new CreateParamsFetcher())->fetch($request); @@ -67,11 +68,11 @@ class CreateParamsFetcherTest extends \PHPUnit\Framework\TestCase $request ->method('getHeader') - ->will( - $this->returnValueMap([ + ->willReturnMap( + [ ['X-Skip-Duplicate-Check', 'false'], ['X-Duplicate-Source-Id', null], - ]) + ] ); $params = (new CreateParamsFetcher())->fetch($request); @@ -102,11 +103,11 @@ class CreateParamsFetcherTest extends \PHPUnit\Framework\TestCase $request ->method('getHeader') - ->will( - $this->returnValueMap([ + ->willReturnMap( + [ ['X-Skip-Duplicate-Check', 'TRUE'], ['X-Duplicate-Source-Id', null], - ]) + ] ); $params = (new CreateParamsFetcher())->fetch($request); diff --git a/tests/unit/Espo/Core/Record/SearchParamsFetcherTest.php b/tests/unit/Espo/Core/Record/SearchParamsFetcherTest.php index 8aa69b906b..b0ac737db8 100644 --- a/tests/unit/Espo/Core/Record/SearchParamsFetcherTest.php +++ b/tests/unit/Espo/Core/Record/SearchParamsFetcherTest.php @@ -35,11 +35,13 @@ use Espo\Core\Api\RequestWrapper; use Espo\Core\Utils\Config; use Espo\Core\Select\Text\MetadataProvider as TextMetadataProvider; +use PHPUnit\Framework\TestCase; use Slim\Psr7\Factory\RequestFactory; -class SearchParamsFetcherTest extends \PHPUnit\Framework\TestCase +class SearchParamsFetcherTest extends TestCase { private $config; + private $textMetadataProvider; protected function setUp(): void {