public function testExecuteWithNew() { $context = array('providers' => array(), 'formats' => array(), 'download' => array()); $this->pool->expects($this->any())->method('getContexts')->will($this->returnValue(array('foo' => $context))); $contextModel = $this->getMock('Sonata\\ClassificationBundle\\Model\\ContextInterface'); $this->contextManger->expects($this->once())->method('findOneBy')->with($this->equalTo(array('id' => 'foo')))->will($this->returnValue(null)); $this->contextManger->expects($this->once())->method('create')->will($this->returnValue($contextModel)); $this->contextManger->expects($this->once())->method('save')->with($this->equalTo($contextModel)); $category = $this->getMock('Sonata\\ClassificationBundle\\Model\\CategoryInterface'); $this->categoryManger->expects($this->once())->method('getRootCategory')->with($this->equalTo($contextModel))->will($this->returnValue(null)); $this->categoryManger->expects($this->once())->method('create')->will($this->returnValue($category)); $this->categoryManger->expects($this->once())->method('save')->with($this->equalTo($category)); $output = $this->tester->execute(array('command' => $this->command->getName())); $this->assertRegExp('@ > default category for \'foo\' is missing, creating one\\s+Done!@', $this->tester->getDisplay()); $this->assertSame(0, $output); }