public function testValidateWithValidContext() { $pool = new Pool('defaultContext'); $pool->addContext('test'); $gallery = $this->getMock('Sonata\\MediaBundle\\Model\\GalleryInterface'); $gallery->expects($this->once())->method('getDefaultFormat')->will($this->returnValue('format1')); $gallery->expects($this->once())->method('getContext')->will($this->returnValue('test')); $context = $this->getMock('Symfony\\Component\\Validator\\ExecutionContext', array(), array(), '', false); $context->expects($this->once())->method('addViolation'); $validator = new FormatValidator($pool); $validator->initialize($context); $validator->validate($gallery, new ValidMediaFormat()); }