<commit_before><?php

namespace Spec\PHPSpec\Runner\Formatter;

use PHPSpec\Runner\Formatter\Textmate as TextmateFormatter;

class DescribeTextmate extends \PHPSpec\Context
{
    const TEXTMATE_URL = 'txmt://open?url=file://%s&line=%s';
    
    public function itDecoratesTheBacktraceLinesWithATextmateLink()
    {
        $reporter = $this->_buildReporter();
        $reportEvent = $this->_buildReportEvent();
        
        $reportEvent->backtrace = '    # ./_files/spec/FooSpec.php:8';
        
        $textmateFormatter = new TextmateFormatter($reporter);
        $textmateFormatter->update($this->mock('SplSubject'), $reportEvent);
        
        // $textmateLink = $this->_buildLink('./_files/spec/FooSpec.php:8');
        // $this->property($textmateFormatter, '_examples')
        //     ->should
        
    }
    
    private function _buildLink($backtraceLine)
    {
        list ($path, $line) = explode(':', $backtraceLine);
        $url = sprintf(self::TEXTMATE_URL, realpath($path), $line);
        return sprintf("<a href=\"%s\">%s</a>", $url, $backtraceLine);
    }
    
    private function _buildReporter()
    {
        $failure = $this->mock("\SplObjectStorage");
        $failure->shouldReceive('count')
                ->andReturn(1);
        $otherResults = $this->mock("\SplObjectStorage");
        $otherResults->shouldReceive('count')
                ->andReturn(0);
        
        $reporter = $this->mock('PHPSpec\Runner\Reporter');
        $reporter->shouldReceive('hasMessage')
                 ->andReturn(false);
        $reporter->shouldReceive('getFailures')
                 ->andReturn($failure);
        $reporter->shouldReceive('getErrors')
                 ->andReturn($otherResults);
        $reporter->shouldReceive('getPendingExamples')
                 ->andReturn($otherResults);
        $reporter->shouldReceive('getExceptions')
                 ->andReturn($otherResults);
        $reporter->shouldReceive('getPassing')
                 ->andReturn($otherResults);
        $reporter->shouldReceive('getRuntime')
                 ->andReturn(1);
                 
        return $reporter;
    }
    
    private function _buildReportEvent()
    {
        $reportEvent = $this->mock('SplSubject');
        $reportEvent->event = 'status';
        $reportEvent->status = 'F';
        $reportEvent->example = 'itShouldDoStuff';
        $reportEvent->message = 'it didn\'t do it properly';
        $reportEvent->exception = $this->mock(new \PHPSpec\Exception);
        return $reportEvent;
    }
    
}<commit_msg>Fix itDecoratesTheBacktraceLinesWithATextmateLink test<commit_after><?php

namespace Spec\PHPSpec\Runner\Formatter;

use PHPSpec\Runner\Formatter\Textmate as TextmateFormatter;

class DescribeTextmate extends \PHPSpec\Context
{
    const TEXTMATE_URL = 'txmt://open?url=file://%s&line=%s';
    
    public function before()
    {
        $this->cwd = getcwd();
    }
    
    
    public function after()
    {
        chdir($this->cwd);
    }
    
    public function itDecoratesTheBacktraceLinesWithATextmateLink()
    {
        
        $reporter = $this->_buildReporter();
        $reportEvent = $this->_buildReportEvent();
        chdir(__DIR__);
        $reportEvent->backtrace = '    # ./_files/spec/FooSpec.php:8';
        
        $textmateFormatter = new TextmateFormatter($reporter);
        
        $textmateFormatter->update($this->mock('SplSubject'), $this->_buildReportEvent('start'));
        $textmateFormatter->update($this->mock('SplSubject'), $reportEvent);
        $textmateFormatter->update($this->mock('SplSubject'), $this->_buildReportEvent('finish'));
        
        ob_start();
        $textmateFormatter->output();
        $output = ob_get_contents();
        ob_end_clean();
        
        $position = $this->spec(
            strpos(
                $output,
                '<a href="txmt://open?url=file://'.
                realpath(__DIR__) .
                '/_files/spec/FooSpec.php&line=8">./_files/spec/FooSpec.php:8</a>'
            )
        );
        
        $position->shouldNot->beFalse();
    }
    
    private function _buildLink($backtraceLine)
    {
        list ($path, $line) = explode(':', $backtraceLine);
        $url = sprintf(self::TEXTMATE_URL, realpath($path), $line);
        return sprintf("<a href=\"%s\">%s</a>", $url, $backtraceLine);
    }
    
    private function _buildReporter()
    {
        $failure = $this->mock("\SplObjectStorage");
        $failure->shouldReceive('count')
                ->andReturn(1);
        $otherResults = $this->mock("\SplObjectStorage");
        $otherResults->shouldReceive('count')
                ->andReturn(0);
        
        $reporter = $this->mock('PHPSpec\Runner\Reporter');
        $reporter->shouldReceive('hasMessage')
                 ->andReturn(false);
        $reporter->shouldReceive('getFailures')
                 ->andReturn($failure);
        $reporter->shouldReceive('getErrors')
                 ->andReturn($otherResults);
        $reporter->shouldReceive('getPendingExamples')
                 ->andReturn($otherResults);
        $reporter->shouldReceive('getExceptions')
                 ->andReturn($otherResults);
        $reporter->shouldReceive('getPassing')
                 ->andReturn($otherResults);
        $reporter->shouldReceive('getRuntime')
                 ->andReturn(1);
                 
        return $reporter;
    }
    
    private function _buildReportEvent($status = 'status')
    {
        $reportEvent = $this->mock('SplSubject');
        $reportEvent->event = $status;
        $reportEvent->status = 'F';
        $reportEvent->example = 'itShouldDoStuff';
        $reportEvent->message = 'it didn\'t do it properly';
        $reportEvent->exception = $this->mock(new \PHPSpec\Exception);
        return $reportEvent;
    }
    
    
}
{'fraction_non_alphanumeric': 0.15007683114222298, 'fraction_numerical': 0.00187809458767287, 'mean_word_length': 2.2984234234234235, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 90, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7472148', 'n_tokens_mistral': 1677, 'n_tokens_neox': 1653, 'n_words': 228}