1
0

ManagerTest.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
  4. *
  5. * @license GNU AGPL version 3 or any later version
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as
  9. * published by the Free Software Foundation, either version 3 of the
  10. * License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. namespace OCA\WorkflowEngine\Tests;
  22. use OC\L10N\L10N;
  23. use OCA\WorkflowEngine\Entity\File;
  24. use OCA\WorkflowEngine\Helper\ScopeContext;
  25. use OCA\WorkflowEngine\Manager;
  26. use OCP\EventDispatcher\IEventDispatcher;
  27. use OCP\Files\IRootFolder;
  28. use OCP\IConfig;
  29. use OCP\IDBConnection;
  30. use OCP\IL10N;
  31. use OCP\ILogger;
  32. use OCP\IServerContainer;
  33. use OCP\IURLGenerator;
  34. use OCP\IUserManager;
  35. use OCP\IUserSession;
  36. use OCP\SystemTag\ISystemTagManager;
  37. use OCP\WorkflowEngine\ICheck;
  38. use OCP\WorkflowEngine\IEntity;
  39. use OCP\WorkflowEngine\IEntityEvent;
  40. use OCP\WorkflowEngine\IManager;
  41. use OCP\WorkflowEngine\IOperation;
  42. use PHPUnit\Framework\MockObject\MockObject;
  43. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  44. use Test\TestCase;
  45. /**
  46. * Class ManagerTest
  47. *
  48. * @package OCA\WorkflowEngine\Tests
  49. * @group DB
  50. */
  51. class ManagerTest extends TestCase {
  52. /** @var Manager */
  53. protected $manager;
  54. /** @var MockObject|IDBConnection */
  55. protected $db;
  56. /** @var \PHPUnit\Framework\MockObject\MockObject|ILogger */
  57. protected $logger;
  58. /** @var \PHPUnit\Framework\MockObject\MockObject|EventDispatcherInterface */
  59. protected $legacyDispatcher;
  60. /** @var MockObject|IServerContainer */
  61. protected $container;
  62. /** @var MockObject|IUserSession */
  63. protected $session;
  64. /** @var MockObject|L10N */
  65. protected $l;
  66. /** @var MockObject|IEventDispatcher */
  67. protected $dispatcher;
  68. /** @var MockObject|IConfig */
  69. protected $config;
  70. protected function setUp(): void {
  71. parent::setUp();
  72. $this->db = \OC::$server->getDatabaseConnection();
  73. $this->container = $this->createMock(IServerContainer::class);
  74. /** @var IL10N|MockObject $l */
  75. $this->l = $this->createMock(IL10N::class);
  76. $this->l->method('t')
  77. ->willReturnCallback(function ($text, $parameters = []) {
  78. return vsprintf($text, $parameters);
  79. });
  80. $this->legacyDispatcher = $this->createMock(EventDispatcherInterface::class);
  81. $this->logger = $this->createMock(ILogger::class);
  82. $this->session = $this->createMock(IUserSession::class);
  83. $this->dispatcher = $this->createMock(IEventDispatcher::class);
  84. $this->config = $this->createMock(IConfig::class);
  85. $this->manager = new Manager(
  86. \OC::$server->getDatabaseConnection(),
  87. $this->container,
  88. $this->l,
  89. $this->legacyDispatcher,
  90. $this->logger,
  91. $this->session,
  92. $this->dispatcher,
  93. $this->config
  94. );
  95. $this->clearTables();
  96. }
  97. protected function tearDown(): void {
  98. $this->clearTables();
  99. parent::tearDown();
  100. }
  101. /**
  102. * @return MockObject|ScopeContext
  103. */
  104. protected function buildScope(string $scopeId = null): MockObject {
  105. $scopeContext = $this->createMock(ScopeContext::class);
  106. $scopeContext->expects($this->any())
  107. ->method('getScope')
  108. ->willReturn($scopeId ? IManager::SCOPE_USER : IManager::SCOPE_ADMIN);
  109. $scopeContext->expects($this->any())
  110. ->method('getScopeId')
  111. ->willReturn($scopeId ?? '');
  112. $scopeContext->expects($this->any())
  113. ->method('getHash')
  114. ->willReturn(md5($scopeId ?? ''));
  115. return $scopeContext;
  116. }
  117. public function clearTables() {
  118. $query = $this->db->getQueryBuilder();
  119. foreach (['flow_checks', 'flow_operations', 'flow_operations_scope'] as $table) {
  120. $query->delete($table)
  121. ->execute();
  122. }
  123. }
  124. public function testChecks() {
  125. $check1 = $this->invokePrivate($this->manager, 'addCheck', ['Test', 'equal', 1]);
  126. $check2 = $this->invokePrivate($this->manager, 'addCheck', ['Test', '!equal', 2]);
  127. $data = $this->manager->getChecks([$check1]);
  128. $this->assertArrayHasKey($check1, $data);
  129. $this->assertArrayNotHasKey($check2, $data);
  130. $data = $this->manager->getChecks([$check1, $check2]);
  131. $this->assertArrayHasKey($check1, $data);
  132. $this->assertArrayHasKey($check2, $data);
  133. $data = $this->manager->getChecks([$check2, $check1]);
  134. $this->assertArrayHasKey($check1, $data);
  135. $this->assertArrayHasKey($check2, $data);
  136. $data = $this->manager->getChecks([$check2]);
  137. $this->assertArrayNotHasKey($check1, $data);
  138. $this->assertArrayHasKey($check2, $data);
  139. }
  140. public function testScope() {
  141. $adminScope = $this->buildScope();
  142. $userScope = $this->buildScope('jackie');
  143. $entity = File::class;
  144. $opId1 = $this->invokePrivate(
  145. $this->manager,
  146. 'insertOperation',
  147. ['OCA\WFE\TestOp', 'Test01', [11, 22], 'foo', $entity, []]
  148. );
  149. $this->invokePrivate($this->manager, 'addScope', [$opId1, $adminScope]);
  150. $opId2 = $this->invokePrivate(
  151. $this->manager,
  152. 'insertOperation',
  153. ['OCA\WFE\TestOp', 'Test02', [33, 22], 'bar', $entity, []]
  154. );
  155. $this->invokePrivate($this->manager, 'addScope', [$opId2, $userScope]);
  156. $opId3 = $this->invokePrivate(
  157. $this->manager,
  158. 'insertOperation',
  159. ['OCA\WFE\TestOp', 'Test03', [11, 44], 'foobar', $entity, []]
  160. );
  161. $this->invokePrivate($this->manager, 'addScope', [$opId3, $userScope]);
  162. $this->assertTrue($this->invokePrivate($this->manager, 'canModify', [$opId1, $adminScope]));
  163. $this->assertFalse($this->invokePrivate($this->manager, 'canModify', [$opId2, $adminScope]));
  164. $this->assertFalse($this->invokePrivate($this->manager, 'canModify', [$opId3, $adminScope]));
  165. $this->assertFalse($this->invokePrivate($this->manager, 'canModify', [$opId1, $userScope]));
  166. $this->assertTrue($this->invokePrivate($this->manager, 'canModify', [$opId2, $userScope]));
  167. $this->assertTrue($this->invokePrivate($this->manager, 'canModify', [$opId3, $userScope]));
  168. }
  169. public function testGetAllOperations() {
  170. $adminScope = $this->buildScope();
  171. $userScope = $this->buildScope('jackie');
  172. $entity = File::class;
  173. $opId1 = $this->invokePrivate(
  174. $this->manager,
  175. 'insertOperation',
  176. ['OCA\WFE\TestAdminOp', 'Test01', [11, 22], 'foo', $entity, []]
  177. );
  178. $this->invokePrivate($this->manager, 'addScope', [$opId1, $adminScope]);
  179. $opId2 = $this->invokePrivate(
  180. $this->manager,
  181. 'insertOperation',
  182. ['OCA\WFE\TestUserOp', 'Test02', [33, 22], 'bar', $entity, []]
  183. );
  184. $this->invokePrivate($this->manager, 'addScope', [$opId2, $userScope]);
  185. $opId3 = $this->invokePrivate(
  186. $this->manager,
  187. 'insertOperation',
  188. ['OCA\WFE\TestUserOp', 'Test03', [11, 44], 'foobar', $entity, []]
  189. );
  190. $this->invokePrivate($this->manager, 'addScope', [$opId3, $userScope]);
  191. $adminOps = $this->manager->getAllOperations($adminScope);
  192. $userOps = $this->manager->getAllOperations($userScope);
  193. $this->assertSame(1, count($adminOps));
  194. $this->assertTrue(array_key_exists('OCA\WFE\TestAdminOp', $adminOps));
  195. $this->assertFalse(array_key_exists('OCA\WFE\TestUserOp', $adminOps));
  196. $this->assertSame(1, count($userOps));
  197. $this->assertFalse(array_key_exists('OCA\WFE\TestAdminOp', $userOps));
  198. $this->assertTrue(array_key_exists('OCA\WFE\TestUserOp', $userOps));
  199. $this->assertSame(2, count($userOps['OCA\WFE\TestUserOp']));
  200. }
  201. public function testGetOperations() {
  202. $adminScope = $this->buildScope();
  203. $userScope = $this->buildScope('jackie');
  204. $entity = File::class;
  205. $opId1 = $this->invokePrivate(
  206. $this->manager,
  207. 'insertOperation',
  208. ['OCA\WFE\TestOp', 'Test01', [11, 22], 'foo', $entity, []]
  209. );
  210. $this->invokePrivate($this->manager, 'addScope', [$opId1, $adminScope]);
  211. $opId4 = $this->invokePrivate(
  212. $this->manager,
  213. 'insertOperation',
  214. ['OCA\WFE\OtherTestOp', 'Test04', [5], 'foo', $entity, []]
  215. );
  216. $this->invokePrivate($this->manager, 'addScope', [$opId4, $adminScope]);
  217. $opId2 = $this->invokePrivate(
  218. $this->manager,
  219. 'insertOperation',
  220. ['OCA\WFE\TestOp', 'Test02', [33, 22], 'bar', $entity, []]
  221. );
  222. $this->invokePrivate($this->manager, 'addScope', [$opId2, $userScope]);
  223. $opId3 = $this->invokePrivate(
  224. $this->manager,
  225. 'insertOperation',
  226. ['OCA\WFE\TestOp', 'Test03', [11, 44], 'foobar', $entity, []]
  227. );
  228. $this->invokePrivate($this->manager, 'addScope', [$opId3, $userScope]);
  229. $opId5 = $this->invokePrivate(
  230. $this->manager,
  231. 'insertOperation',
  232. ['OCA\WFE\OtherTestOp', 'Test05', [5], 'foobar', $entity, []]
  233. );
  234. $this->invokePrivate($this->manager, 'addScope', [$opId5, $userScope]);
  235. $adminOps = $this->manager->getOperations('OCA\WFE\TestOp', $adminScope);
  236. $userOps = $this->manager->getOperations('OCA\WFE\TestOp', $userScope);
  237. $this->assertSame(1, count($adminOps));
  238. array_walk($adminOps, function ($op) {
  239. $this->assertTrue($op['class'] === 'OCA\WFE\TestOp');
  240. });
  241. $this->assertSame(2, count($userOps));
  242. array_walk($userOps, function ($op) {
  243. $this->assertTrue($op['class'] === 'OCA\WFE\TestOp');
  244. });
  245. }
  246. public function testUpdateOperation() {
  247. $adminScope = $this->buildScope();
  248. $userScope = $this->buildScope('jackie');
  249. $entity = File::class;
  250. $this->container->expects($this->any())
  251. ->method('query')
  252. ->willReturnCallback(function ($class) {
  253. if (substr($class, -2) === 'Op') {
  254. return $this->createMock(IOperation::class);
  255. } elseif ($class === File::class) {
  256. return $this->getMockBuilder(File::class)
  257. ->setConstructorArgs([
  258. $this->l,
  259. $this->createMock(IURLGenerator::class),
  260. $this->createMock(IRootFolder::class),
  261. $this->createMock(ILogger::class),
  262. $this->createMock(\OCP\Share\IManager::class),
  263. $this->createMock(IUserSession::class),
  264. $this->createMock(ISystemTagManager::class),
  265. $this->createMock(IUserManager::class),
  266. ])
  267. ->setMethodsExcept(['getEvents'])
  268. ->getMock();
  269. }
  270. return $this->createMock(ICheck::class);
  271. });
  272. $opId1 = $this->invokePrivate(
  273. $this->manager,
  274. 'insertOperation',
  275. ['OCA\WFE\TestAdminOp', 'Test01', [11, 22], 'foo', $entity, []]
  276. );
  277. $this->invokePrivate($this->manager, 'addScope', [$opId1, $adminScope]);
  278. $opId2 = $this->invokePrivate(
  279. $this->manager,
  280. 'insertOperation',
  281. ['OCA\WFE\TestUserOp', 'Test02', [33, 22], 'bar', $entity, []]
  282. );
  283. $this->invokePrivate($this->manager, 'addScope', [$opId2, $userScope]);
  284. $check1 = ['class' => 'OCA\WFE\C22', 'operator' => 'eq', 'value' => 'asdf'];
  285. $check2 = ['class' => 'OCA\WFE\C33', 'operator' => 'eq', 'value' => 23456];
  286. /** @noinspection PhpUnhandledExceptionInspection */
  287. $op = $this->manager->updateOperation($opId1, 'Test01a', [$check1, $check2], 'foohur', $adminScope, $entity, ['\OCP\Files::postDelete']);
  288. $this->assertSame('Test01a', $op['name']);
  289. $this->assertSame('foohur', $op['operation']);
  290. /** @noinspection PhpUnhandledExceptionInspection */
  291. $op = $this->manager->updateOperation($opId2, 'Test02a', [$check1], 'barfoo', $userScope, $entity, ['\OCP\Files::postDelete']);
  292. $this->assertSame('Test02a', $op['name']);
  293. $this->assertSame('barfoo', $op['operation']);
  294. foreach ([[$adminScope, $opId2], [$userScope, $opId1]] as $run) {
  295. try {
  296. /** @noinspection PhpUnhandledExceptionInspection */
  297. $this->manager->updateOperation($run[1], 'Evil', [$check2], 'hackx0r', $run[0], $entity, []);
  298. $this->assertTrue(false, 'DomainException not thrown');
  299. } catch (\DomainException $e) {
  300. $this->assertTrue(true);
  301. }
  302. }
  303. }
  304. public function testDeleteOperation() {
  305. $adminScope = $this->buildScope();
  306. $userScope = $this->buildScope('jackie');
  307. $entity = File::class;
  308. $opId1 = $this->invokePrivate(
  309. $this->manager,
  310. 'insertOperation',
  311. ['OCA\WFE\TestAdminOp', 'Test01', [11, 22], 'foo', $entity, []]
  312. );
  313. $this->invokePrivate($this->manager, 'addScope', [$opId1, $adminScope]);
  314. $opId2 = $this->invokePrivate(
  315. $this->manager,
  316. 'insertOperation',
  317. ['OCA\WFE\TestUserOp', 'Test02', [33, 22], 'bar', $entity, []]
  318. );
  319. $this->invokePrivate($this->manager, 'addScope', [$opId2, $userScope]);
  320. foreach ([[$adminScope, $opId2], [$userScope, $opId1]] as $run) {
  321. try {
  322. /** @noinspection PhpUnhandledExceptionInspection */
  323. $this->manager->deleteOperation($run[1], $run[0]);
  324. $this->assertTrue(false, 'DomainException not thrown');
  325. } catch (\Exception $e) {
  326. $this->assertInstanceOf(\DomainException::class, $e);
  327. }
  328. }
  329. /** @noinspection PhpUnhandledExceptionInspection */
  330. $this->manager->deleteOperation($opId1, $adminScope);
  331. /** @noinspection PhpUnhandledExceptionInspection */
  332. $this->manager->deleteOperation($opId2, $userScope);
  333. foreach ([$opId1, $opId2] as $opId) {
  334. try {
  335. $this->invokePrivate($this->manager, 'getOperation', [$opId]);
  336. $this->assertTrue(false, 'UnexpectedValueException not thrown');
  337. } catch (\Exception $e) {
  338. $this->assertInstanceOf(\UnexpectedValueException::class, $e);
  339. }
  340. }
  341. }
  342. public function testGetEntitiesListBuildInOnly() {
  343. $fileEntityMock = $this->createMock(File::class);
  344. $this->container->expects($this->once())
  345. ->method('query')
  346. ->with(File::class)
  347. ->willReturn($fileEntityMock);
  348. $entities = $this->manager->getEntitiesList();
  349. $this->assertCount(1, $entities);
  350. $this->assertInstanceOf(IEntity::class, $entities[0]);
  351. }
  352. public function testGetEntitiesList() {
  353. $fileEntityMock = $this->createMock(File::class);
  354. $this->container->expects($this->once())
  355. ->method('query')
  356. ->with(File::class)
  357. ->willReturn($fileEntityMock);
  358. /** @var MockObject|IEntity $extraEntity */
  359. $extraEntity = $this->createMock(IEntity::class);
  360. $this->legacyDispatcher->expects($this->once())
  361. ->method('dispatch')
  362. ->with('OCP\WorkflowEngine::registerEntities', $this->anything())
  363. ->willReturnCallback(function () use ($extraEntity) {
  364. $this->manager->registerEntity($extraEntity);
  365. });
  366. $entities = $this->manager->getEntitiesList();
  367. $this->assertCount(2, $entities);
  368. $entityTypeCounts = array_reduce($entities, function (array $carry, IEntity $entity) {
  369. if ($entity instanceof File) {
  370. $carry[0]++;
  371. } elseif ($entity instanceof IEntity) {
  372. $carry[1]++;
  373. }
  374. return $carry;
  375. }, [0, 0]);
  376. $this->assertSame(1, $entityTypeCounts[0]);
  377. $this->assertSame(1, $entityTypeCounts[1]);
  378. }
  379. public function testValidateOperationOK() {
  380. $check = [
  381. 'class' => ICheck::class,
  382. 'operator' => 'is',
  383. 'value' => 'barfoo',
  384. ];
  385. $operationMock = $this->createMock(IOperation::class);
  386. $entityMock = $this->createMock(IEntity::class);
  387. $eventEntityMock = $this->createMock(IEntityEvent::class);
  388. $checkMock = $this->createMock(ICheck::class);
  389. $operationMock->expects($this->once())
  390. ->method('validateOperation')
  391. ->with('test', [$check], 'operationData');
  392. $entityMock->expects($this->any())
  393. ->method('getEvents')
  394. ->willReturn([$eventEntityMock]);
  395. $eventEntityMock->expects($this->any())
  396. ->method('getEventName')
  397. ->willReturn('MyEvent');
  398. $checkMock->expects($this->any())
  399. ->method('supportedEntities')
  400. ->willReturn([IEntity::class]);
  401. $checkMock->expects($this->atLeastOnce())
  402. ->method('validateCheck');
  403. $this->container->expects($this->any())
  404. ->method('query')
  405. ->willReturnCallback(function ($className) use ($operationMock, $entityMock, $eventEntityMock, $checkMock) {
  406. switch ($className) {
  407. case IOperation::class:
  408. return $operationMock;
  409. case IEntity::class:
  410. return $entityMock;
  411. case IEntityEvent::class:
  412. return $eventEntityMock;
  413. case ICheck::class:
  414. return $checkMock;
  415. default:
  416. return $this->createMock($className);
  417. }
  418. });
  419. $this->manager->validateOperation(IOperation::class, 'test', [$check], 'operationData', IEntity::class, ['MyEvent']);
  420. }
  421. public function testValidateOperationCheckInputLengthError() {
  422. $check = [
  423. 'class' => ICheck::class,
  424. 'operator' => 'is',
  425. 'value' => str_pad('', IManager::MAX_CHECK_VALUE_BYTES + 1, 'FooBar'),
  426. ];
  427. $operationMock = $this->createMock(IOperation::class);
  428. $entityMock = $this->createMock(IEntity::class);
  429. $eventEntityMock = $this->createMock(IEntityEvent::class);
  430. $checkMock = $this->createMock(ICheck::class);
  431. $operationMock->expects($this->once())
  432. ->method('validateOperation')
  433. ->with('test', [$check], 'operationData');
  434. $entityMock->expects($this->any())
  435. ->method('getEvents')
  436. ->willReturn([$eventEntityMock]);
  437. $eventEntityMock->expects($this->any())
  438. ->method('getEventName')
  439. ->willReturn('MyEvent');
  440. $checkMock->expects($this->any())
  441. ->method('supportedEntities')
  442. ->willReturn([IEntity::class]);
  443. $checkMock->expects($this->never())
  444. ->method('validateCheck');
  445. $this->container->expects($this->any())
  446. ->method('query')
  447. ->willReturnCallback(function ($className) use ($operationMock, $entityMock, $eventEntityMock, $checkMock) {
  448. switch ($className) {
  449. case IOperation::class:
  450. return $operationMock;
  451. case IEntity::class:
  452. return $entityMock;
  453. case IEntityEvent::class:
  454. return $eventEntityMock;
  455. case ICheck::class:
  456. return $checkMock;
  457. default:
  458. return $this->createMock($className);
  459. }
  460. });
  461. try {
  462. $this->manager->validateOperation(IOperation::class, 'test', [$check], 'operationData', IEntity::class, ['MyEvent']);
  463. } catch (\UnexpectedValueException $e) {
  464. $this->assertSame('The provided check value is too long', $e->getMessage());
  465. }
  466. }
  467. public function testValidateOperationDataLengthError() {
  468. $check = [
  469. 'class' => ICheck::class,
  470. 'operator' => 'is',
  471. 'value' => 'barfoo',
  472. ];
  473. $operationData = str_pad('', IManager::MAX_OPERATION_VALUE_BYTES + 1, 'FooBar');
  474. $operationMock = $this->createMock(IOperation::class);
  475. $entityMock = $this->createMock(IEntity::class);
  476. $eventEntityMock = $this->createMock(IEntityEvent::class);
  477. $checkMock = $this->createMock(ICheck::class);
  478. $operationMock->expects($this->never())
  479. ->method('validateOperation');
  480. $entityMock->expects($this->any())
  481. ->method('getEvents')
  482. ->willReturn([$eventEntityMock]);
  483. $eventEntityMock->expects($this->any())
  484. ->method('getEventName')
  485. ->willReturn('MyEvent');
  486. $checkMock->expects($this->any())
  487. ->method('supportedEntities')
  488. ->willReturn([IEntity::class]);
  489. $checkMock->expects($this->never())
  490. ->method('validateCheck');
  491. $this->container->expects($this->any())
  492. ->method('query')
  493. ->willReturnCallback(function ($className) use ($operationMock, $entityMock, $eventEntityMock, $checkMock) {
  494. switch ($className) {
  495. case IOperation::class:
  496. return $operationMock;
  497. case IEntity::class:
  498. return $entityMock;
  499. case IEntityEvent::class:
  500. return $eventEntityMock;
  501. case ICheck::class:
  502. return $checkMock;
  503. default:
  504. return $this->createMock($className);
  505. }
  506. });
  507. try {
  508. $this->manager->validateOperation(IOperation::class, 'test', [$check], $operationData, IEntity::class, ['MyEvent']);
  509. } catch (\UnexpectedValueException $e) {
  510. $this->assertSame('The provided operation data is too long', $e->getMessage());
  511. }
  512. }
  513. }