Пример #1
0
    /**
     * @covers phpDocumentor\Plugin\Core\Transformer\Writer\CheckStyle::transform
     */
    public function testTransform()
    {
        $transformer = m::mock('phpDocumentor\\Transformer\\Transformation');
        $transformer->shouldReceive('getTransformer->getTarget')->andReturn(vfsStream::url('CheckStyleTest'));
        $transformer->shouldReceive('getArtifact')->andReturn('artifact.xml');
        $fileDescriptor = m::mock('phpDocumentor\\Descriptor\\FileDescriptor');
        $projectDescriptor = m::mock('phpDocumentor\\Descriptor\\ProjectDescriptor');
        $projectDescriptor->shouldReceive('getFiles->getAll')->andReturn(array($fileDescriptor));
        $error = m::mock('phpDocumentor\\Descriptor\\Validator\\Error');
        $fileDescriptor->shouldReceive('getPath')->andReturn('/foo/bar/baz');
        $fileDescriptor->shouldReceive('getAllErrors->getAll')->andReturn(array($error));
        $error->shouldReceive('getLine')->andReturn(1234);
        $error->shouldReceive('getCode')->andReturn(5678);
        $error->shouldReceive('getSeverity')->andReturn('error');
        $error->shouldReceive('getContext')->andReturn('myContext');
        $this->translator->shouldReceive('translate')->with('5678')->andReturn('5678 %s');
        // Call the actual method
        $this->checkStyle->transform($projectDescriptor, $transformer);
        // Assert file exists
        $this->assertTrue($this->fs->hasChild('artifact.xml'));
        // Inspect XML
        $xml = <<<XML
<?xml version="1.0"?>
<checkstyle version="1.3.0">
  <file name="/foo/bar/baz">
    <error line="1234" severity="error" message="5678 myContext" source="phpDocumentor.file.5678"/>
  </file>
</checkstyle>
XML;
        $expectedXml = new \DOMDocument();
        $expectedXml->loadXML($xml);
        $actualXml = new \DOMDocument();
        $actualXml->load(vfsStream::url('CheckStyleTest/artifact.xml'));
        $this->assertEqualXMLStructure($expectedXml->firstChild, $actualXml->firstChild, true);
    }