<commit_before><?php
/**
 * PHPSpec
 *
 * LICENSE
 *
 * This file is subject to the GNU Lesser General Public License Version 3
 * that is bundled with this package in the file LICENSE.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/lgpl-3.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to <EMAIL> so we can send you a copy immediately.
 *
 * @category  PHPSpec
 * @package   PHPSpec
 * @copyright Copyright (c) 2007-2009 <NAME>, <NAME>
 * @copyright Copyright (c) 2010-2011 <NAME>, <NAME>,
 * <NAME>
 * @license   http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
 *
 *
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite
name="TestDummy"
file="/home/mmueller/Development/Checkouts/trivago-php/tests/unit/TestDummy.php"
tests="1" assertions="1" failures="0" errors="0" time="0.005316">
<testcase name="testNothing" class="TestDummy"
file="/home/mmueller/Development/Checkouts/trivago-php/tests/unit/TestDummy.php"
line="12" assertions="1" time="0.005316"/>
</testsuite>
</testsuites>
*/
namespace PHPSpec\Runner\Formatter;
use PHPSpec\Util\Backtrace, PHPSpec\Specification\Result\DeliberateFailure, PHPSpec\Runner\Reporter;
class Junit extends Progress
{
    
    /**
     * @var \SimpleXMLElement
     */
    private $_xml;
    private $_i = 0;
    private $_result;
    private $_examples;
    private $_testSuite;
    private $_suiteTime = 0;
    private $_errors = 0;
    private $_failures = 0;
    private $_pending = 0;
    private $_total = 0;
    private $_complete = 0;
    private $_errorOnExit = false;
    
    public function __construct (Reporter $reporter)
    {
        parent::__construct($reporter);
        $this->_xml = new \SimpleXMLElement("<testsuites></testsuites>");
    }
    /**
     * Prints the report in a specific format
     */
    public function output ()
    {
        return $this->_xml;
    }
    
    /**
     * Opens the testsuite tag
     * @see PHPSpec\Runner\Formatter\FormatterAbstract::_startRenderingExampleGroup()
     */
    protected function _startRenderingExampleGroup($reporterEvent)
    {
        $this->_testSuite = $this->_xml->addChild('testsuite');
        $this->_testSuite->addAttribute('name', $reporterEvent->example);
        
        $this->_suiteTime = 0;
        
        $this->_currentGroup = $reporterEvent->example;
    }
    
    protected function _finishRenderingExampleGroup()
    {
        $this->_testSuite->addAttribute('tests', $this->_total);
        $this->_testSuite->addAttribute('failures', $this->_failures);
        $this->_testSuite->addAttribute('errors', $this->_errors);
        // $this->_testSuite->addAttribute('assertions', $this->_assertions);  not available yet
        $this->_testSuite->addAttribute('time', $this->_suiteTime);
        
        if ($this->_errors > 0 || $this->_failures > 0) {
            $this->_errorOnExit = true;
        }
        
        $this->_total = 0;
        $this->_failures = 0;
        $this->_errors = 0;
        $this->_pending = 0;
        $this->_complete = 0;
    }
    
    protected function _renderExamples($reporterEvent)
    {
        $this->_total++;
        $this->_suiteTime += $reporterEvent->time;
        
        $status = $reporterEvent->status;
        
        $case = $this->_testSuite->addChild('testcase');
        $case->addAttribute('class', $this->_currentGroup);
        $case->addAttribute('name', $reporterEvent->example);
        // $case->addAttribute('file', 'filename.php'); not available yet
        // $case->addAttribute('assertions', '1'); not available yet
        $case->addAttribute('time', $reporterEvent->time);
        // $case->addAttribute('line', '30'); not available yet
        
        switch ($status) {
            case '.':
                $this->_complete++;
                break;
            case '*':
                $failure_msg = PHP_EOL . $reporterEvent->example . ' (PENDING)' . PHP_EOL;
                $failure_msg .= $reporterEvent->message . PHP_EOL;
                
                $failure = $case->addChild('failure', $failure_msg);
                $failure->addAttribute('type', get_class($reporterEvent->exception));
                
                $error = '   <error type="'.get_class($reporterEvent->exception).'">' . PHP_EOL;
                $error .= '    Skipped Test: ' . $reporterEvent->example;
                $error .= '    ' . $reporterEvent->message;
                $error .= '   </error>';
                
                $this->_failures++;
                break;
            case 'E':
                $failure_msg = PHP_EOL . $reporterEvent->example . ' (ERROR)' . PHP_EOL;
                $failure_msg .= $reporterEvent->message . PHP_EOL;
                $failure_msg .= $reporterEvent->backtrace . PHP_EOL;
                
                $error = $case->addChild('error', $failure_msg);
                $error->addAttribute('type', get_class($reporterEvent->exception));
                
                $this->_errors++;
                break;
            case 'F':
                $failure_msg = PHP_EOL . $reporterEvent->example . ' (FAILED)' . PHP_EOL;
                $failure_msg .= $reporterEvent->message . PHP_EOL;
                $failure_msg .= $reporterEvent->backtrace . PHP_EOL;
                
                $failure = $case->addChild('failure', $failure_msg);
                $failure->addAttribute('type', get_class($reporterEvent->exception));
                
                $this->_failures++;
                break;
        }
    }
    
    /**
     * Gets the code based on the exception backtrace
     * 
     * @param \Exception $e
     * @return string
     */
    protected function getCode($e)
    {
        if (!$e instanceof \Exception) {
            return '';
        }
        
        if (!$e instanceof \PHPSpec\Specification\Result\DeliberateFailure) {
            $traceline = Backtrace::getFileAndLine($e->getTrace(), 1);<commit_msg>Changed to pass the CodeSniffer check. Warnings remain in some lines longer than 80 characters.<commit_after><?php
/**
 * PHPSpec
 *
 * LICENSE
 *
 * This file is subject to the GNU Lesser General Public License Version 3
 * that is bundled with this package in the file LICENSE.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/lgpl-3.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to <EMAIL> so we can send you a copy immediately.
 *
 * @category  PHPSpec
 * @package   PHPSpec
 * @copyright Copyright (c) 2007-2009 <NAME>, <NAME>
 * @copyright Copyright (c) 2010-2011 <NAME>, <NAME>,
 * <NAME>
 * @license   http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
 *
 *
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite
name="TestDummy"
file="/home/mmueller/Development/Checkouts/trivago-php/tests/unit/TestDummy.php"
tests="1" assertions="1" failures="0" errors="0" time="0.005316">
<testcase name="testNothing" class="TestDummy"
file="/home/mmueller/Development/Checkouts/trivago-php/tests/unit/TestDummy.php"
line="12" assertions="1" time="0.005316"/>
</testsuite>
</testsuites>
*/
namespace PHPSpec\Runner\Formatter;
use PHPSpec\Util\Backtrace,
    PHPSpec\Specification\Result\DeliberateFailure,
    PHPSpec\Runner\Reporter;
class Junit extends Progress
{
    
    /**
     * @var \SimpleXMLElement
     */
    private $_xml;
    private $_i = 0;
    private $_result;
    private $_examples;
    private $_testSuite;
    private $_suiteTime = 0;
    private $_errors = 0;
    private $_failures = 0;
    private $_pending = 0;
    private $_total = 0;
    private $_complete = 0;
    private $_errorOnExit = false;
    
    public function __construct (Reporter $reporter)
    {
        parent::__construct($reporter);
        $this->_xml = new \SimpleXMLElement("<testsuites></testsuites>");
    }
    /**
     * Prints the report in a specific format
     */
    public function output ()
    {
        return $this->_xml;
    }
    
    /**
     * Opens the testsuite tag
     * @see PHPSpec\Runner\Formatter\FormatterAbstract::_startRenderingExampleGroup()
     */
    protected function _startRenderingExampleGroup($reporterEvent)
    {
        $this->_testSuite = $this->_xml->addChild('testsuite');
        $this->_testSuite->addAttribute('name', $reporterEvent->example);
        
        $this->_suiteTime = 0;
        
        $this->_currentGroup = $reporterEvent->example;
    }
    
    protected function _finishRenderingExampleGroup()
    {
        $this->_testSuite->addAttribute('tests', $this->_total);
        $this->_testSuite->addAttribute('failures', $this->_failures);
        $this->_testSuite->addAttribute('errors', $this->_errors);
        // not available yet
        // $this->_testSuite->addAttribute('assertions', $this->_assertions);
        $this->_testSuite->addAttribute('time', $this->_suiteTime);
        
        if ($this->_errors > 0 || $this->_failures > 0) {
            $this->_errorOnExit = true;
        }
        
        $this->_total = 0;
        $this->_failures = 0;
        $this->_errors = 0;
        $this->_pending = 0;
        $this->_complete = 0;
    }
    
    protected function _renderExamples($reporterEvent)
    {
        $this->_total++;
        $this->_suiteTime += $reporterEvent->time;
        
        $status = $reporterEvent->status;
        
        $case = $this->_testSuite->addChild('testcase');
        $case->addAttribute('class', $this->_currentGroup);
        $case->addAttribute('name', $reporterEvent->example);
        // $case->addAttribute('file', 'filename.php'); not available yet
        // $case->addAttribute('assertions', '1'); not available yet
        $case->addAttribute('time', $reporterEvent->time);
        // $case->addAttribute('line', '30'); not available yet
        
        switch ($status) {
        case '.':
            $this->_complete++;
            break;
        case '*':
            $failureMsg = PHP_EOL . $reporterEvent->example
                        . ' (PENDING)' . PHP_EOL;
            $failureMsg .= $reporterEvent->message . PHP_EOL;
            
            $failure = $case->addChild('failure', $failureMsg);
            $failure->addAttribute(
                'type',
                get_class($reporterEvent->exception)
            );
            
            $this->_failures++;
            break;
        case 'E':
            $failureMsg = PHP_EOL . $reporterEvent->example
                        . ' (ERROR)' . PHP_EOL;
            $failureMsg .= $reporterEvent->message . PHP_EOL;
            $failureMsg .= $reporterEvent->backtrace . PHP_EOL;
            
            $error = $case->addChild('error', $failureMsg);
            $error->addAttribute(
                'type',
                get_class($reporterEvent->exception)
            );
            
            $this->_errors++;
            break;
        case 'F':
            $failureMsg = PHP_EOL . $reporterEvent->example
            . ' (FAILED)' . PHP_EOL;
            $failureMsg .= $reporterEvent->message . PHP_EOL;
            $failureMsg .= $reporterEvent->backtrace . PHP_EOL;
            
            $failure = $case->addChild('failure', $failureMsg);
            $failure->addAttribute(
                'type',
                get_class($reporterEvent->exception)
            );
            
            $this->_failures++;
            break;
        }
    }
    
    /**
     * Gets the code based on the exception backtrace
     * 
     * @param \Exception $e
     * @return string
     */
    protected function getCode($e)
    {
        if (!$e instanceof \Exception) {
            return '';
        }
        
        if (!$e instanceof \PHPSpec\Specification\Result\DeliberateFailure) {
            $traceline = Backtrace::getFileAndLine($e->getTrace(), 1);
{'fraction_non_alphanumeric': 0.13943825826824, 'fraction_numerical': 0.010968921389396709, 'mean_word_length': 2.1662720336753485, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 2, '>': 182, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5614232', 'n_tokens_mistral': 3560, 'n_tokens_neox': 3450, 'n_words': 732}