2017-07-14 26 views
1

我想測試我ArticleForm其中包含CKEditor領域:測試形式CKEditor的

$builder->add('content', CKEditorType::class, array(
    'config' => array('uiColor' => '#ffffff'), 
    'required' => true)); 

然而,當我運行PHPUnit我得到了以下錯誤:

Argument 1 passed to Ivory\CKEditorBundle\Form\Type\CKEditorType::__construct() 
must be an instance of Ivory\CKEditorBundle\Model\ConfigManagerInterface, none given 

測試配置是與devprod其中CKEditor工作f國家統計局:

ivory_ck_editor: 
    default_config: default 
    configs: 
     default: 
      filebrowserBrowseRoute: elfinder 
      filebrowserBrowseRouteParameters: [] 

測試用例擴展Symfonys' TypeTestCase它創建了自己的工廠。這可能是原因。但是我不知道如何強制這個工廠提供合適的CKEditor實例。有人知道該怎麼做嗎?

回答

1

問題的解決PreloadedExtension

class ArticleTypeTest { 

    protected function getExtensions() { 
     return array(new PreloadedExtension(array($this->getCKEditor()), array())); 
    } 

    ... 

    protected function getCKEditor() { 
     $configManager = $this->getMockBuilder (ConfigManagerInterface::class)->disableOriginalConstructor()->getMock(); 
     $pluginManager = $this->getMockBuilder (PluginManagerInterface::class)->disableOriginalConstructor()->getMock(); 
     $stylesSetManager = $this->getMockBuilder (StylesSetManagerInterface::class)->disableOriginalConstructor()->getMock(); 
     $templateManager = $this->getMockBuilder (TemplateManagerInterface::class)->disableOriginalConstructor()->getMock(); 

     $type = new CKEditorType($configManager, $pluginManager, $stylesSetManager, $templateManager); 

     return $type; 
    } 
} 
+1

偉大的答案!對於最新版本的Ivory CKEditor軟件包,您還需要模擬工具欄管理器: '$ toolbarManager = $ this-> getMockBuilder(ToolbarManagerInterface :: class) - > disableOriginalConstructor() - > getMock(); $ type = new CKEditorType($ configManager,$ pluginManager,$ stylesSetManager,$ templateManager,$ toolbarManager);' – guhemama