'Extension', 'params' => array( 'packagePath' => 'tests/unit/testData/Upgrades/data/upload/extensions', 'backupPath' => 'tests/unit/testData/Upgrades/data/.backup/extensions', 'scriptNames' => array( 'before' => 'BeforeInstall', 'after' => 'AfterInstall', 'beforeUninstall' => 'BeforeUninstall', 'afterUninstall' => 'AfterUninstall', ) ), ); protected function setUp() : void { $this->objects['container'] = $container = $this->getMockBuilder('Espo\Core\Container')->disableOriginalConstructor()->getMock(); $fileManager = $this->getMockBuilder(FileManager::class)->disableOriginalConstructor()->getMock(); $container ->expects($this->any()) ->method('get') ->will( $this->returnValueMap([ ['fileManager', $fileManager], ]) ); $this->object = new \Espo\Core\Upgrades\ActionManager( $this->params['name'], $this->objects['container'], $this->params['params'] ); $this->reflection = new ReflectionHelper($this->object); } protected function tearDown() : void { $this->object = NULL; } public function testGetObjectExtensionUpload() { $this->object->setAction(ExtensionManager::UPLOAD); $class = $this->reflection->invokeMethod('getObject'); $this->assertInstanceOf('\Espo\Core\Upgrades\Actions\Extension\Upload', $class); } public function testGetObjectExtensionInstall() { $this->object->setAction(ExtensionManager::INSTALL); $class = $this->reflection->invokeMethod('getObject'); $this->assertInstanceOf('\Espo\Core\Upgrades\Actions\Extension\Install', $class); } public function testGetObjectExtensionUninstall() { $this->object->setAction(ExtensionManager::UNINSTALL); $class = $this->reflection->invokeMethod('getObject'); $this->assertInstanceOf('\Espo\Core\Upgrades\Actions\Extension\Uninstall', $class); } public function testGetObjectExtensionDelete() { $this->object->setAction(ExtensionManager::DELETE); $class = $this->reflection->invokeMethod('getObject'); $this->assertInstanceOf('\Espo\Core\Upgrades\Actions\Extension\Delete', $class); } public function testGetObjectExtensionNotExists() { $this->expectException('\Espo\Core\Exceptions\Error'); $this->object->setAction('CustomClass'); $class = $this->reflection->invokeMethod('getObject'); } public function testGetObjectUpgradeUpload() { $this->reflection->setProperty('managerName', 'Upgrade'); $this->object->setAction(UpgradeManager::UPLOAD); $class = $this->reflection->invokeMethod('getObject'); $this->assertInstanceOf('\Espo\Core\Upgrades\Actions\Upgrade\Upload', $class); } public function testGetObjectUpgradeInstall() { $this->reflection->setProperty('managerName', 'Upgrade'); $this->object->setAction(UpgradeManager::INSTALL); $class = $this->reflection->invokeMethod('getObject'); $this->assertInstanceOf('\Espo\Core\Upgrades\Actions\Upgrade\Install', $class); } public function testGetObjectUpgradeUninstall() { $this->expectException('\Espo\Core\Exceptions\Error'); $this->reflection->setProperty('managerName', 'Upgrade'); $this->object->setAction(UpgradeManager::UNINSTALL); $class = $this->reflection->invokeMethod('getObject'); $this->assertInstanceOf('\Espo\Core\Upgrades\Actions\Upgrade\Uninstall', $class); $class->run(array()); } public function testGetObjectUpgradeDelete() { $this->expectException('\Espo\Core\Exceptions\Error'); $this->reflection->setProperty('managerName', 'Upgrade'); $this->object->setAction(UpgradeManager::DELETE); $class = $this->reflection->invokeMethod('getObject'); $this->assertInstanceOf('\Espo\Core\Upgrades\Actions\Upgrade\Delete', $class); $class->run(array()); } }