Вход Регистрация
Файл: gapps/vendor/sebastian/diff/tests/DifferTest.php
Строк: 660
<?php
/*
 * This file is part of the Diff package.
 *
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace SebastianBergmannDiff;

use 
PHPUnit_Framework_TestCase;
use 
SebastianBergmannDiffLCSMemoryEfficientImplementation;
use 
SebastianBergmannDiffLCSTimeEfficientImplementation;

class 
DifferTest extends PHPUnit_Framework_TestCase
{
    const 
REMOVED 2;
    const 
ADDED   1;
    const 
OLD     0;

    
/**
     * @var Differ
     */
    
private $differ;

    protected function 
setUp()
    {
        
$this->differ = new Differ;
    }

    
/**
     * @param array  $expected
     * @param string $from
     * @param string $to
     * @dataProvider arrayProvider
     * @covers       SebastianBergmannDiffDiffer::diffToArray
     * @covers       SebastianBergmannDiffLCSTimeEfficientImplementation
     */
    
public function testArrayRepresentationOfDiffCanBeRenderedUsingTimeEfficientLcsImplementation(array $expected$from$to)
    {
        
$this->assertEquals($expected$this->differ->diffToArray($from$to, new TimeEfficientImplementation));
    }

    
/**
     * @param string $expected
     * @param string $from
     * @param string $to
     * @dataProvider textProvider
     * @covers       SebastianBergmannDiffDiffer::diff
     * @covers       SebastianBergmannDiffLCSTimeEfficientImplementation
     */
    
public function testTextRepresentationOfDiffCanBeRenderedUsingTimeEfficientLcsImplementation($expected$from$to)
    {
        
$this->assertEquals($expected$this->differ->diff($from$to, new TimeEfficientImplementation));
    }

    
/**
     * @param array  $expected
     * @param string $from
     * @param string $to
     * @dataProvider arrayProvider
     * @covers       SebastianBergmannDiffDiffer::diffToArray
     * @covers       SebastianBergmannDiffLCSMemoryEfficientImplementation
     */
    
public function testArrayRepresentationOfDiffCanBeRenderedUsingMemoryEfficientLcsImplementation(array $expected$from$to)
    {
        
$this->assertEquals($expected$this->differ->diffToArray($from$to, new MemoryEfficientImplementation));
    }

    
/**
     * @param string $expected
     * @param string $from
     * @param string $to
     * @dataProvider textProvider
     * @covers       SebastianBergmannDiffDiffer::diff
     * @covers       SebastianBergmannDiffLCSMemoryEfficientImplementation
     */
    
public function testTextRepresentationOfDiffCanBeRenderedUsingMemoryEfficientLcsImplementation($expected$from$to)
    {
        
$this->assertEquals($expected$this->differ->diff($from$to, new MemoryEfficientImplementation));
    }

    
/**
     * @covers SebastianBergmannDiffDiffer::diff
     */
    
public function testCustomHeaderCanBeUsed()
    {
        
$differ = new Differ('CUSTOM HEADER');

        
$this->assertEquals(
            
"CUSTOM HEADER@@ @@n-an+bn",
            
$differ->diff('a''b')
        );
    }

    public function 
testTypesOtherThanArrayAndStringCanBePassed()
    {
        
$this->assertEquals(
            
"--- Originaln+++ Newn@@ @@n-1n+2n",
            
$this->differ->diff(12)
        );
    }

    
/**
     * @param string $diff
     * @param array  $expected
     * @dataProvider diffProvider
     * @covers       SebastianBergmannDiffParser::parse
     */
    
public function testParser($diff$expected)
    {
        
$parser = new Parser;
        
$result $parser->parse($diff);

        
$this->assertEquals($expected$result);
    }

    public function 
arrayProvider()
    {
        return array(
            array(
                array(
                    array(
'a'self::REMOVED),
                    array(
'b'self::ADDED)
                ),
                
'a',
                
'b'
            
),
            array(
                array(
                    array(
'ba'self::REMOVED),
                    array(
'bc'self::ADDED)
                ),
                
'ba',
                
'bc'
            
),
            array(
                array(
                    array(
'ab'self::REMOVED),
                    array(
'cb'self::ADDED)
                ),
                
'ab',
                
'cb'
            
),
            array(
                array(
                    array(
'abc'self::REMOVED),
                    array(
'adc'self::ADDED)
                ),
                
'abc',
                
'adc'
            
),
            array(
                array(
                    array(
'ab'self::REMOVED),
                    array(
'abc'self::ADDED)
                ),
                
'ab',
                
'abc'
            
),
            array(
                array(
                    array(
'bc'self::REMOVED),
                    array(
'abc'self::ADDED)
                ),
                
'bc',
                
'abc'
            
),
            array(
                array(
                    array(
'abc'self::REMOVED),
                    array(
'abbc'self::ADDED)
                ),
                
'abc',
                
'abbc'
            
),
            array(
                array(
                    array(
'abcdde'self::REMOVED),
                    array(
'abcde'self::ADDED)
                ),
                
'abcdde',
                
'abcde'
            
)
        );
    }

    public function 
textProvider()
    {
        return array(
            array(
                
"--- Originaln+++ Newn@@ @@n-an+bn",
                
'a',
                
'b'
            
),
            array(
                
"--- Originaln+++ Newn@@ @@n-ban+bcn",
                
'ba',
                
'bc'
            
),
            array(
                
"--- Originaln+++ Newn@@ @@n-abn+cbn",
                
'ab',
                
'cb'
            
),
            array(
                
"--- Originaln+++ Newn@@ @@n-abcn+adcn",
                
'abc',
                
'adc'
            
),
            array(
                
"--- Originaln+++ Newn@@ @@n-abn+abcn",
                
'ab',
                
'abc'
            
),
            array(
                
"--- Originaln+++ Newn@@ @@n-bcn+abcn",
                
'bc',
                
'abc'
            
),
            array(
                
"--- Originaln+++ Newn@@ @@n-abcn+abbcn",
                
'abc',
                
'abbc'
            
),
            array(
                
"--- Originaln+++ Newn@@ @@n-abcdden+abcden",
                
'abcdde',
                
'abcde'
            
),
        );
    }

    public function 
diffProvider()
    {
        
$serialized_arr = <<<EOL
a:1:{i:0;O:27:"SebastianBergmannDiffDiff":3:{s:33:"SebastianBergmannDiffDifffrom";s:7:"old.txt";s:31:"SebastianBergmannDiffDiffto";s:7:"new.txt";s:35:"SebastianBergmannDiffDiffchunks";a:3:{i:0;O:28:"SebastianBergmannDiffChunk":5:{s:35:"SebastianBergmannDiffChunkstart";i:1;s:40:"SebastianBergmannDiffChunkstartRange";i:3;s:33:"SebastianBergmannDiffChunkend";i:1;s:38:"SebastianBergmannDiffChunkendRange";i:4;s:35:"SebastianBergmannDiffChunklines";a:4:{i:0;O:27:"SebastianBergmannDiffLine":2:{s:33:"SebastianBergmannDiffLinetype";i:1;s:36:"SebastianBergmannDiffLinecontent";s:7:"2222111";}i:1;O:27:"SebastianBergmannDiffLine":2:{s:33:"SebastianBergmannDiffLinetype";i:3;s:36:"SebastianBergmannDiffLinecontent";s:7:"1111111";}i:2;O:27:"SebastianBergmannDiffLine":2:{s:33:"SebastianBergmannDiffLinetype";i:3;s:36:"SebastianBergmannDiffLinecontent";s:7:"1111111";}i:3;O:27:"SebastianBergmannDiffLine":2:{s:33:"SebastianBergmannDiffLinetype";i:3;s:36:"SebastianBergmannDiffLinecontent";s:7:"1111111";}}}i:1;O:28:"SebastianBergmannDiffChunk":5:{s:35:"SebastianBergmannDiffChunkstart";i:5;s:40:"SebastianBergmannDiffChunkstartRange";i:10;s:33:"SebastianBergmannDiffChunkend";i:6;s:38:"SebastianBergmannDiffChunkendRange";i:8;s:35:"SebastianBergmannDiffChunklines";a:11:{i:0;O:27:"SebastianBergmannDiffLine":2:{s:33:"SebastianBergmannDiffLinetype";i:3;s:36:"SebastianBergmannDiffLinecontent";s:7:"1111111";}i:1;O:27:"SebastianBergmannDiffLine":2:{s:33:"SebastianBergmannDiffLinetype";i:3;s:36:"SebastianBergmannDiffLinecontent";s:7:"1111111";}i:2;O:27:"SebastianBergmannDiffLine":2:{s:33:"SebastianBergmannDiffLinetype";i:3;s:36:"SebastianBergmannDiffLinecontent";s:7:"1111111";}i:3;O:27:"SebastianBergmannDiffLine":2:{s:33:"SebastianBergmannDiffLinetype";i:3;s:36:"SebastianBergmannDiffLinecontent";s:8:"+1121211";}i:4;O:27:"SebastianBergmannDiffLine":2:{s:33:"SebastianBergmannDiffLinetype";i:3;s:36:"SebastianBergmannDiffLinecontent";s:7:"1111111";}i:5;O:27:"SebastianBergmannDiffLine":2:{s:33:"SebastianBergmannDiffLinetype";i:3;s:36:"SebastianBergmannDiffLinecontent";s:8:"-1111111";}i:6;O:27:"SebastianBergmannDiffLine":2:{s:33:"SebastianBergmannDiffLinetype";i:3;s:36:"SebastianBergmannDiffLinecontent";s:8:"-1111111";}i:7;O:27:"SebastianBergmannDiffLine":2:{s:33:"SebastianBergmannDiffLinetype";i:3;s:36:"SebastianBergmannDiffLinecontent";s:8:"-2222222";}i:8;O:27:"SebastianBergmannDiffLine":2:{s:33:"SebastianBergmannDiffLinetype";i:3;s:36:"SebastianBergmannDiffLinecontent";s:7:"2222222";}i:9;O:27:"SebastianBergmannDiffLine":2:{s:33:"SebastianBergmannDiffLinetype";i:3;s:36:"SebastianBergmannDiffLinecontent";s:7:"2222222";}i:10;O:27:"SebastianBergmannDiffLine":2:{s:33:"SebastianBergmannDiffLinetype";i:3;s:36:"SebastianBergmannDiffLinecontent";s:7:"2222222";}}}i:2;O:28:"SebastianBergmannDiffChunk":5:{s:35:"SebastianBergmannDiffChunkstart";i:17;s:40:"SebastianBergmannDiffChunkstartRange";i:5;s:33:"SebastianBergmannDiffChunkend";i:16;s:38:"SebastianBergmannDiffChunkendRange";i:6;s:35:"SebastianBergmannDiffChunklines";a:7:{i:0;O:27:"SebastianBergmannDiffLine":2:{s:33:"SebastianBergmannDiffLinetype";i:3;s:36:"SebastianBergmannDiffLinecontent";s:7:"2222222";}i:1;O:27:"SebastianBergmannDiffLine":2:{s:33:"SebastianBergmannDiffLinetype";i:3;s:36:"SebastianBergmannDiffLinecontent";s:7:"2222222";}i:2;O:27:"SebastianBergmannDiffLine":2:{s:33:"SebastianBergmannDiffLinetype";i:3;s:36:"SebastianBergmannDiffLinecontent";s:7:"2222222";}i:3;O:27:"SebastianBergmannDiffLine":2:{s:33:"SebastianBergmannDiffLinetype";i:3;s:36:"SebastianBergmannDiffLinecontent";s:8:"+2122212";}i:4;O:27:"SebastianBergmannDiffLine":2:{s:33:"SebastianBergmannDiffLinetype";i:3;s:36:"SebastianBergmannDiffLinecontent";s:7:"2222222";}i:5;O:27:"SebastianBergmannDiffLine":2:{s:33:"SebastianBergmannDiffLinetype";i:3;s:36:"SebastianBergmannDiffLinecontent";s:7:"2222222";}i:6;O:27:"SebastianBergmannDiffLine":2:{s:33:"SebastianBergmannDiffLinetype";i:3;s:36:"SebastianBergmannDiffLinecontent";s:0:"";}}}}}}
EOL;

        return array(
            array(
                
"--- old.txt    2014-11-04 08:51:02.661868729 +0300n+++ new.txt    2014-11-04 08:51:02.665868730 +0300n@@ -1,3 +1,4 @@n+2222111n 1111111n 1111111n 1111111n@@ -5,10 +6,8 @@n 1111111n 1111111n 1111111n +1121211n 1111111n -1111111n -1111111n -2222222n 2222222n 2222222n 2222222n@@ -17,5 +16,6 @@n 2222222n 2222222n 2222222n +2122212n 2222222n 2222222n",
                
unserialize($serialized_arr)
            )
        );
    }
}
Онлайн: 1
Реклама