first commit
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2011 by TEQneers GmbH & Co. KG
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace TQ\Tests\Git\Cli;
|
||||
|
||||
use TQ\Git\Cli\Binary;
|
||||
use TQ\Tests\Helper;
|
||||
|
||||
class CallCreationTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected function assertCliCommandEquals($expected, $actual)
|
||||
{
|
||||
if (strpos(PHP_OS, 'WIN') !== false) {
|
||||
$expected = Helper::normalizeEscapeShellArg($expected);
|
||||
}
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testHandleSingleDash()
|
||||
{
|
||||
$binary = new Binary('/usr/bin/git');
|
||||
$call = $binary->createGitCall('/', 'command', array(
|
||||
'-a'
|
||||
));
|
||||
$this->assertCliCommandEquals("/usr/bin/git 'command' -'a'", $call->getCmd());
|
||||
}
|
||||
|
||||
public function testHandleDoubleDash()
|
||||
{
|
||||
$binary = new Binary('/usr/bin/git');
|
||||
$call = $binary->createGitCall('/', 'command', array(
|
||||
'--argument'
|
||||
));
|
||||
$this->assertCliCommandEquals("/usr/bin/git 'command' --'argument'", $call->getCmd());
|
||||
}
|
||||
|
||||
public function testHandleSingleDashWithValue()
|
||||
{
|
||||
$binary = new Binary('/usr/bin/git');
|
||||
$call = $binary->createGitCall('/', 'command', array(
|
||||
'-a' => 'value'
|
||||
));
|
||||
$this->assertCliCommandEquals("/usr/bin/git 'command' -'a' 'value'", $call->getCmd());
|
||||
}
|
||||
|
||||
public function testHandleDoubleDashWithValue()
|
||||
{
|
||||
$binary = new Binary('/usr/bin/git');
|
||||
$call = $binary->createGitCall('/', 'command', array(
|
||||
'--argument' => 'value'
|
||||
));
|
||||
$this->assertCliCommandEquals("/usr/bin/git 'command' --'argument'='value'", $call->getCmd());
|
||||
}
|
||||
|
||||
public function testIgnoreLoneDoubleDash()
|
||||
{
|
||||
$binary = new Binary('/usr/bin/git');
|
||||
$call = $binary->createGitCall('/', 'command', array(
|
||||
'--'
|
||||
));
|
||||
$this->assertCliCommandEquals("/usr/bin/git 'command'", $call->getCmd());
|
||||
}
|
||||
|
||||
public function testSimpleArgument()
|
||||
{
|
||||
$binary = new Binary('/usr/bin/git');
|
||||
$call = $binary->createGitCall('/', 'command', array(
|
||||
'option'
|
||||
));
|
||||
$this->assertCliCommandEquals("/usr/bin/git 'command' 'option'", $call->getCmd());
|
||||
}
|
||||
|
||||
public function testFilePathAsArgument()
|
||||
{
|
||||
$binary = new Binary('/usr/bin/git');
|
||||
$call = $binary->createGitCall('/', 'command', array(
|
||||
'/path/to/file'
|
||||
));
|
||||
$this->assertCliCommandEquals("/usr/bin/git 'command' '/path/to/file'", $call->getCmd());
|
||||
}
|
||||
|
||||
public function testFileModeSwitch()
|
||||
{
|
||||
$binary = new Binary('/usr/bin/git');
|
||||
$call = $binary->createGitCall('/', 'command', array(
|
||||
'option',
|
||||
'--',
|
||||
'path/to/file'
|
||||
));
|
||||
$this->assertCliCommandEquals("/usr/bin/git 'command' 'option' -- 'path/to/file'", $call->getCmd());
|
||||
}
|
||||
|
||||
public function testFileModeSwitchWithFileArgument()
|
||||
{
|
||||
$binary = new Binary('/usr/bin/git');
|
||||
$call = $binary->createGitCall('/', 'command', array(
|
||||
'option',
|
||||
'/path/to/file',
|
||||
'--',
|
||||
'path/to/file'
|
||||
));
|
||||
$this->assertCliCommandEquals("/usr/bin/git 'command' 'option' '/path/to/file' -- 'path/to/file'", $call->getCmd());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2011 by TEQneers GmbH & Co. KG
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace TQ\Tests\Git\Cli;
|
||||
|
||||
use TQ\Git\Cli\Binary;
|
||||
use TQ\Git\Cli\CallResult;
|
||||
|
||||
class CallResultTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSuccessfulCall()
|
||||
{
|
||||
$binary = new Binary(GIT_BINARY);
|
||||
$call = $binary->createGitCall('/', '', array(
|
||||
'--version'
|
||||
));
|
||||
$result = $call->execute();
|
||||
|
||||
$this->assertTrue($result->hasStdOut());
|
||||
$this->assertFalse($result->hasStdErr());
|
||||
$this->assertEmpty($result->getStdErr());
|
||||
$this->assertEquals(0, $result->getReturnCode());
|
||||
$this->assertStringStartsWith('git version', $result->getStdOut());
|
||||
$this->assertSame($call, $result->getCliCall());
|
||||
}
|
||||
|
||||
public function testFailedCall()
|
||||
{
|
||||
$binary = new Binary(GIT_BINARY);
|
||||
$call = $binary->createGitCall('/', 'unknowncommand', array());
|
||||
$result = $call->execute();
|
||||
|
||||
$this->assertFalse($result->hasStdOut());
|
||||
$this->assertTrue($result->hasStdErr());
|
||||
$this->assertEmpty($result->getStdOut());
|
||||
$this->assertNotEmpty($result->getStdErr());
|
||||
$this->assertGreaterThan(0, $result->getReturnCode());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2011 by TEQneers GmbH & Co. KG
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace TQ\Tests\Git\Repository;
|
||||
|
||||
use TQ\Git\Cli\Binary;
|
||||
use TQ\Git\Repository\Repository;
|
||||
use TQ\Tests\Helper;
|
||||
|
||||
class InfoTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Sets up the fixture, for example, open a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
Helper::removeDirectory(TESTS_TMP_PATH);
|
||||
mkdir(TESTS_TMP_PATH, 0777, true);
|
||||
mkdir(TESTS_REPO_PATH_1, 0777, true);
|
||||
|
||||
exec(sprintf('cd %s && %s init',
|
||||
escapeshellarg(TESTS_REPO_PATH_1),
|
||||
GIT_BINARY
|
||||
));
|
||||
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$file = sprintf('file_%d.txt', $i);
|
||||
$path = TESTS_REPO_PATH_1.'/'.$file;
|
||||
file_put_contents($path, sprintf('File %d', $i));
|
||||
exec(sprintf('cd %s && %s add %s',
|
||||
escapeshellarg(TESTS_REPO_PATH_1),
|
||||
GIT_BINARY,
|
||||
escapeshellarg($file)
|
||||
));
|
||||
}
|
||||
exec(sprintf('cd %s && %s commit --message=%s',
|
||||
escapeshellarg(TESTS_REPO_PATH_1),
|
||||
GIT_BINARY,
|
||||
escapeshellarg('Initial commit')
|
||||
));
|
||||
|
||||
clearstatcache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, close a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
Helper::removeDirectory(TESTS_TMP_PATH);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Repository
|
||||
*/
|
||||
protected function getRepository()
|
||||
{
|
||||
return Repository::open(TESTS_REPO_PATH_1, new Binary(GIT_BINARY));
|
||||
}
|
||||
|
||||
public function testGetCurrentBranch()
|
||||
{
|
||||
$c = $this->getRepository();
|
||||
$this->assertEquals('master', $c->getCurrentBranch());
|
||||
}
|
||||
|
||||
public function testGetBranches()
|
||||
{
|
||||
$c = $this->getRepository();
|
||||
$this->assertEquals(array('master'), $c->getBranches());
|
||||
}
|
||||
|
||||
public function testGetStatus()
|
||||
{
|
||||
$c = $this->getRepository();
|
||||
$this->assertFalse($c->isDirty());
|
||||
|
||||
$file = TESTS_REPO_PATH_1.'/test.txt';
|
||||
file_put_contents($file, 'Test');
|
||||
$this->assertTrue($c->isDirty());
|
||||
$status = $c->getStatus();
|
||||
$this->assertEquals(array(
|
||||
'file' => 'test.txt',
|
||||
'x' => '?',
|
||||
'y' => '?',
|
||||
'renamed' => null
|
||||
), $status[0]);
|
||||
|
||||
$c->add(array('test.txt'));
|
||||
$this->assertTrue($c->isDirty());
|
||||
$status = $c->getStatus();
|
||||
$this->assertEquals(array(
|
||||
'file' => 'test.txt',
|
||||
'x' => 'A',
|
||||
'y' => '',
|
||||
'renamed' => null
|
||||
), $status[0]);
|
||||
|
||||
$c->commit('Commt file', array('test.txt'));
|
||||
$this->assertFalse($c->isDirty());
|
||||
}
|
||||
|
||||
public function testGetLog()
|
||||
{
|
||||
$c = $this->getRepository();
|
||||
$log = $c->getLog();
|
||||
$this->assertEquals(1, count($log));
|
||||
$this->assertContains('Initial commit', $log[0]);
|
||||
|
||||
$hash = $c->writeFile('/directory/test.txt', 'Test');
|
||||
$log = $c->getLog();
|
||||
$this->assertEquals(2, count($log));
|
||||
$this->assertContains($hash, $log[0]);
|
||||
$this->assertContains('Initial commit', $log[1]);
|
||||
|
||||
$log = $c->getLog(1);
|
||||
$this->assertEquals(1, count($log));
|
||||
$this->assertContains($hash, $log[0]);
|
||||
|
||||
$log = $c->getLog(1, 1);
|
||||
$this->assertEquals(1, count($log));
|
||||
$this->assertContains('Initial commit', $log[0]);
|
||||
}
|
||||
|
||||
public function testShowCommit()
|
||||
{
|
||||
$c = $this->getRepository();
|
||||
$hash = $c->writeFile('test.txt', 'Test');
|
||||
$commit = $c->showCommit($hash);
|
||||
$this->assertContains('test.txt', $commit);
|
||||
$this->assertContains('Test', $commit);
|
||||
}
|
||||
|
||||
public function testListDirectory()
|
||||
{
|
||||
$c = $this->getRepository();
|
||||
|
||||
$list = $c->listDirectory();
|
||||
$this->assertContains('file_0.txt', $list);
|
||||
$this->assertContains('file_1.txt', $list);
|
||||
$this->assertContains('file_2.txt', $list);
|
||||
$this->assertContains('file_3.txt', $list);
|
||||
$this->assertContains('file_4.txt', $list);
|
||||
$this->assertNotContains('test.txt', $list);
|
||||
|
||||
$c->writeFile('test.txt', 'Test');
|
||||
$list = $c->listDirectory();
|
||||
$this->assertContains('file_0.txt', $list);
|
||||
$this->assertContains('file_1.txt', $list);
|
||||
$this->assertContains('file_2.txt', $list);
|
||||
$this->assertContains('file_3.txt', $list);
|
||||
$this->assertContains('file_4.txt', $list);
|
||||
$this->assertContains('test.txt', $list);
|
||||
|
||||
$c->removeFile('test.txt');
|
||||
$list = $c->listDirectory();
|
||||
$this->assertContains('file_0.txt', $list);
|
||||
$this->assertContains('file_1.txt', $list);
|
||||
$this->assertContains('file_2.txt', $list);
|
||||
$this->assertContains('file_3.txt', $list);
|
||||
$this->assertContains('file_4.txt', $list);
|
||||
$this->assertNotContains('test.txt', $list);
|
||||
|
||||
$list = $c->listDirectory('.', 'HEAD^^');
|
||||
$this->assertContains('file_0.txt', $list);
|
||||
$this->assertContains('file_1.txt', $list);
|
||||
$this->assertContains('file_2.txt', $list);
|
||||
$this->assertContains('file_3.txt', $list);
|
||||
$this->assertContains('file_4.txt', $list);
|
||||
$this->assertNotContains('test.txt', $list);
|
||||
|
||||
$list = $c->listDirectory('.', 'HEAD^');
|
||||
$this->assertContains('file_0.txt', $list);
|
||||
$this->assertContains('file_1.txt', $list);
|
||||
$this->assertContains('file_2.txt', $list);
|
||||
$this->assertContains('file_3.txt', $list);
|
||||
$this->assertContains('file_4.txt', $list);
|
||||
$this->assertContains('test.txt', $list);
|
||||
|
||||
$c->writeFile('directory/test.txt', 'Test');
|
||||
$list = $c->listDirectory('directory/', 'HEAD');
|
||||
$this->assertContains('test.txt', $list);
|
||||
|
||||
$list = $c->listDirectory('directory', 'HEAD');
|
||||
$this->assertContains('test.txt', $list);
|
||||
}
|
||||
|
||||
public function testShowFile()
|
||||
{
|
||||
$c = $this->getRepository();
|
||||
|
||||
$this->assertEquals('File 0', $c->showFile('file_0.txt'));
|
||||
|
||||
$c->writeFile('test.txt', 'Test 1');
|
||||
$this->assertEquals('Test 1', $c->showFile('test.txt'));
|
||||
|
||||
$c->writeFile('test.txt', 'Test 2');
|
||||
$this->assertEquals('Test 2', $c->showFile('test.txt'));
|
||||
$this->assertEquals('Test 1', $c->showFile('test.txt', 'HEAD^'));
|
||||
|
||||
$c->writeFile('test.txt', 'Test 3');
|
||||
$this->assertEquals('Test 3', $c->showFile('test.txt'));
|
||||
$this->assertEquals('Test 2', $c->showFile('test.txt', 'HEAD^'));
|
||||
$this->assertEquals('Test 1', $c->showFile('test.txt', 'HEAD^^'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,338 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2011 by TEQneers GmbH & Co. KG
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace TQ\Tests\Git\Repository;
|
||||
|
||||
use TQ\Git\Cli\Binary;
|
||||
use TQ\Git\Repository\Repository;
|
||||
use TQ\Git\Repository\Transaction;
|
||||
use TQ\Tests\Helper;
|
||||
|
||||
class ModificationTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Sets up the fixture, for example, open a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
Helper::removeDirectory(TESTS_TMP_PATH);
|
||||
mkdir(TESTS_TMP_PATH, 0777, true);
|
||||
mkdir(TESTS_REPO_PATH_1, 0777, true);
|
||||
|
||||
exec(sprintf('cd %s && %s init',
|
||||
escapeshellarg(TESTS_REPO_PATH_1),
|
||||
GIT_BINARY
|
||||
));
|
||||
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$file = sprintf('file_%d.txt', $i);
|
||||
$path = TESTS_REPO_PATH_1.'/'.$file;
|
||||
file_put_contents($path, sprintf('File %d', $i));
|
||||
exec(sprintf('cd %s && %s add %s',
|
||||
escapeshellarg(TESTS_REPO_PATH_1),
|
||||
GIT_BINARY,
|
||||
escapeshellarg($file)
|
||||
));
|
||||
}
|
||||
exec(sprintf('cd %s && %s commit --message=%s',
|
||||
escapeshellarg(TESTS_REPO_PATH_1),
|
||||
GIT_BINARY,
|
||||
escapeshellarg('Initial commit')
|
||||
));
|
||||
|
||||
clearstatcache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, close a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
Helper::removeDirectory(TESTS_TMP_PATH);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Repository
|
||||
*/
|
||||
protected function getRepository()
|
||||
{
|
||||
return Repository::open(TESTS_REPO_PATH_1, new Binary(GIT_BINARY));
|
||||
}
|
||||
|
||||
public function testAddFile()
|
||||
{
|
||||
$c = $this->getRepository();
|
||||
$hash = $c->writeFile('test.txt', 'Test');
|
||||
$this->assertEquals(40, strlen($hash));
|
||||
|
||||
$this->assertFileExists(TESTS_REPO_PATH_1.'/test.txt');
|
||||
$this->assertEquals('Test', file_get_contents(TESTS_REPO_PATH_1.'/test.txt'));
|
||||
|
||||
$commit = $c->showCommit($hash);
|
||||
$this->assertContains('+++ b/test.txt', $commit);
|
||||
}
|
||||
|
||||
public function testAddFileInSubdirectory()
|
||||
{
|
||||
$c = $this->getRepository();
|
||||
$hash = $c->writeFile('/directory/test.txt', 'Test');
|
||||
$this->assertEquals(40, strlen($hash));
|
||||
|
||||
$this->assertFileExists(TESTS_REPO_PATH_1.'/directory/test.txt');
|
||||
$this->assertEquals('Test', file_get_contents(TESTS_REPO_PATH_1.'/directory/test.txt'));
|
||||
|
||||
$commit = $c->showCommit($hash);
|
||||
$this->assertContains('+++ b/directory/test.txt', $commit);
|
||||
}
|
||||
|
||||
public function testAddMultipleFiles()
|
||||
{
|
||||
$c = $this->getRepository();
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$hash = $c->writeFile(sprintf('test_%s.txt', $i), $i);
|
||||
$this->assertEquals(40, strlen($hash));
|
||||
$commit = $c->showCommit($hash);
|
||||
$this->assertContains(sprintf('+++ b/test_%d.txt', $i), $commit);
|
||||
}
|
||||
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$this->assertFileExists(TESTS_REPO_PATH_1.sprintf('/test_%s.txt', $i));
|
||||
$this->assertEquals($i, file_get_contents(TESTS_REPO_PATH_1.sprintf('/test_%s.txt', $i)));
|
||||
}
|
||||
}
|
||||
|
||||
public function testRemoveFile()
|
||||
{
|
||||
$c = $this->getRepository();
|
||||
$hash = $c->removeFile('file_0.txt');
|
||||
$this->assertEquals(40, strlen($hash));
|
||||
|
||||
$this->assertFileNotExists(TESTS_REPO_PATH_1.'/file_0.txt');
|
||||
|
||||
$commit = $c->showCommit($hash);
|
||||
$this->assertContains('--- a/file_0.txt', $commit);
|
||||
}
|
||||
|
||||
public function testRemoveMultipleFiles()
|
||||
{
|
||||
$c = $this->getRepository();
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$hash = $c->removeFile(sprintf('file_%s.txt', $i), $i);
|
||||
$this->assertEquals(40, strlen($hash));
|
||||
$commit = $c->showCommit($hash);
|
||||
$this->assertContains(sprintf('--- a/file_%d.txt', $i), $commit);
|
||||
}
|
||||
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$this->assertFileNotExists(TESTS_REPO_PATH_1.sprintf('/file_%d.txt', $i));
|
||||
}
|
||||
}
|
||||
|
||||
public function testRemoveWildcardFile()
|
||||
{
|
||||
$c = $this->getRepository();
|
||||
$hash = $c->removeFile('file_*');
|
||||
$this->assertEquals(40, strlen($hash));
|
||||
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$this->assertFileNotExists(TESTS_REPO_PATH_1.sprintf('/file_%d.txt', $i));
|
||||
}
|
||||
|
||||
$commit = $c->showCommit($hash);
|
||||
$this->assertContains('--- a/file_0.txt', $commit);
|
||||
$this->assertContains('--- a/file_1.txt', $commit);
|
||||
$this->assertContains('--- a/file_2.txt', $commit);
|
||||
$this->assertContains('--- a/file_3.txt', $commit);
|
||||
$this->assertContains('--- a/file_4.txt', $commit);
|
||||
}
|
||||
|
||||
public function testRemoveSubdirectory()
|
||||
{
|
||||
$c = $this->getRepository();
|
||||
$c->writeFile('subdirectory/.gitkeep', '');
|
||||
|
||||
$hash = $c->removeFile('subdirectory', null, true);
|
||||
$this->assertEquals(40, strlen($hash));
|
||||
|
||||
$this->assertFileNotExists(TESTS_REPO_PATH_1.'/subdirectory');
|
||||
|
||||
$commit = $c->showCommit($hash);
|
||||
$this->assertContains('deleted file', $commit);
|
||||
}
|
||||
|
||||
public function testMoveFile()
|
||||
{
|
||||
$c = $this->getRepository();
|
||||
$hash = $c->renameFile('file_0.txt', 'test.txt');
|
||||
$this->assertEquals(40, strlen($hash));
|
||||
|
||||
$this->assertFileNotExists(TESTS_REPO_PATH_1.'/file_0.txt');
|
||||
$this->assertFileExists(TESTS_REPO_PATH_1.'/test.txt');
|
||||
|
||||
$commit = $c->showCommit($hash);
|
||||
$this->assertContains('--- a/file_0.txt', $commit);
|
||||
$this->assertContains('+++ b/test.txt', $commit);
|
||||
}
|
||||
|
||||
public function testReset()
|
||||
{
|
||||
$c = $this->getRepository();
|
||||
$this->assertFalse($c->isDirty());
|
||||
|
||||
$file = TESTS_REPO_PATH_1.'/test.txt';
|
||||
file_put_contents($file, 'Test');
|
||||
$this->assertTrue($c->isDirty());
|
||||
$c->reset();
|
||||
$this->assertFalse($c->isDirty());
|
||||
$this->assertFileNotExists($file);
|
||||
|
||||
file_put_contents($file, 'Test');
|
||||
$c->add(array('test.txt'));
|
||||
$c->reset();
|
||||
$this->assertFalse($c->isDirty());
|
||||
$this->assertFileNotExists($file);
|
||||
|
||||
file_put_contents($file, 'Test');
|
||||
$this->assertTrue($c->isDirty());
|
||||
$c->reset(Repository::RESET_WORKING);
|
||||
$this->assertFalse($c->isDirty());
|
||||
$this->assertFileNotExists($file);
|
||||
|
||||
file_put_contents($file, 'Test');
|
||||
$c->add(array('test.txt'));
|
||||
$this->assertTrue($c->isDirty());
|
||||
$c->reset(Repository::RESET_WORKING);
|
||||
$this->assertTrue($c->isDirty());
|
||||
$this->assertFileExists($file);
|
||||
$c->reset(Repository::RESET_STAGED);
|
||||
$this->assertFalse($c->isDirty());
|
||||
$this->assertFileNotExists($file);
|
||||
}
|
||||
|
||||
public function testTransactionalChangesNoException()
|
||||
{
|
||||
$c = $this->getRepository();
|
||||
|
||||
$result = $c->transactional(function(Transaction $t) {
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$file = $t->getRepositoryPath().'/'.sprintf('test_%s.txt', $i);
|
||||
file_put_contents($file, 'Test');
|
||||
}
|
||||
$t->setCommitMsg('Hello World');
|
||||
return 'This is the return value';
|
||||
});
|
||||
|
||||
$this->assertEquals('This is the return value', $result->getResult());
|
||||
|
||||
$this->assertFalse($c->isDirty());
|
||||
|
||||
$list = $c->listDirectory();
|
||||
$this->assertContains('file_0.txt', $list);
|
||||
$this->assertContains('file_1.txt', $list);
|
||||
$this->assertContains('file_2.txt', $list);
|
||||
$this->assertContains('file_3.txt', $list);
|
||||
$this->assertContains('file_4.txt', $list);
|
||||
$this->assertContains('test_0.txt', $list);
|
||||
$this->assertContains('test_1.txt', $list);
|
||||
$this->assertContains('test_2.txt', $list);
|
||||
$this->assertContains('test_3.txt', $list);
|
||||
$this->assertContains('test_4.txt', $list);
|
||||
|
||||
$commit = $c->showCommit($result->getCommitHash());
|
||||
$this->assertContains($result->getCommitMsg(), $commit);
|
||||
$this->assertContains('+++ b/test_0.txt', $commit);
|
||||
$this->assertContains('+++ b/test_1.txt', $commit);
|
||||
$this->assertContains('+++ b/test_2.txt', $commit);
|
||||
$this->assertContains('+++ b/test_3.txt', $commit);
|
||||
$this->assertContains('+++ b/test_4.txt', $commit);
|
||||
}
|
||||
|
||||
public function testTransactionalChangesException()
|
||||
{
|
||||
$c = $this->getRepository();
|
||||
|
||||
|
||||
try {
|
||||
$result = $c->transactional(function(Transaction $t) {
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$file = $t->getRepositoryPath().'/'.sprintf('test_%s.txt', $i);
|
||||
file_put_contents($file, 'Test');
|
||||
}
|
||||
throw new \Exception('Test');
|
||||
});
|
||||
$this->fail('Exception not thrown');
|
||||
} catch (\Exception $e) {
|
||||
$this->assertEquals('Test', $e->getMessage());
|
||||
$this->assertFalse($c->isDirty());
|
||||
}
|
||||
}
|
||||
|
||||
public function testTransactionalChangesRenameAndDelete()
|
||||
{
|
||||
$c = $this->getRepository();
|
||||
|
||||
$result = $c->transactional(function(Transaction $t) {
|
||||
unlink($t->resolvePath('file_0.txt'));
|
||||
rename($t->resolvePath('file_1.txt'), $t->resolvePath('test.txt'));
|
||||
$t->setCommitMsg('Hello World');
|
||||
return 'This is the return value';
|
||||
});
|
||||
|
||||
$this->assertEquals('This is the return value', $result->getResult());
|
||||
|
||||
$this->assertFalse($c->isDirty());
|
||||
|
||||
$list = $c->listDirectory();
|
||||
$this->assertNotContains('file_0.txt', $list);
|
||||
$this->assertNotContains('file_1.txt', $list);
|
||||
$this->assertContains('test.txt', $list);
|
||||
$this->assertContains('file_2.txt', $list);
|
||||
$this->assertContains('file_3.txt', $list);
|
||||
$this->assertContains('file_4.txt', $list);
|
||||
|
||||
$commit = $c->showCommit($result->getCommitHash());
|
||||
$this->assertContains($result->getCommitMsg(), $commit);
|
||||
$this->assertContains('--- a/file_0.txt', $commit);
|
||||
$this->assertContains('--- a/file_1.txt', $commit);
|
||||
$this->assertContains('+++ b/test.txt', $commit);
|
||||
}
|
||||
|
||||
public function testTransactionalNoChanges()
|
||||
{
|
||||
$c = $this->getRepository();
|
||||
$currentCommit = $c->getCurrentCommit();
|
||||
|
||||
$result = $c->transactional(function(Transaction $t) {
|
||||
$t->setCommitMsg('Hello World');
|
||||
return 'This is the return value';
|
||||
});
|
||||
|
||||
$this->assertEquals('This is the return value', $result->getResult());
|
||||
$this->assertEquals($currentCommit, $result->getCommitHash());
|
||||
$this->assertEquals($currentCommit, $c->getCurrentCommit());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2011 by TEQneers GmbH & Co. KG
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace TQ\Tests\Git\Repository;
|
||||
|
||||
use TQ\Git\Cli\Binary;
|
||||
use TQ\Git\Repository\Repository;
|
||||
use TQ\Tests\Helper;
|
||||
|
||||
class SetupTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Sets up the fixture, for example, open a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
Helper::removeDirectory(TESTS_TMP_PATH);
|
||||
mkdir(TESTS_TMP_PATH, 0777, true);
|
||||
mkdir(TESTS_REPO_PATH_1, 0777, true);
|
||||
mkdir(TESTS_REPO_PATH_2, 0777, true);
|
||||
|
||||
exec(sprintf('cd %s && %s init',
|
||||
escapeshellarg(TESTS_REPO_PATH_1),
|
||||
GIT_BINARY
|
||||
));
|
||||
|
||||
clearstatcache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, close a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
Helper::removeDirectory(TESTS_TMP_PATH);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $path
|
||||
* @paran boolean|integer $create
|
||||
* @return Repository
|
||||
*/
|
||||
protected function getRepository($path, $create = false)
|
||||
{
|
||||
return Repository::open($path, new Binary(GIT_BINARY), $create);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testRepositoryOpenOnNonExistantPath()
|
||||
{
|
||||
$c = $this->getRepository('/does/not/exist', false);
|
||||
}
|
||||
|
||||
public function testRepositoryOpenOnFile()
|
||||
{
|
||||
$c = $this->getRepository(__FILE__, false);
|
||||
$this->assertInstanceOf('TQ\Git\Repository\Repository', $c);
|
||||
$this->assertEquals(PROJECT_PATH, $c->getRepositoryPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testRepositoryOpenOnNonRepositoryPath()
|
||||
{
|
||||
$c = $this->getRepository('/usr', false);
|
||||
}
|
||||
|
||||
public function testRepositoryOpenOnRepositoryPath()
|
||||
{
|
||||
$c = $this->getRepository(TESTS_REPO_PATH_1, false);
|
||||
$this->assertInstanceOf('TQ\Git\Repository\Repository', $c);
|
||||
}
|
||||
|
||||
public function testRepositoryCreateOnExistingRepositoryPath()
|
||||
{
|
||||
$c = $this->getRepository(TESTS_REPO_PATH_1, 0755);
|
||||
$this->assertInstanceOf('TQ\Git\Repository\Repository', $c);
|
||||
}
|
||||
|
||||
public function testRepositoryCreateOnFile()
|
||||
{
|
||||
$c = $this->getRepository(__FILE__, 0755);
|
||||
$this->assertInstanceOf('TQ\Git\Repository\Repository', $c);
|
||||
$this->assertEquals(PROJECT_PATH, $c->getRepositoryPath());
|
||||
}
|
||||
|
||||
public function testRepositoryCreateOnExistingPath()
|
||||
{
|
||||
$c = $this->getRepository(TESTS_REPO_PATH_2, 0755);
|
||||
$this->assertInstanceOf('TQ\Git\Repository\Repository', $c);
|
||||
}
|
||||
|
||||
public function testRepositoryCreateOnCreateablePath()
|
||||
{
|
||||
$c = $this->getRepository(TESTS_REPO_PATH_3, 0755);
|
||||
$this->assertInstanceOf('TQ\Git\Repository\Repository', $c);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2011 by TEQneers GmbH & Co. KG
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace TQ\Tests\Git\StreamWrapper;
|
||||
|
||||
use TQ\Git\StreamWrapper\DirectoryBuffer;
|
||||
|
||||
class DirectoryBufferTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testIteration()
|
||||
{
|
||||
$listing = array('a', 'b', 'c');
|
||||
$iterator = new DirectoryBuffer($listing);
|
||||
$i = 0;
|
||||
while($iterator->valid()) {
|
||||
$this->assertEquals($listing[$i], $iterator->current());
|
||||
$this->assertEquals($i, $iterator->key());
|
||||
$i++;
|
||||
$iterator->next();
|
||||
}
|
||||
$this->assertEquals(count($listing), $i);
|
||||
|
||||
$iterator->rewind();
|
||||
$this->assertEquals(reset($listing), $iterator->current());
|
||||
$this->assertEquals(key($listing), $iterator->key());
|
||||
}
|
||||
|
||||
public function testForeach()
|
||||
{
|
||||
$listing = array('a', 'b', 'c');
|
||||
$iterator = new DirectoryBuffer($listing);
|
||||
$i = 0;
|
||||
foreach ($iterator as $k => $v) {
|
||||
$this->assertEquals($listing[$i], $v);
|
||||
$this->assertEquals($i, $k);
|
||||
$i++;
|
||||
}
|
||||
$this->assertEquals(count($listing), $i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,471 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2011 by TEQneers GmbH & Co. KG
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace TQ\Tests\Git\StreamWrapper;
|
||||
|
||||
use TQ\Git\Cli\Binary;
|
||||
use TQ\Git\Repository\Repository;
|
||||
use TQ\Git\StreamWrapper\StreamWrapper;
|
||||
use TQ\Tests\Helper;
|
||||
|
||||
class DirectoryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Sets up the fixture, for example, open a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
Helper::removeDirectory(TESTS_TMP_PATH);
|
||||
mkdir(TESTS_TMP_PATH, 0777, true);
|
||||
mkdir(TESTS_REPO_PATH_1, 0777, true);
|
||||
|
||||
exec(sprintf('cd %s && %s init',
|
||||
escapeshellarg(TESTS_REPO_PATH_1),
|
||||
GIT_BINARY
|
||||
));
|
||||
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$file = sprintf('file_%d.txt', $i);
|
||||
$path = TESTS_REPO_PATH_1.'/'.$file;
|
||||
file_put_contents($path, sprintf('File %d', $i));
|
||||
exec(sprintf('cd %s && %s add %s',
|
||||
escapeshellarg(TESTS_REPO_PATH_1),
|
||||
GIT_BINARY,
|
||||
escapeshellarg($file)
|
||||
));
|
||||
}
|
||||
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$dir = sprintf('dir_%d', $i);
|
||||
$path = TESTS_REPO_PATH_1.'/'.$dir;
|
||||
mkdir($path, 0777);
|
||||
file_put_contents($path.'/file.txt', sprintf('Directory %d File', $i));
|
||||
exec(sprintf('cd %s && %s add %s',
|
||||
escapeshellarg(TESTS_REPO_PATH_1),
|
||||
GIT_BINARY,
|
||||
escapeshellarg($path)
|
||||
));
|
||||
}
|
||||
|
||||
exec(sprintf('cd %s && %s commit --message=%s',
|
||||
escapeshellarg(TESTS_REPO_PATH_1),
|
||||
GIT_BINARY,
|
||||
escapeshellarg('Initial commit')
|
||||
));
|
||||
|
||||
clearstatcache();
|
||||
|
||||
StreamWrapper::register('git', new Binary(GIT_BINARY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, close a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
Helper::removeDirectory(TESTS_TMP_PATH);
|
||||
|
||||
StreamWrapper::unregister();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Repository
|
||||
*/
|
||||
protected function getRepository()
|
||||
{
|
||||
return Repository::open(TESTS_REPO_PATH_1, new Binary(GIT_BINARY));
|
||||
}
|
||||
|
||||
public function testListDirectory()
|
||||
{
|
||||
$dir = opendir('git://'.TESTS_REPO_PATH_1);
|
||||
$i = 0;
|
||||
while ($f = readdir($dir)) {
|
||||
if ($i < 5) {
|
||||
$this->assertEquals(sprintf('dir_%d', $i), $f);
|
||||
} else {
|
||||
$this->assertEquals(sprintf('file_%d.txt', $i % 5), $f);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
closedir($dir);
|
||||
$this->assertEquals(10, $i);
|
||||
}
|
||||
|
||||
public function testListSubDirectory()
|
||||
{
|
||||
$dir = opendir('git://'.TESTS_REPO_PATH_1.'/dir_0');
|
||||
$i = 0;
|
||||
while ($f = readdir($dir)) {
|
||||
$this->assertEquals('file.txt', $f);
|
||||
$i++;
|
||||
}
|
||||
closedir($dir);
|
||||
$this->assertEquals(1, $i);
|
||||
}
|
||||
|
||||
public function testListDirectoryWithRef()
|
||||
{
|
||||
$c = $this->getRepository();
|
||||
$firstCommit = $c->writeFile('test_0.txt', 'Test 0');
|
||||
$c->writeFile('test_1.txt', 'Test 1');
|
||||
|
||||
$dir = opendir('git://'.TESTS_REPO_PATH_1);
|
||||
$i = 0;
|
||||
while ($f = readdir($dir)) {
|
||||
if ($i < 5) {
|
||||
$this->assertEquals(sprintf('dir_%d', $i), $f);
|
||||
} else if ($i < 10) {
|
||||
$this->assertEquals(sprintf('file_%d.txt', $i % 5), $f);
|
||||
} else {
|
||||
$this->assertEquals(sprintf('test_%d.txt', $i % 10), $f);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
closedir($dir);
|
||||
$this->assertEquals(12, $i);
|
||||
|
||||
$dir = opendir('git://'.TESTS_REPO_PATH_1.'#HEAD^');
|
||||
$i = 0;
|
||||
while ($f = readdir($dir)) {
|
||||
if ($i < 5) {
|
||||
$this->assertEquals(sprintf('dir_%d', $i), $f);
|
||||
} else if ($i < 10) {
|
||||
$this->assertEquals(sprintf('file_%d.txt', $i % 5), $f);
|
||||
} else {
|
||||
$this->assertEquals(sprintf('test_%d.txt', $i % 10), $f);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
closedir($dir);
|
||||
$this->assertEquals(11, $i);
|
||||
|
||||
$dir = opendir('git://'.TESTS_REPO_PATH_1.'#HEAD^^');
|
||||
$i = 0;
|
||||
while ($f = readdir($dir)) {
|
||||
if ($i < 5) {
|
||||
$this->assertEquals(sprintf('dir_%d', $i), $f);
|
||||
} else {
|
||||
$this->assertEquals(sprintf('file_%d.txt', $i % 5), $f);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
closedir($dir);
|
||||
$this->assertEquals(10, $i);
|
||||
|
||||
$dir = opendir('git://'.TESTS_REPO_PATH_1.'#'.$firstCommit);
|
||||
$i = 0;
|
||||
while ($f = readdir($dir)) {
|
||||
if ($i < 5) {
|
||||
$this->assertEquals(sprintf('dir_%d', $i), $f);
|
||||
} else if ($i < 10) {
|
||||
$this->assertEquals(sprintf('file_%d.txt', $i % 5), $f);
|
||||
} else {
|
||||
$this->assertEquals(sprintf('test_%d.txt', $i % 10), $f);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
closedir($dir);
|
||||
$this->assertEquals(11, $i);
|
||||
}
|
||||
|
||||
public function testListDirectoryWithIterator()
|
||||
{
|
||||
$dir = new \FilesystemIterator(
|
||||
'git://'.TESTS_REPO_PATH_1,
|
||||
\FilesystemIterator::KEY_AS_FILENAME | \FilesystemIterator::CURRENT_AS_FILEINFO
|
||||
);
|
||||
$i = 0;
|
||||
foreach ($dir as $f => $fi) {
|
||||
if ($i < 5) {
|
||||
$this->assertEquals(sprintf('dir_%d', $i), $f);
|
||||
} else {
|
||||
$this->assertEquals(sprintf('file_%d.txt', $i % 5), $f);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
$this->assertEquals(10, $i);
|
||||
}
|
||||
|
||||
public function testListDirectoryWithRecursiveIterator()
|
||||
{
|
||||
$dir = new \RecursiveDirectoryIterator(
|
||||
'git://'.TESTS_REPO_PATH_1,
|
||||
\FilesystemIterator::KEY_AS_FILENAME | \FilesystemIterator::CURRENT_AS_FILEINFO
|
||||
);
|
||||
$it = new \RecursiveIteratorIterator($dir, \RecursiveIteratorIterator::SELF_FIRST);
|
||||
$i = 0;
|
||||
foreach ($it as $f => $fi) {
|
||||
if ($i < 10) {
|
||||
if ($i % 2 === 0) {
|
||||
$this->assertEquals(sprintf('dir_%d', $i / 2), $f);
|
||||
} else {
|
||||
$this->assertEquals('file.txt', $f);
|
||||
}
|
||||
} else {
|
||||
$this->assertEquals(sprintf('file_%d.txt', $i % 5), $f);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
$this->assertEquals(15, $i);
|
||||
}
|
||||
|
||||
public function testListDirectoryWithRefWithRecursiveIterator()
|
||||
{
|
||||
$c = $this->getRepository();
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$dir = sprintf('dir_%d', $i);
|
||||
$path = TESTS_REPO_PATH_1.'/'.$dir.'/test.txt';
|
||||
$c->writeFile($path, 'Test');
|
||||
}
|
||||
$c->writeFile('test.txt', 'Test');
|
||||
|
||||
$dir = new \RecursiveDirectoryIterator(
|
||||
'git://'.TESTS_REPO_PATH_1,
|
||||
\FilesystemIterator::KEY_AS_FILENAME | \FilesystemIterator::CURRENT_AS_FILEINFO
|
||||
);
|
||||
$it = new \RecursiveIteratorIterator($dir, \RecursiveIteratorIterator::SELF_FIRST);
|
||||
$i = 0;
|
||||
$ex = array(
|
||||
'dir_0',
|
||||
'file.txt',
|
||||
'test.txt',
|
||||
'dir_1',
|
||||
'file.txt',
|
||||
'test.txt',
|
||||
'dir_2',
|
||||
'file.txt',
|
||||
'test.txt',
|
||||
'dir_3',
|
||||
'file.txt',
|
||||
'test.txt',
|
||||
'dir_4',
|
||||
'file.txt',
|
||||
'test.txt',
|
||||
'file_0.txt',
|
||||
'file_1.txt',
|
||||
'file_2.txt',
|
||||
'file_3.txt',
|
||||
'file_4.txt',
|
||||
'test.txt'
|
||||
);
|
||||
foreach ($it as $f => $fi) {
|
||||
$this->assertEquals($ex[$i], $f);
|
||||
$i++;
|
||||
}
|
||||
$this->assertEquals(count($ex), $i);
|
||||
|
||||
$dir = new \RecursiveDirectoryIterator(
|
||||
'git://'.TESTS_REPO_PATH_1.'#HEAD^',
|
||||
\FilesystemIterator::KEY_AS_FILENAME | \FilesystemIterator::CURRENT_AS_FILEINFO
|
||||
);
|
||||
$it = new \RecursiveIteratorIterator($dir, \RecursiveIteratorIterator::SELF_FIRST);
|
||||
$i = 0;
|
||||
$ex = array(
|
||||
'dir_0',
|
||||
'file.txt',
|
||||
'test.txt',
|
||||
'dir_1',
|
||||
'file.txt',
|
||||
'test.txt',
|
||||
'dir_2',
|
||||
'file.txt',
|
||||
'test.txt',
|
||||
'dir_3',
|
||||
'file.txt',
|
||||
'test.txt',
|
||||
'dir_4',
|
||||
'file.txt',
|
||||
'test.txt',
|
||||
'file_0.txt',
|
||||
'file_1.txt',
|
||||
'file_2.txt',
|
||||
'file_3.txt',
|
||||
'file_4.txt',
|
||||
);
|
||||
foreach ($it as $f => $fi) {
|
||||
$this->assertEquals($ex[$i], $f);
|
||||
$i++;
|
||||
}
|
||||
$this->assertEquals(count($ex), $i);
|
||||
|
||||
$dir = new \RecursiveDirectoryIterator(
|
||||
'git://'.TESTS_REPO_PATH_1.'#HEAD^^',
|
||||
\FilesystemIterator::KEY_AS_FILENAME | \FilesystemIterator::CURRENT_AS_FILEINFO
|
||||
);
|
||||
$it = new \RecursiveIteratorIterator($dir, \RecursiveIteratorIterator::SELF_FIRST);
|
||||
$i = 0;
|
||||
$ex = array(
|
||||
'dir_0',
|
||||
'file.txt',
|
||||
'test.txt',
|
||||
'dir_1',
|
||||
'file.txt',
|
||||
'test.txt',
|
||||
'dir_2',
|
||||
'file.txt',
|
||||
'test.txt',
|
||||
'dir_3',
|
||||
'file.txt',
|
||||
'test.txt',
|
||||
'dir_4',
|
||||
'file.txt',
|
||||
'file_0.txt',
|
||||
'file_1.txt',
|
||||
'file_2.txt',
|
||||
'file_3.txt',
|
||||
'file_4.txt'
|
||||
);
|
||||
foreach ($it as $f => $fi) {
|
||||
$this->assertEquals($ex[$i], $f);
|
||||
$i++;
|
||||
}
|
||||
$this->assertEquals(count($ex), $i);
|
||||
|
||||
$dir = new \RecursiveDirectoryIterator(
|
||||
'git://'.TESTS_REPO_PATH_1.'#HEAD^^^',
|
||||
\FilesystemIterator::KEY_AS_FILENAME | \FilesystemIterator::CURRENT_AS_FILEINFO
|
||||
);
|
||||
$it = new \RecursiveIteratorIterator($dir, \RecursiveIteratorIterator::SELF_FIRST);
|
||||
$i = 0;
|
||||
$ex = array(
|
||||
'dir_0',
|
||||
'file.txt',
|
||||
'test.txt',
|
||||
'dir_1',
|
||||
'file.txt',
|
||||
'test.txt',
|
||||
'dir_2',
|
||||
'file.txt',
|
||||
'test.txt',
|
||||
'dir_3',
|
||||
'file.txt',
|
||||
'dir_4',
|
||||
'file.txt',
|
||||
'file_0.txt',
|
||||
'file_1.txt',
|
||||
'file_2.txt',
|
||||
'file_3.txt',
|
||||
'file_4.txt'
|
||||
);
|
||||
foreach ($it as $f => $fi) {
|
||||
$this->assertEquals($ex[$i], $f);
|
||||
$i++;
|
||||
}
|
||||
$this->assertEquals(count($ex), $i);
|
||||
|
||||
$dir = new \RecursiveDirectoryIterator(
|
||||
'git://'.TESTS_REPO_PATH_1.'#HEAD^^^^',
|
||||
\FilesystemIterator::KEY_AS_FILENAME | \FilesystemIterator::CURRENT_AS_FILEINFO
|
||||
);
|
||||
$it = new \RecursiveIteratorIterator($dir, \RecursiveIteratorIterator::SELF_FIRST);
|
||||
$i = 0;
|
||||
$ex = array(
|
||||
'dir_0',
|
||||
'file.txt',
|
||||
'test.txt',
|
||||
'dir_1',
|
||||
'file.txt',
|
||||
'test.txt',
|
||||
'dir_2',
|
||||
'file.txt',
|
||||
'dir_3',
|
||||
'file.txt',
|
||||
'dir_4',
|
||||
'file.txt',
|
||||
'file_0.txt',
|
||||
'file_1.txt',
|
||||
'file_2.txt',
|
||||
'file_3.txt',
|
||||
'file_4.txt'
|
||||
);
|
||||
foreach ($it as $f => $fi) {
|
||||
$this->assertEquals($ex[$i], $f);
|
||||
$i++;
|
||||
}
|
||||
$this->assertEquals(count($ex), $i);
|
||||
|
||||
$dir = new \RecursiveDirectoryIterator(
|
||||
'git://'.TESTS_REPO_PATH_1.'#HEAD^^^^^',
|
||||
\FilesystemIterator::KEY_AS_FILENAME | \FilesystemIterator::CURRENT_AS_FILEINFO
|
||||
);
|
||||
$it = new \RecursiveIteratorIterator($dir, \RecursiveIteratorIterator::SELF_FIRST);
|
||||
$i = 0;
|
||||
$ex = array(
|
||||
'dir_0',
|
||||
'file.txt',
|
||||
'test.txt',
|
||||
'dir_1',
|
||||
'file.txt',
|
||||
'dir_2',
|
||||
'file.txt',
|
||||
'dir_3',
|
||||
'file.txt',
|
||||
'dir_4',
|
||||
'file.txt',
|
||||
'file_0.txt',
|
||||
'file_1.txt',
|
||||
'file_2.txt',
|
||||
'file_3.txt',
|
||||
'file_4.txt'
|
||||
);
|
||||
foreach ($it as $f => $fi) {
|
||||
$this->assertEquals($ex[$i], $f);
|
||||
$i++;
|
||||
}
|
||||
$this->assertEquals(count($ex), $i);
|
||||
|
||||
$dir = new \RecursiveDirectoryIterator(
|
||||
'git://'.TESTS_REPO_PATH_1.'#HEAD^^^^^^',
|
||||
\FilesystemIterator::KEY_AS_FILENAME | \FilesystemIterator::CURRENT_AS_FILEINFO
|
||||
);
|
||||
$it = new \RecursiveIteratorIterator($dir, \RecursiveIteratorIterator::SELF_FIRST);
|
||||
$i = 0;
|
||||
$ex = array(
|
||||
'dir_0',
|
||||
'file.txt',
|
||||
'dir_1',
|
||||
'file.txt',
|
||||
'dir_2',
|
||||
'file.txt',
|
||||
'dir_3',
|
||||
'file.txt',
|
||||
'dir_4',
|
||||
'file.txt',
|
||||
'file_0.txt',
|
||||
'file_1.txt',
|
||||
'file_2.txt',
|
||||
'file_3.txt',
|
||||
'file_4.txt'
|
||||
);
|
||||
foreach ($it as $f => $fi) {
|
||||
$this->assertEquals($ex[$i], $f);
|
||||
$i++;
|
||||
}
|
||||
$this->assertEquals(count($ex), $i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2011 by TEQneers GmbH & Co. KG
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace TQ\Tests\Git\StreamWrapper\FileBuffer\Factory;
|
||||
|
||||
use TQ\Git\StreamWrapper\FileBuffer\Factory\Resolver;
|
||||
use TQ\Git\StreamWrapper\FileBuffer\Factory\Factory;
|
||||
use TQ\Git\StreamWrapper\PathInformation;
|
||||
|
||||
class ResolverTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @return PathInformation
|
||||
*/
|
||||
protected function createPathMock()
|
||||
{
|
||||
return $this->getMock(
|
||||
'TQ\Git\StreamWrapper\PathInformation',
|
||||
array(),
|
||||
array(),
|
||||
'',
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Factory
|
||||
*/
|
||||
protected function createFactoryMock()
|
||||
{
|
||||
return $this->getMock(
|
||||
'TQ\Git\StreamWrapper\FileBuffer\Factory\Factory',
|
||||
array('canHandle', 'createFileBuffer')
|
||||
);
|
||||
}
|
||||
|
||||
public function testReturnsFactoryWhichIsResponsible()
|
||||
{
|
||||
$resolver = new Resolver();
|
||||
|
||||
$factory1 = $this->createFactoryMock();
|
||||
$factory1->expects($this->any())
|
||||
->method('canHandle')
|
||||
->will($this->returnValue(true));
|
||||
$factory2 = $this->createFactoryMock();
|
||||
$factory2->expects($this->any())
|
||||
->method('canHandle')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$resolver->addFactory($factory1, 10);
|
||||
$resolver->addFactory($factory2, 30);
|
||||
|
||||
$path = $this->createPathMock();
|
||||
|
||||
$this->assertSame($factory1, $resolver->findFactory($path, 'r+'));
|
||||
}
|
||||
|
||||
public function testReturnsFactoryWithHigherPriority()
|
||||
{
|
||||
$resolver = new Resolver();
|
||||
|
||||
$factory1 = $this->createFactoryMock();
|
||||
$factory1->expects($this->any())
|
||||
->method('canHandle')
|
||||
->will($this->returnValue(true));
|
||||
$factory2 = $this->createFactoryMock();
|
||||
$factory2->expects($this->any())
|
||||
->method('canHandle')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$resolver->addFactory($factory1, 10);
|
||||
$resolver->addFactory($factory2, 30);
|
||||
|
||||
$path = $this->createPathMock();
|
||||
|
||||
$this->assertSame($factory2, $resolver->findFactory($path, 'r+'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testFailsWithoutAnyFactoryResponsible()
|
||||
{
|
||||
$resolver = new Resolver();
|
||||
|
||||
$factory1 = $this->createFactoryMock();
|
||||
$factory1->expects($this->any())
|
||||
->method('canHandle')
|
||||
->will($this->returnValue(false));
|
||||
$factory2 = $this->createFactoryMock();
|
||||
$factory2->expects($this->any())
|
||||
->method('canHandle')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$resolver->addFactory($factory1, 10);
|
||||
$resolver->addFactory($factory2, 30);
|
||||
|
||||
$path = $this->createPathMock();
|
||||
|
||||
$resolver->findFactory($path, 'r+');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2011 by TEQneers GmbH & Co. KG
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace TQ\Tests\Git\StreamWrapper\FileBuffer;
|
||||
|
||||
use TQ\Git\StreamWrapper\FileBuffer\StreamBuffer;
|
||||
use TQ\Tests\Helper;
|
||||
|
||||
class StreamBufferTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Sets up the fixture, for example, open a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
Helper::removeDirectory(TESTS_TMP_PATH);
|
||||
mkdir(TESTS_TMP_PATH, 0777, true);
|
||||
|
||||
file_put_contents(TESTS_TMP_PATH.'/file_0.txt', 'File 0');
|
||||
file_put_contents(TESTS_TMP_PATH.'/abc.txt', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ');
|
||||
touch(TESTS_TMP_PATH.'/empty.txt');
|
||||
|
||||
clearstatcache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, close a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
Helper::removeDirectory(TESTS_TMP_PATH);
|
||||
}
|
||||
|
||||
public function testReadByByte()
|
||||
{
|
||||
$expected = 'File 0';
|
||||
$buffer = new StreamBuffer(TESTS_TMP_PATH.'/file_0.txt');
|
||||
$expLength = strlen($expected);
|
||||
for ($i = 0; $i < $expLength; $i++) {
|
||||
$this->assertEquals($i, $buffer->getPosition());
|
||||
$char = $buffer->read(1);
|
||||
$this->assertEquals($expected[$i], $char);
|
||||
$this->assertEquals($i + 1, $buffer->getPosition());
|
||||
}
|
||||
}
|
||||
|
||||
public function testSeek()
|
||||
{
|
||||
$expected = 'File 0';
|
||||
$buffer = new StreamBuffer(TESTS_TMP_PATH.'/file_0.txt');
|
||||
|
||||
$buffer->setPosition(-1, SEEK_END);
|
||||
$this->assertEquals('0', $buffer->read(1));
|
||||
$this->assertEquals(6, $buffer->getPosition());
|
||||
$this->assertFalse($buffer->isEof());
|
||||
$this->assertEmpty($buffer->read(1));
|
||||
$this->assertTrue($buffer->isEof());
|
||||
|
||||
$buffer->setPosition(0, SEEK_SET);
|
||||
$this->assertEquals('F', $buffer->read(1));
|
||||
$this->assertEquals(1, $buffer->getPosition());
|
||||
|
||||
$buffer->setPosition(3, SEEK_CUR);
|
||||
$this->assertEquals(' ', $buffer->read(1));
|
||||
$this->assertEquals(5, $buffer->getPosition());
|
||||
|
||||
$buffer->setPosition(-2, SEEK_CUR);
|
||||
$this->assertEquals('e', $buffer->read(1));
|
||||
$this->assertEquals(4, $buffer->getPosition());
|
||||
}
|
||||
|
||||
public function testReadInReverse()
|
||||
{
|
||||
$buffer = new StreamBuffer(TESTS_TMP_PATH.'/file_0.txt');
|
||||
$expected = '0 eliF';
|
||||
$actual = '';
|
||||
|
||||
$buffer->setPosition(-1, SEEK_END);
|
||||
while (($pos = $buffer->getPosition()) > 0) {
|
||||
$actual .= $buffer->read(1);
|
||||
$buffer->setPosition(-2, SEEK_CUR);
|
||||
}
|
||||
$actual .= $buffer->read(1);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testWriteInMiddle()
|
||||
{
|
||||
$buffer = new StreamBuffer(TESTS_TMP_PATH.'/abc.txt');
|
||||
$expected = 'ABC1234567890NOPQRSTUVWXYZ';
|
||||
$buffer->setPosition(3, SEEK_SET);
|
||||
$buffer->write('1234567890');
|
||||
$actual = $buffer->getBuffer();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testWriteAtStart()
|
||||
{
|
||||
$buffer = new StreamBuffer(TESTS_TMP_PATH.'/abc.txt');
|
||||
$expected = '1234567890KLMNOPQRSTUVWXYZ';
|
||||
$buffer->setPosition(0, SEEK_SET);
|
||||
$buffer->write('1234567890');
|
||||
$actual = $buffer->getBuffer();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testWriteAtEnd()
|
||||
{
|
||||
$buffer = new StreamBuffer(TESTS_TMP_PATH.'/abc.txt');
|
||||
$expected = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
|
||||
$buffer->setPosition(0, SEEK_END);
|
||||
$buffer->write('1234567890');
|
||||
$actual = $buffer->getBuffer();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testWriteOverlappingEnd()
|
||||
{
|
||||
$buffer = new StreamBuffer(TESTS_TMP_PATH.'/abc.txt');
|
||||
$expected = 'ABCDEFGHIJKLMNOPQRSTUVW1234567890';
|
||||
$buffer->setPosition(-3, SEEK_END);
|
||||
$buffer->write('1234567890');
|
||||
$actual = $buffer->getBuffer();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testWriteInEmptyBuffer()
|
||||
{
|
||||
$buffer = new StreamBuffer(TESTS_TMP_PATH.'/empty.txt');
|
||||
$expected = '1234567890';
|
||||
$buffer->write('1234567890');
|
||||
$actual = $buffer->getBuffer();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2011 by TEQneers GmbH & Co. KG
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace TQ\Tests\Git\StreamWrapper\FileBuffer;
|
||||
|
||||
use TQ\Git\StreamWrapper\FileBuffer\StringBuffer;
|
||||
|
||||
class StringBufferTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testReadByByte()
|
||||
{
|
||||
$expected = 'File 0';
|
||||
$buffer = new StringBuffer($expected);
|
||||
$expLength = strlen($expected);
|
||||
for ($i = 0; $i < $expLength; $i++) {
|
||||
$this->assertEquals($i, $buffer->getPosition());
|
||||
$char = $buffer->read(1);
|
||||
$this->assertEquals($expected[$i], $char);
|
||||
$this->assertEquals($i + 1, $buffer->getPosition());
|
||||
}
|
||||
}
|
||||
|
||||
public function testSeek()
|
||||
{
|
||||
$expected = 'File 0';
|
||||
$buffer = new StringBuffer($expected);
|
||||
|
||||
$buffer->setPosition(-1, SEEK_END);
|
||||
$this->assertEquals('0', $buffer->read(1));
|
||||
$this->assertEquals(6, $buffer->getPosition());
|
||||
$this->assertFalse($buffer->isEof());
|
||||
$this->assertEmpty($buffer->read(1));
|
||||
$this->assertTrue($buffer->isEof());
|
||||
|
||||
$buffer->setPosition(0, SEEK_SET);
|
||||
$this->assertEquals('F', $buffer->read(1));
|
||||
$this->assertEquals(1, $buffer->getPosition());
|
||||
|
||||
$buffer->setPosition(3, SEEK_CUR);
|
||||
$this->assertEquals(' ', $buffer->read(1));
|
||||
$this->assertEquals(5, $buffer->getPosition());
|
||||
|
||||
$buffer->setPosition(-2, SEEK_CUR);
|
||||
$this->assertEquals('e', $buffer->read(1));
|
||||
$this->assertEquals(4, $buffer->getPosition());
|
||||
}
|
||||
|
||||
public function testReadInReverse()
|
||||
{
|
||||
$buffer = new StringBuffer('File 0');
|
||||
$expected = '0 eliF';
|
||||
$actual = '';
|
||||
|
||||
$buffer->setPosition(-1, SEEK_END);
|
||||
while (($pos = $buffer->getPosition()) > 0) {
|
||||
$actual .= $buffer->read(1);
|
||||
$buffer->setPosition(-2, SEEK_CUR);
|
||||
}
|
||||
$actual .= $buffer->read(1);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testWriteInMiddle()
|
||||
{
|
||||
$buffer = new StringBuffer('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
|
||||
$expected = 'ABC1234567890NOPQRSTUVWXYZ';
|
||||
$buffer->setPosition(3, SEEK_SET);
|
||||
$buffer->write('1234567890');
|
||||
$actual = $buffer->getBuffer();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testWriteAtStart()
|
||||
{
|
||||
$buffer = new StringBuffer('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
|
||||
$expected = '1234567890KLMNOPQRSTUVWXYZ';
|
||||
$buffer->setPosition(0, SEEK_SET);
|
||||
$buffer->write('1234567890');
|
||||
$actual = $buffer->getBuffer();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testWriteAtEnd()
|
||||
{
|
||||
$buffer = new StringBuffer('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
|
||||
$expected = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
|
||||
$buffer->setPosition(0, SEEK_END);
|
||||
$buffer->write('1234567890');
|
||||
$actual = $buffer->getBuffer();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testWriteOverlappingEnd()
|
||||
{
|
||||
$buffer = new StringBuffer('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
|
||||
$expected = 'ABCDEFGHIJKLMNOPQRSTUVW1234567890';
|
||||
$buffer->setPosition(-3, SEEK_END);
|
||||
$buffer->write('1234567890');
|
||||
$actual = $buffer->getBuffer();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testWriteInEmptyBuffer()
|
||||
{
|
||||
$buffer = new StringBuffer('');
|
||||
$expected = '1234567890';
|
||||
$buffer->write('1234567890');
|
||||
$actual = $buffer->getBuffer();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testSeekBeyondLimits()
|
||||
{
|
||||
$buffer = new StringBuffer('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
|
||||
$this->assertFalse($buffer->setPosition(-5, SEEK_SET));
|
||||
$this->assertEquals(0, $buffer->getPosition());
|
||||
|
||||
$this->assertFalse($buffer->setPosition(4711, SEEK_SET));
|
||||
$this->assertEquals(26, $buffer->getPosition());
|
||||
}
|
||||
|
||||
public function testSeekWithIllegalWhence()
|
||||
{
|
||||
$buffer = new StringBuffer('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
|
||||
$this->assertFalse($buffer->setPosition(5, 4711));
|
||||
$this->assertEquals(0, $buffer->getPosition());
|
||||
}
|
||||
|
||||
public function testLengthAndPositionUpdatedWithWrite()
|
||||
{
|
||||
$buffer = new StringBuffer('');
|
||||
$this->assertEquals(0, $buffer->getPosition());
|
||||
$this->assertEquals(0, $buffer->getLength());
|
||||
|
||||
$buffer->write('1');
|
||||
$this->assertEquals(1, $buffer->getPosition());
|
||||
$this->assertEquals(1, $buffer->getLength());
|
||||
|
||||
$buffer->write('23');
|
||||
$this->assertEquals(3, $buffer->getPosition());
|
||||
$this->assertEquals(3, $buffer->getLength());
|
||||
|
||||
$buffer->setPosition(-2, SEEK_CUR);
|
||||
$this->assertEquals(1, $buffer->getPosition());
|
||||
|
||||
$buffer->write('4');
|
||||
$this->assertEquals(2, $buffer->getPosition());
|
||||
$this->assertEquals(3, $buffer->getLength());
|
||||
|
||||
$this->assertEquals('143', $buffer->getBuffer());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,359 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2011 by TEQneers GmbH & Co. KG
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace TQ\Tests\Git\StreamWrapper;
|
||||
|
||||
use TQ\Git\Cli\Binary;
|
||||
use TQ\Git\Repository\Repository;
|
||||
use TQ\Git\StreamWrapper\StreamWrapper;
|
||||
use TQ\Tests\Helper;
|
||||
|
||||
class FileOperationTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Sets up the fixture, for example, open a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
Helper::removeDirectory(TESTS_TMP_PATH);
|
||||
mkdir(TESTS_TMP_PATH, 0777, true);
|
||||
mkdir(TESTS_REPO_PATH_1, 0777, true);
|
||||
|
||||
exec(sprintf('cd %s && %s init',
|
||||
escapeshellarg(TESTS_REPO_PATH_1),
|
||||
GIT_BINARY
|
||||
));
|
||||
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$file = sprintf('file_%d.txt', $i);
|
||||
$path = TESTS_REPO_PATH_1.'/'.$file;
|
||||
file_put_contents($path, sprintf('File %d', $i));
|
||||
exec(sprintf('cd %s && %s add %s',
|
||||
escapeshellarg(TESTS_REPO_PATH_1),
|
||||
GIT_BINARY,
|
||||
escapeshellarg($file)
|
||||
));
|
||||
}
|
||||
|
||||
exec(sprintf('cd %s && %s commit --message=%s',
|
||||
escapeshellarg(TESTS_REPO_PATH_1),
|
||||
GIT_BINARY,
|
||||
escapeshellarg('Initial commit')
|
||||
));
|
||||
|
||||
clearstatcache();
|
||||
|
||||
StreamWrapper::register('git', new Binary(GIT_BINARY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, close a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
Helper::removeDirectory(TESTS_TMP_PATH);
|
||||
|
||||
StreamWrapper::unregister();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Repository
|
||||
*/
|
||||
protected function getRepository()
|
||||
{
|
||||
return Repository::open(TESTS_REPO_PATH_1, new Binary(GIT_BINARY));
|
||||
}
|
||||
|
||||
public function testUnlinkFile()
|
||||
{
|
||||
$path = sprintf('git://%s/file_0.txt', TESTS_REPO_PATH_1);
|
||||
unlink($path);
|
||||
|
||||
$this->assertFileNotExists(TESTS_REPO_PATH_1.'/file_0.txt');
|
||||
|
||||
$c = $this->getRepository();
|
||||
$commit = $c->showCommit($c->getCurrentCommit());
|
||||
$this->assertContains('--- a/file_0.txt', $commit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPUnit_Framework_Error_Warning
|
||||
*/
|
||||
public function testUnlinkFileNonHead()
|
||||
{
|
||||
$path = sprintf('git://%s/file_0.txt#HEAD^', TESTS_REPO_PATH_1);
|
||||
unlink($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPUnit_Framework_Error_Warning
|
||||
*/
|
||||
public function testUnlinkNonExistantFile()
|
||||
{
|
||||
$path = sprintf('git://%s/file_does_not_exist.txt', TESTS_REPO_PATH_1);
|
||||
unlink($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPUnit_Framework_Error_Warning
|
||||
*/
|
||||
public function testUnlinkNonFile()
|
||||
{
|
||||
$c = $this->getRepository();
|
||||
$c->writeFile('directory/test.txt', 'Test');
|
||||
|
||||
$path = sprintf('git://%s/directory', TESTS_REPO_PATH_1);
|
||||
unlink($path);
|
||||
}
|
||||
|
||||
public function testUnlinkFileWithContext()
|
||||
{
|
||||
$path = sprintf('git://%s/file_0.txt', TESTS_REPO_PATH_1);
|
||||
$cntxt = stream_context_create(array(
|
||||
'git' => array(
|
||||
'commitMsg' => 'Hello World',
|
||||
'author' => 'Luke Skywalker <skywalker@deathstar.com>'
|
||||
)
|
||||
));
|
||||
unlink($path, $cntxt);
|
||||
|
||||
$c = $this->getRepository();
|
||||
$commit = $c->showCommit($c->getCurrentCommit());
|
||||
$this->assertContains('Hello World', $commit);
|
||||
$this->assertContains('Luke Skywalker <skywalker@deathstar.com>', $commit);
|
||||
}
|
||||
|
||||
public function testRenameFile()
|
||||
{
|
||||
$pathFrom = sprintf('git://%s/file_0.txt', TESTS_REPO_PATH_1);
|
||||
$pathTo = sprintf('git://%s/test.txt', TESTS_REPO_PATH_1);
|
||||
rename($pathFrom, $pathTo);
|
||||
|
||||
$this->assertFileNotExists(TESTS_REPO_PATH_1.'/file_0.txt');
|
||||
$this->assertFileExists(TESTS_REPO_PATH_1.'/test.txt');
|
||||
|
||||
$c = $this->getRepository();
|
||||
$commit = $c->showCommit($c->getCurrentCommit());
|
||||
$this->assertContains('--- a/file_0.txt', $commit);
|
||||
$this->assertContains('+++ b/test.txt', $commit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPUnit_Framework_Error_Warning
|
||||
*/
|
||||
public function testRenameFileNonHead()
|
||||
{
|
||||
$pathFrom = sprintf('git://%s/file_0.txt#HEAD^', TESTS_REPO_PATH_1);
|
||||
$pathTo = sprintf('git://%s/test.txt', TESTS_REPO_PATH_1);
|
||||
rename($pathFrom, $pathTo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPUnit_Framework_Error_Warning
|
||||
*/
|
||||
public function testRenameNonExistantFile()
|
||||
{
|
||||
$pathFrom = sprintf('git://%s/file_does_not_exist.txt', TESTS_REPO_PATH_1);
|
||||
$pathTo = sprintf('git://%s/test.txt', TESTS_REPO_PATH_1);
|
||||
rename($pathFrom, $pathTo);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPUnit_Framework_Error_Warning
|
||||
*/
|
||||
public function testRenameNonFile()
|
||||
{
|
||||
$c = $this->getRepository();
|
||||
$c->writeFile('directory/test.txt', 'Test');
|
||||
|
||||
$pathFrom = sprintf('git://%s/directory', TESTS_REPO_PATH_1);
|
||||
$pathTo = sprintf('git://%s/test.txt', TESTS_REPO_PATH_1);
|
||||
rename($pathFrom, $pathTo);
|
||||
}
|
||||
|
||||
public function testRenameFileWithContext()
|
||||
{
|
||||
$pathFrom = sprintf('git://%s/file_0.txt', TESTS_REPO_PATH_1);
|
||||
$pathTo = sprintf('git://%s/test.txt', TESTS_REPO_PATH_1);
|
||||
$cntxt = stream_context_create(array(
|
||||
'git' => array(
|
||||
'commitMsg' => 'Hello World',
|
||||
'author' => 'Luke Skywalker <skywalker@deathstar.com>'
|
||||
)
|
||||
));
|
||||
rename($pathFrom, $pathTo, $cntxt);
|
||||
|
||||
$c = $this->getRepository();
|
||||
$commit = $c->showCommit($c->getCurrentCommit());
|
||||
$this->assertContains('Hello World', $commit);
|
||||
$this->assertContains('Luke Skywalker <skywalker@deathstar.com>', $commit);
|
||||
}
|
||||
|
||||
public function testRmdirDirectory()
|
||||
{
|
||||
$c = $this->getRepository();
|
||||
$c->writeFile('directory/test.txt', 'Test');
|
||||
$this->assertFileExists(TESTS_REPO_PATH_1.'/directory');
|
||||
$this->assertFileExists(TESTS_REPO_PATH_1.'/directory/test.txt');
|
||||
|
||||
$path = sprintf('git://%s/directory', TESTS_REPO_PATH_1);
|
||||
rmdir($path);
|
||||
|
||||
$this->assertFileNotExists(TESTS_REPO_PATH_1.'/directory');
|
||||
|
||||
$c = $this->getRepository();
|
||||
$commit = $c->showCommit($c->getCurrentCommit());
|
||||
|
||||
$this->assertContains('--- a/directory/test.txt', $commit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPUnit_Framework_Error_Warning
|
||||
*/
|
||||
public function testRmdirDirectoryNonHead()
|
||||
{
|
||||
$c = $this->getRepository();
|
||||
$c->writeFile('directory/test.txt', 'Test');
|
||||
|
||||
$path = sprintf('git://%s/directory#HEAD^', TESTS_REPO_PATH_1);
|
||||
rmdir($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPUnit_Framework_Error_Warning
|
||||
*/
|
||||
public function testRmdirNonExistantDirectory()
|
||||
{
|
||||
$path = sprintf('git://%s/directory_does_not_exist', TESTS_REPO_PATH_1);
|
||||
rmdir($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPUnit_Framework_Error_Warning
|
||||
*/
|
||||
public function testRmdirNonDirectory()
|
||||
{
|
||||
$path = sprintf('git://%s/file_0.txt', TESTS_REPO_PATH_1);
|
||||
rmdir($path);
|
||||
}
|
||||
|
||||
public function testRmdirDirectoryWithContext()
|
||||
{
|
||||
$c = $this->getRepository();
|
||||
$c->writeFile('directory/test.txt', 'Test');
|
||||
$this->assertFileExists(TESTS_REPO_PATH_1.'/directory');
|
||||
$this->assertFileExists(TESTS_REPO_PATH_1.'/directory/test.txt');
|
||||
|
||||
$path = sprintf('git://%s/directory', TESTS_REPO_PATH_1);
|
||||
$cntxt = stream_context_create(array(
|
||||
'git' => array(
|
||||
'commitMsg' => 'Hello World',
|
||||
'author' => 'Luke Skywalker <skywalker@deathstar.com>'
|
||||
)
|
||||
));
|
||||
rmdir($path, $cntxt);
|
||||
|
||||
$c = $this->getRepository();
|
||||
$commit = $c->showCommit($c->getCurrentCommit());
|
||||
$this->assertContains('Hello World', $commit);
|
||||
$this->assertContains('Luke Skywalker <skywalker@deathstar.com>', $commit);
|
||||
}
|
||||
|
||||
public function testMkdirDirectory()
|
||||
{
|
||||
$path = sprintf('git://%s/directory', TESTS_REPO_PATH_1);
|
||||
mkdir($path);
|
||||
|
||||
$this->assertFileExists(TESTS_REPO_PATH_1.'/directory');
|
||||
$this->assertFileExists(TESTS_REPO_PATH_1.'/directory/.gitkeep');
|
||||
|
||||
$c = $this->getRepository();
|
||||
$commit = $c->showCommit($c->getCurrentCommit());
|
||||
$this->assertContains('b/directory/.gitkeep', $commit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPUnit_Framework_Error_Warning
|
||||
*/
|
||||
public function testMkdirDirectoryNonHead()
|
||||
{
|
||||
$path = sprintf('git://%s/directory#HEAD^', TESTS_REPO_PATH_1);
|
||||
mkdir($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPUnit_Framework_Error_Warning
|
||||
*/
|
||||
public function testMkdirExistantDirectory()
|
||||
{
|
||||
$c = $this->getRepository();
|
||||
$c->writeFile('directory/test.txt', 'Test');
|
||||
|
||||
$path = sprintf('git://%s/directory', TESTS_REPO_PATH_1);
|
||||
mkdir($path);
|
||||
}
|
||||
|
||||
public function testMkdirDirectoryRecursively()
|
||||
{
|
||||
$path = sprintf('git://%s/directory/directory', TESTS_REPO_PATH_1);
|
||||
mkdir($path, 0777, true);
|
||||
|
||||
$this->assertFileExists(TESTS_REPO_PATH_1.'/directory');
|
||||
$this->assertFileExists(TESTS_REPO_PATH_1.'/directory/directory');
|
||||
$this->assertFileExists(TESTS_REPO_PATH_1.'/directory/directory/.gitkeep');
|
||||
|
||||
$c = $this->getRepository();
|
||||
$commit = $c->showCommit($c->getCurrentCommit());
|
||||
$this->assertContains('b/directory/directory/.gitkeep', $commit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPUnit_Framework_Error_Warning
|
||||
*/
|
||||
public function testMkdirDirectoryRecursivelyFailsIfNotRequested()
|
||||
{
|
||||
$path = sprintf('git://%s/directory/directory', TESTS_REPO_PATH_1);
|
||||
mkdir($path, 0777, false);
|
||||
}
|
||||
|
||||
public function testMkdirDirectoryWithContext()
|
||||
{
|
||||
$path = sprintf('git://%s/directory', TESTS_REPO_PATH_1);
|
||||
$cntxt = stream_context_create(array(
|
||||
'git' => array(
|
||||
'commitMsg' => 'Hello World',
|
||||
'author' => 'Luke Skywalker <skywalker@deathstar.com>'
|
||||
)
|
||||
));
|
||||
mkdir($path, 0777, false, $cntxt);
|
||||
|
||||
$c = $this->getRepository();
|
||||
$commit = $c->showCommit($c->getCurrentCommit());
|
||||
$this->assertContains('Hello World', $commit);
|
||||
$this->assertContains('Luke Skywalker <skywalker@deathstar.com>', $commit);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,225 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2011 by TEQneers GmbH & Co. KG
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace TQ\Tests\Git\StreamWrapper;
|
||||
|
||||
use TQ\Git\Cli\Binary;
|
||||
use TQ\Git\Repository\Repository;
|
||||
use TQ\Git\StreamWrapper\StreamWrapper;
|
||||
use TQ\Tests\Helper;
|
||||
|
||||
class FileReadTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Sets up the fixture, for example, open a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
Helper::removeDirectory(TESTS_TMP_PATH);
|
||||
mkdir(TESTS_TMP_PATH, 0777, true);
|
||||
mkdir(TESTS_REPO_PATH_1, 0777, true);
|
||||
|
||||
exec(sprintf('cd %s && %s init',
|
||||
escapeshellarg(TESTS_REPO_PATH_1),
|
||||
GIT_BINARY
|
||||
));
|
||||
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$file = sprintf('file_%d.txt', $i);
|
||||
$path = TESTS_REPO_PATH_1.'/'.$file;
|
||||
file_put_contents($path, sprintf('File %d', $i));
|
||||
exec(sprintf('cd %s && %s add %s',
|
||||
escapeshellarg(TESTS_REPO_PATH_1),
|
||||
GIT_BINARY,
|
||||
escapeshellarg($file)
|
||||
));
|
||||
}
|
||||
|
||||
exec(sprintf('cd %s && %s commit --message=%s',
|
||||
escapeshellarg(TESTS_REPO_PATH_1),
|
||||
GIT_BINARY,
|
||||
escapeshellarg('Initial commit')
|
||||
));
|
||||
|
||||
clearstatcache();
|
||||
|
||||
StreamWrapper::register('git', new Binary(GIT_BINARY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, close a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
Helper::removeDirectory(TESTS_TMP_PATH);
|
||||
|
||||
StreamWrapper::unregister();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Repository
|
||||
*/
|
||||
protected function getRepository()
|
||||
{
|
||||
return Repository::open(TESTS_REPO_PATH_1, new Binary(GIT_BINARY));
|
||||
}
|
||||
|
||||
public function testGetContentsOfFile()
|
||||
{
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$file = sprintf('git://%s/file_%d.txt', TESTS_REPO_PATH_1, $i);
|
||||
$content = file_get_contents($file);
|
||||
$this->assertEquals(sprintf('File %d', $i), $content);
|
||||
}
|
||||
}
|
||||
|
||||
public function testReadFileByByte()
|
||||
{
|
||||
$filePath = sprintf('git://%s/file_0.txt', TESTS_REPO_PATH_1);
|
||||
$file = fopen($filePath, 'r');
|
||||
$expected = 'File 0';
|
||||
$expLength = strlen($expected);
|
||||
for ($i = 0; $i < $expLength; $i++) {
|
||||
$this->assertEquals($i, ftell($file));
|
||||
$buffer = fgetc($file);
|
||||
$this->assertEquals($expected[$i], $buffer);
|
||||
$this->assertEquals($i + 1, ftell($file));
|
||||
}
|
||||
fclose($file);
|
||||
}
|
||||
|
||||
public function testSeekInFile()
|
||||
{
|
||||
$filePath = sprintf('git://%s/file_0.txt', TESTS_REPO_PATH_1);
|
||||
$file = fopen($filePath, 'r');
|
||||
$expected = 'File 0';
|
||||
|
||||
fseek($file, -1, SEEK_END);
|
||||
$this->assertEquals('0', fgetc($file));
|
||||
$this->assertEquals(6, ftell($file));
|
||||
$this->assertTrue(feof($file));
|
||||
|
||||
fseek($file, 0, SEEK_SET);
|
||||
$this->assertEquals('F', fgetc($file));
|
||||
$this->assertEquals(1, ftell($file));
|
||||
|
||||
fseek($file, 3, SEEK_CUR);
|
||||
$this->assertEquals(' ', fgetc($file));
|
||||
$this->assertEquals(5, ftell($file));
|
||||
|
||||
fseek($file, -2, SEEK_CUR);
|
||||
$this->assertEquals('e', fgetc($file));
|
||||
$this->assertEquals(4, ftell($file));
|
||||
|
||||
fclose($file);
|
||||
}
|
||||
|
||||
public function testReadFileInReverse()
|
||||
{
|
||||
$filePath = sprintf('git://%s/file_0.txt', TESTS_REPO_PATH_1);
|
||||
$file = fopen($filePath, 'r');
|
||||
$expected = '0 eliF';
|
||||
$actual = '';
|
||||
|
||||
fseek($file, -1, SEEK_END);
|
||||
while (($pos = ftell($file)) > 0) {
|
||||
$actual .= fgetc($file);
|
||||
fseek($file, -2, SEEK_CUR);
|
||||
}
|
||||
$actual .= fgetc($file);
|
||||
|
||||
fclose($file);
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testGetContentsOfFileWithRef()
|
||||
{
|
||||
$c = $this->getRepository();
|
||||
|
||||
$file = sprintf('git://%s/test.txt', TESTS_REPO_PATH_1);
|
||||
|
||||
$commit1 = $c->writeFile('test.txt', 'Test 1');
|
||||
$this->assertEquals('Test 1', file_get_contents($file));
|
||||
$this->assertEquals('Test 1', file_get_contents($file.'#HEAD'));
|
||||
$this->assertEquals('Test 1', file_get_contents($file.'#'.$commit1));
|
||||
|
||||
$commit2 = $c->writeFile('test.txt', 'Test 2');
|
||||
$this->assertEquals('Test 2', file_get_contents($file));
|
||||
$this->assertEquals('Test 2', file_get_contents($file.'#HEAD'));
|
||||
$this->assertEquals('Test 2', file_get_contents($file.'#'.$commit2));
|
||||
$this->assertEquals('Test 1', file_get_contents($file.'#HEAD^'));
|
||||
$this->assertEquals('Test 1', file_get_contents($file.'#'.$commit1));
|
||||
|
||||
$commit3 = $c->writeFile('test.txt', 'Test 3');
|
||||
$this->assertEquals('Test 3', file_get_contents($file));
|
||||
$this->assertEquals('Test 3', file_get_contents($file.'#HEAD'));
|
||||
$this->assertEquals('Test 3', file_get_contents($file.'#'.$commit3));
|
||||
$this->assertEquals('Test 2', file_get_contents($file.'#HEAD^'));
|
||||
$this->assertEquals('Test 2', file_get_contents($file.'#'.$commit2));
|
||||
$this->assertEquals('Test 1', file_get_contents($file.'#HEAD^^'));
|
||||
$this->assertEquals('Test 1', file_get_contents($file.'#'.$commit1));
|
||||
}
|
||||
|
||||
public function testGetContentsOfDirectory()
|
||||
{
|
||||
$c = $this->getRepository();
|
||||
|
||||
$dir = sprintf('git://%s', TESTS_REPO_PATH_1);
|
||||
$this->assertEquals(Helper::normalizeNewLines("tree HEAD:
|
||||
|
||||
file_0.txt
|
||||
file_1.txt
|
||||
file_2.txt
|
||||
file_3.txt
|
||||
file_4.txt"), Helper::normalizeNewLines(file_get_contents($dir)));
|
||||
|
||||
$c->removeFile('file_0.txt');
|
||||
$c->renameFile('file_1.txt', 'file_x.txt');
|
||||
$this->assertEquals(Helper::normalizeNewLines("tree HEAD:
|
||||
|
||||
file_2.txt
|
||||
file_3.txt
|
||||
file_4.txt
|
||||
file_x.txt"), Helper::normalizeNewLines(file_get_contents($dir)));
|
||||
|
||||
$this->assertEquals(Helper::normalizeNewLines("tree HEAD^:
|
||||
|
||||
file_1.txt
|
||||
file_2.txt
|
||||
file_3.txt
|
||||
file_4.txt"), Helper::normalizeNewLines(file_get_contents($dir.'#HEAD^')));
|
||||
|
||||
$this->assertEquals(Helper::normalizeNewLines("tree HEAD^^:
|
||||
|
||||
file_0.txt
|
||||
file_1.txt
|
||||
file_2.txt
|
||||
file_3.txt
|
||||
file_4.txt"), Helper::normalizeNewLines(file_get_contents($dir.'#HEAD^^')));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,293 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2011 by TEQneers GmbH & Co. KG
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace TQ\Tests\Git\StreamWrapper;
|
||||
|
||||
use TQ\Git\Cli\Binary;
|
||||
use TQ\Git\Repository\Repository;
|
||||
use TQ\Git\StreamWrapper\StreamWrapper;
|
||||
use TQ\Tests\Helper;
|
||||
|
||||
class FileWriteTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Sets up the fixture, for example, open a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
Helper::removeDirectory(TESTS_TMP_PATH);
|
||||
mkdir(TESTS_TMP_PATH, 0777, true);
|
||||
mkdir(TESTS_REPO_PATH_1, 0777, true);
|
||||
|
||||
exec(sprintf('cd %s && %s init',
|
||||
escapeshellarg(TESTS_REPO_PATH_1),
|
||||
GIT_BINARY
|
||||
));
|
||||
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$file = sprintf('file_%d.txt', $i);
|
||||
$path = TESTS_REPO_PATH_1.'/'.$file;
|
||||
file_put_contents($path, sprintf('File %d', $i));
|
||||
exec(sprintf('cd %s && %s add %s',
|
||||
escapeshellarg(TESTS_REPO_PATH_1),
|
||||
GIT_BINARY,
|
||||
escapeshellarg($file)
|
||||
));
|
||||
}
|
||||
|
||||
exec(sprintf('cd %s && %s commit --message=%s',
|
||||
escapeshellarg(TESTS_REPO_PATH_1),
|
||||
GIT_BINARY,
|
||||
escapeshellarg('Initial commit')
|
||||
));
|
||||
|
||||
clearstatcache();
|
||||
|
||||
StreamWrapper::register('git', new Binary(GIT_BINARY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, close a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
Helper::removeDirectory(TESTS_TMP_PATH);
|
||||
|
||||
StreamWrapper::unregister();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Repository
|
||||
*/
|
||||
protected function getRepository()
|
||||
{
|
||||
return Repository::open(TESTS_REPO_PATH_1, new Binary(GIT_BINARY));
|
||||
}
|
||||
|
||||
public function testWriteNewFile()
|
||||
{
|
||||
$filePath = sprintf('git://%s/test.txt', TESTS_REPO_PATH_1);
|
||||
$file = fopen($filePath, 'w');
|
||||
fwrite($file, 'Test');
|
||||
fclose($file);
|
||||
|
||||
$this->assertFileExists(TESTS_REPO_PATH_1.'/test.txt');
|
||||
$this->assertEquals('Test', file_get_contents(TESTS_REPO_PATH_1.'/test.txt'));
|
||||
|
||||
$c = $this->getRepository();
|
||||
$commit = $c->showCommit($c->getCurrentCommit());
|
||||
$this->assertRegExp('~^\+\+\+ b/test.txt$~m', $commit);
|
||||
$this->assertRegExp('~^\+Test$~m', $commit);
|
||||
}
|
||||
|
||||
public function testWriteNewFileWithContext()
|
||||
{
|
||||
$filePath = sprintf('git://%s/test.txt', TESTS_REPO_PATH_1);
|
||||
$cntxt = stream_context_create(array(
|
||||
'git' => array(
|
||||
'commitMsg' => 'Hello World',
|
||||
'author' => 'Luke Skywalker <skywalker@deathstar.com>'
|
||||
)
|
||||
));
|
||||
$file = fopen($filePath, 'w', false, $cntxt);
|
||||
fwrite($file, 'Test');
|
||||
fclose($file);
|
||||
|
||||
$this->assertFileExists(TESTS_REPO_PATH_1.'/test.txt');
|
||||
$this->assertEquals('Test', file_get_contents(TESTS_REPO_PATH_1.'/test.txt'));
|
||||
|
||||
$c = $this->getRepository();
|
||||
$commit = $c->showCommit($c->getCurrentCommit());
|
||||
$this->assertRegExp('~^\+\+\+ b/test.txt$~m', $commit);
|
||||
$this->assertRegExp('~^\+Test$~m', $commit);
|
||||
$this->assertContains('Hello World', $commit);
|
||||
$this->assertContains('Luke Skywalker <skywalker@deathstar.com>', $commit);
|
||||
}
|
||||
|
||||
public function testWriteExistingFile()
|
||||
{
|
||||
$filePath = sprintf('git://%s/file_0.txt', TESTS_REPO_PATH_1);
|
||||
$file = fopen($filePath, 'w');
|
||||
fwrite($file, 'Test');
|
||||
fclose($file);
|
||||
|
||||
$this->assertFileExists(TESTS_REPO_PATH_1.'/file_0.txt');
|
||||
$this->assertEquals('Test', file_get_contents(TESTS_REPO_PATH_1.'/file_0.txt'));
|
||||
|
||||
$c = $this->getRepository();
|
||||
$commit = $c->showCommit($c->getCurrentCommit());
|
||||
$this->assertRegExp('~^--- a/file_0.txt$~m', $commit);
|
||||
$this->assertRegExp('~^\+\+\+ b/file_0.txt$~m', $commit);
|
||||
$this->assertRegExp('~^-File 0$~m', $commit);
|
||||
$this->assertRegExp('~^\+Test$~m', $commit);
|
||||
}
|
||||
|
||||
public function testAppendExistingFile()
|
||||
{
|
||||
$filePath = sprintf('git://%s/file_0.txt', TESTS_REPO_PATH_1);
|
||||
$file = fopen($filePath, 'a');
|
||||
fwrite($file, 'Test');
|
||||
fclose($file);
|
||||
|
||||
$this->assertFileExists(TESTS_REPO_PATH_1.'/file_0.txt');
|
||||
$this->assertEquals('File 0Test', file_get_contents(TESTS_REPO_PATH_1.'/file_0.txt'));
|
||||
|
||||
$c = $this->getRepository();
|
||||
$commit = $c->showCommit($c->getCurrentCommit());
|
||||
$this->assertRegExp('~^--- a/file_0.txt$~m', $commit);
|
||||
$this->assertRegExp('~^\+\+\+ b/file_0.txt$~m', $commit);
|
||||
$this->assertRegExp('~^-File 0$~m', $commit);
|
||||
$this->assertRegExp('~^\+File 0Test$~m', $commit);
|
||||
}
|
||||
|
||||
public function testWriteNewFileWithX()
|
||||
{
|
||||
$filePath = sprintf('git://%s/test.txt', TESTS_REPO_PATH_1);
|
||||
$file = fopen($filePath, 'x');
|
||||
fwrite($file, 'Test');
|
||||
fclose($file);
|
||||
|
||||
$this->assertFileExists(TESTS_REPO_PATH_1.'/test.txt');
|
||||
$this->assertEquals('Test', file_get_contents(TESTS_REPO_PATH_1.'/test.txt'));
|
||||
|
||||
$c = $this->getRepository();
|
||||
$commit = $c->showCommit($c->getCurrentCommit());
|
||||
$this->assertRegExp('~^\+\+\+ b/test.txt$~m', $commit);
|
||||
$this->assertRegExp('~^\+Test$~m', $commit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException PHPUnit_Framework_Error_Warning
|
||||
*/
|
||||
public function testWriteExistingFileWithXFails()
|
||||
{
|
||||
$filePath = sprintf('git://%s/file_0.txt', TESTS_REPO_PATH_1);
|
||||
$file = fopen($filePath, 'x');
|
||||
fwrite($file, 'Test');
|
||||
}
|
||||
|
||||
public function testWriteNewFileWithC()
|
||||
{
|
||||
$filePath = sprintf('git://%s/test.txt', TESTS_REPO_PATH_1);
|
||||
$file = fopen($filePath, 'c');
|
||||
fwrite($file, 'Test');
|
||||
fclose($file);
|
||||
|
||||
$this->assertFileExists(TESTS_REPO_PATH_1.'/test.txt');
|
||||
$this->assertEquals('Test', file_get_contents(TESTS_REPO_PATH_1.'/test.txt'));
|
||||
|
||||
$c = $this->getRepository();
|
||||
$commit = $c->showCommit($c->getCurrentCommit());
|
||||
$this->assertRegExp('~^\+\+\+ b/test.txt$~m', $commit);
|
||||
$this->assertRegExp('~^\+Test$~m', $commit);
|
||||
}
|
||||
|
||||
public function testWriteExistingFileWithC()
|
||||
{
|
||||
$filePath = sprintf('git://%s/file_0.txt', TESTS_REPO_PATH_1);
|
||||
$file = fopen($filePath, 'c');
|
||||
fseek($file, 0, SEEK_END);
|
||||
fwrite($file, 'Test');
|
||||
fclose($file);
|
||||
|
||||
$this->assertFileExists(TESTS_REPO_PATH_1.'/file_0.txt');
|
||||
$this->assertEquals('File 0Test', file_get_contents(TESTS_REPO_PATH_1.'/file_0.txt'));
|
||||
|
||||
$c = $this->getRepository();
|
||||
$commit = $c->showCommit($c->getCurrentCommit());
|
||||
$this->assertRegExp('~^--- a/file_0.txt$~m', $commit);
|
||||
$this->assertRegExp('~^\+\+\+ b/file_0.txt$~m', $commit);
|
||||
$this->assertRegExp('~^-File 0$~m', $commit);
|
||||
$this->assertRegExp('~^\+File 0Test$~m', $commit);
|
||||
}
|
||||
|
||||
public function testWriteAndReadNewFile()
|
||||
{
|
||||
$filePath = sprintf('git://%s/test.txt', TESTS_REPO_PATH_1);
|
||||
$file = fopen($filePath, 'w+');
|
||||
fwrite($file, 'Test');
|
||||
fseek($file, -2, SEEK_END);
|
||||
$this->assertEquals('st', fread($file, 2));
|
||||
fseek($file, -2, SEEK_END);
|
||||
fwrite($file, 'xt');
|
||||
fclose($file);
|
||||
|
||||
$this->assertFileExists(TESTS_REPO_PATH_1.'/test.txt');
|
||||
$this->assertEquals('Text', file_get_contents(TESTS_REPO_PATH_1.'/test.txt'));
|
||||
|
||||
$c = $this->getRepository();
|
||||
$commit = $c->showCommit($c->getCurrentCommit());
|
||||
$this->assertRegExp('~^\+\+\+ b/test.txt$~m', $commit);
|
||||
$this->assertRegExp('~^\+Text$~m', $commit);
|
||||
}
|
||||
|
||||
public function testWriteNewFileWithFilePutContents()
|
||||
{
|
||||
$filePath = sprintf('git://%s/test.txt', TESTS_REPO_PATH_1);
|
||||
file_put_contents($filePath, 'Test');
|
||||
|
||||
$this->assertFileExists(TESTS_REPO_PATH_1.'/test.txt');
|
||||
$this->assertEquals('Test', file_get_contents(TESTS_REPO_PATH_1.'/test.txt'));
|
||||
|
||||
$c = $this->getRepository();
|
||||
$commit = $c->showCommit($c->getCurrentCommit());
|
||||
$this->assertRegExp('~^\+\+\+ b/test.txt$~m', $commit);
|
||||
$this->assertRegExp('~^\+Test$~m', $commit);
|
||||
}
|
||||
|
||||
public function testWriteExistingFileWithFilePutContents()
|
||||
{
|
||||
$filePath = sprintf('git://%s/file_0.txt', TESTS_REPO_PATH_1);
|
||||
file_put_contents($filePath, 'Test');
|
||||
|
||||
$this->assertFileExists(TESTS_REPO_PATH_1.'/file_0.txt');
|
||||
$this->assertEquals('Test', file_get_contents(TESTS_REPO_PATH_1.'/file_0.txt'));
|
||||
|
||||
$c = $this->getRepository();
|
||||
$commit = $c->showCommit($c->getCurrentCommit());
|
||||
$this->assertRegExp('~^--- a/file_0.txt$~m', $commit);
|
||||
$this->assertRegExp('~^\+\+\+ b/file_0.txt$~m', $commit);
|
||||
$this->assertRegExp('~^-File 0$~m', $commit);
|
||||
$this->assertRegExp('~^\+Test$~m', $commit);
|
||||
}
|
||||
|
||||
public function testAppendExistingFileWithFilePutContents()
|
||||
{
|
||||
$filePath = sprintf('git://%s/file_0.txt', TESTS_REPO_PATH_1);
|
||||
file_put_contents($filePath, 'Test', FILE_APPEND);
|
||||
|
||||
$this->assertFileExists(TESTS_REPO_PATH_1.'/file_0.txt');
|
||||
$this->assertEquals('File 0Test', file_get_contents(TESTS_REPO_PATH_1.'/file_0.txt'));
|
||||
|
||||
$c = $this->getRepository();
|
||||
$commit = $c->showCommit($c->getCurrentCommit());
|
||||
$this->assertRegExp('~^--- a/file_0.txt$~m', $commit);
|
||||
$this->assertRegExp('~^\+\+\+ b/file_0.txt$~m', $commit);
|
||||
$this->assertRegExp('~^-File 0$~m', $commit);
|
||||
$this->assertRegExp('~^\+File 0Test$~m', $commit);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2011 by TEQneers GmbH & Co. KG
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace TQ\Tests\Git\StreamWrapper;
|
||||
|
||||
use TQ\Git\Cli\Binary;
|
||||
use TQ\Git\Repository\Repository;
|
||||
use TQ\Git\StreamWrapper\StreamWrapper;
|
||||
use TQ\Tests\Helper;
|
||||
|
||||
class FileStatTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Sets up the fixture, for example, open a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
Helper::removeDirectory(TESTS_TMP_PATH);
|
||||
mkdir(TESTS_TMP_PATH, 0777, true);
|
||||
mkdir(TESTS_REPO_PATH_1, 0777, true);
|
||||
|
||||
exec(sprintf('cd %s && %s init',
|
||||
escapeshellarg(TESTS_REPO_PATH_1),
|
||||
GIT_BINARY
|
||||
));
|
||||
|
||||
$path = TESTS_REPO_PATH_1.'/test.txt';
|
||||
file_put_contents($path, 'File 1');
|
||||
exec(sprintf('cd %s && %s add %s',
|
||||
escapeshellarg(TESTS_REPO_PATH_1),
|
||||
GIT_BINARY,
|
||||
escapeshellarg($path)
|
||||
));
|
||||
|
||||
exec(sprintf('cd %s && %s commit --message=%s',
|
||||
escapeshellarg(TESTS_REPO_PATH_1),
|
||||
GIT_BINARY,
|
||||
escapeshellarg('Commit 1')
|
||||
));
|
||||
|
||||
$path = TESTS_REPO_PATH_1.'/directory';
|
||||
mkdir($path, 0777);
|
||||
file_put_contents($path.'/test.txt', 'Directory File 1');
|
||||
exec(sprintf('cd %s && %s add %s',
|
||||
escapeshellarg(TESTS_REPO_PATH_1),
|
||||
GIT_BINARY,
|
||||
escapeshellarg($path)
|
||||
));
|
||||
|
||||
exec(sprintf('cd %s && %s commit --message=%s',
|
||||
escapeshellarg(TESTS_REPO_PATH_1),
|
||||
GIT_BINARY,
|
||||
escapeshellarg('Commit 2')
|
||||
));
|
||||
|
||||
$path = TESTS_REPO_PATH_1.'/test.txt';
|
||||
file_put_contents($path, 'File 1 New');
|
||||
exec(sprintf('cd %s && %s add %s',
|
||||
escapeshellarg(TESTS_REPO_PATH_1),
|
||||
GIT_BINARY,
|
||||
escapeshellarg($path)
|
||||
));
|
||||
|
||||
exec(sprintf('cd %s && %s commit --message=%s',
|
||||
escapeshellarg(TESTS_REPO_PATH_1),
|
||||
GIT_BINARY,
|
||||
escapeshellarg('Commit 3')
|
||||
));
|
||||
|
||||
clearstatcache();
|
||||
|
||||
StreamWrapper::register('git', new Binary(GIT_BINARY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, close a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
Helper::removeDirectory(TESTS_TMP_PATH);
|
||||
|
||||
StreamWrapper::unregister();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Repository
|
||||
*/
|
||||
protected function getRepository()
|
||||
{
|
||||
return Repository::open(TESTS_REPO_PATH_1, new Binary(GIT_BINARY));
|
||||
}
|
||||
|
||||
public function testUrlStatFileWorkingDirectory()
|
||||
{
|
||||
$filePath = sprintf('git://%s/test.txt', TESTS_REPO_PATH_1);
|
||||
$stat = stat($filePath);
|
||||
$this->assertEquals(26, count($stat));
|
||||
$this->assertEquals(0100000, $stat['mode'] & 0100000);
|
||||
$this->assertEquals(10, $stat['size']);
|
||||
|
||||
}
|
||||
|
||||
public function testUrlStatDirWorkingDirectory()
|
||||
{
|
||||
$dirPath = sprintf('git://%s/directory', TESTS_REPO_PATH_1);
|
||||
$stat = stat($dirPath);
|
||||
$this->assertEquals(26, count($stat));
|
||||
$this->assertEquals(0040000, $stat['mode'] & 0040000);
|
||||
}
|
||||
|
||||
public function testUrlStatFileHistory()
|
||||
{
|
||||
$filePath = sprintf('git://%s/test.txt#HEAD^', TESTS_REPO_PATH_1);
|
||||
$stat = stat($filePath);
|
||||
$this->assertEquals(26, count($stat));
|
||||
$this->assertEquals(0100000, $stat['mode'] & 0100000);
|
||||
$this->assertEquals(6, $stat['size']);
|
||||
|
||||
}
|
||||
|
||||
public function testUrlStatDirHistory()
|
||||
{
|
||||
$dirPath = sprintf('git://%s/directory#HEAD^', TESTS_REPO_PATH_1);
|
||||
$stat = stat($dirPath);
|
||||
$this->assertEquals(26, count($stat));
|
||||
$this->assertEquals(0040000, $stat['mode'] & 0040000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2011 by TEQneers GmbH & Co. KG
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace TQ\Tests\Git\StreamWrapper;
|
||||
|
||||
use TQ\Git\Cli\Binary;
|
||||
use TQ\Git\Repository\Repository;
|
||||
use TQ\Git\StreamWrapper\StreamWrapper;
|
||||
use TQ\Tests\Helper;
|
||||
|
||||
class StatusReadTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Sets up the fixture, for example, open a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
Helper::removeDirectory(TESTS_TMP_PATH);
|
||||
mkdir(TESTS_TMP_PATH, 0777, true);
|
||||
mkdir(TESTS_REPO_PATH_1, 0777, true);
|
||||
|
||||
exec(sprintf('cd %s && %s init',
|
||||
escapeshellarg(TESTS_REPO_PATH_1),
|
||||
GIT_BINARY
|
||||
));
|
||||
|
||||
clearstatcache();
|
||||
|
||||
StreamWrapper::register('git', new Binary(GIT_BINARY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, close a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
Helper::removeDirectory(TESTS_TMP_PATH);
|
||||
|
||||
StreamWrapper::unregister();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Repository
|
||||
*/
|
||||
protected function getRepository()
|
||||
{
|
||||
return Repository::open(TESTS_REPO_PATH_1, new Binary(GIT_BINARY));
|
||||
}
|
||||
|
||||
public function testReadCommit() {
|
||||
|
||||
$c = $this->getRepository();
|
||||
$commits = array();
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$commits[] = $c->writeFile(sprintf('test_%d.txt', $i), sprintf('This is file %d', $i));
|
||||
}
|
||||
|
||||
foreach ($commits as $c => $commitHash) {
|
||||
$commitUrl = sprintf('git://%s?commit&ref=%s', TESTS_REPO_PATH_1, $commitHash);
|
||||
$content = file_get_contents($commitUrl);
|
||||
|
||||
$this->assertStringStartsWith('commit '.$commitHash, $content);
|
||||
$this->assertContains(sprintf('+++ b/test_%d.txt', $c), $content);
|
||||
$this->assertContains(sprintf('+This is file %d', $c), $content);
|
||||
}
|
||||
}
|
||||
|
||||
public function testReadLog() {
|
||||
|
||||
$c = $this->getRepository();
|
||||
$commits = array();
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$commits[] = $c->writeFile(sprintf('test_%d.txt', $i), sprintf('This is file %d', $i));
|
||||
}
|
||||
|
||||
$logUrl = sprintf('git://%s?log', TESTS_REPO_PATH_1);
|
||||
$log = file_get_contents($logUrl);
|
||||
foreach ($commits as $c => $commitHash) {
|
||||
$this->assertContains('commit '.$commitHash, $log);
|
||||
}
|
||||
|
||||
$logUrl = sprintf('git://%s?log&limit=%d', TESTS_REPO_PATH_1, 1);
|
||||
$log = file_get_contents($logUrl);
|
||||
foreach ($commits as $c => $commitHash) {
|
||||
if ($c == count($commits) - 1) {
|
||||
$this->assertContains('commit '.$commitHash, $log);
|
||||
} else {
|
||||
$this->assertNotContains('commit '.$commitHash, $log);
|
||||
}
|
||||
}
|
||||
|
||||
$logUrl = sprintf('git://%s?log&limit=%d', TESTS_REPO_PATH_1, 2);
|
||||
$log = file_get_contents($logUrl);
|
||||
foreach ($commits as $c => $commitHash) {
|
||||
if ($c >= count($commits) - 2) {
|
||||
$this->assertContains('commit '.$commitHash, $log);
|
||||
} else {
|
||||
$this->assertNotContains('commit '.$commitHash, $log);
|
||||
}
|
||||
}
|
||||
|
||||
$logUrl = sprintf('git://%s?log&limit=%d&skip=%d', TESTS_REPO_PATH_1, 2, 1);
|
||||
$log = file_get_contents($logUrl);
|
||||
foreach ($commits as $c => $commitHash) {
|
||||
if (($c >= count($commits) - 3) && ($c < count($commits) - 1)) {
|
||||
$this->assertContains('commit '.$commitHash, $log);
|
||||
} else {
|
||||
$this->assertNotContains('commit '.$commitHash, $log);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
73
wp-content/plugins/aceide/vendor/teqneers/php-stream-wrapper-for-git/tests/TQ/Tests/Helper.php
vendored
Normal file
73
wp-content/plugins/aceide/vendor/teqneers/php-stream-wrapper-for-git/tests/TQ/Tests/Helper.php
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2011 by TEQneers GmbH & Co. KG
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace TQ\Tests;
|
||||
|
||||
class Helper
|
||||
{
|
||||
public static function removeDirectory($path)
|
||||
{
|
||||
clearstatcache();
|
||||
if (!file_exists($path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_dir($path)) {
|
||||
throw new \InvalidArgumentException(sprintf('"%s" is not a directory', $path));
|
||||
}
|
||||
|
||||
$dirIt = new \RecursiveDirectoryIterator($path,
|
||||
\RecursiveDirectoryIterator::SKIP_DOTS
|
||||
| \RecursiveDirectoryIterator::KEY_AS_PATHNAME
|
||||
| \RecursiveDirectoryIterator::CURRENT_AS_FILEINFO
|
||||
);
|
||||
$it = new \RecursiveIteratorIterator($dirIt,
|
||||
\RecursiveIteratorIterator::CHILD_FIRST
|
||||
);
|
||||
|
||||
foreach ($it as $p => $f) {
|
||||
if ($f->isDir()) {
|
||||
rmdir($p);
|
||||
} else if ($f->isFile()) {
|
||||
chmod($p, 0777);
|
||||
unlink($p);
|
||||
}
|
||||
}
|
||||
rmdir($path);
|
||||
}
|
||||
|
||||
public static function normalizeDirectorySeparator($path)
|
||||
{
|
||||
return str_replace(DIRECTORY_SEPARATOR, '/', $path);
|
||||
}
|
||||
|
||||
public static function normalizeNewLines($string)
|
||||
{
|
||||
return str_replace("\r\n", "\n", $string);
|
||||
}
|
||||
|
||||
public static function normalizeEscapeShellArg($command)
|
||||
{
|
||||
return str_replace("'", '"', $command);
|
||||
}
|
||||
}
|
||||
45
wp-content/plugins/aceide/vendor/teqneers/php-stream-wrapper-for-git/tests/bootstrap.php
vendored
Normal file
45
wp-content/plugins/aceide/vendor/teqneers/php-stream-wrapper-for-git/tests/bootstrap.php
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2011 by TEQneers GmbH & Co. KG
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
require_once __DIR__.'/TQ/Tests/Helper.php';
|
||||
|
||||
if (file_exists($file = __DIR__.'/../autoload.php')) {
|
||||
require_once $file;
|
||||
} elseif (file_exists($file = __DIR__.'/../autoload.php.dist')) {
|
||||
require_once $file;
|
||||
}
|
||||
|
||||
use TQ\Tests\Helper;
|
||||
|
||||
define('PROJECT_PATH', Helper::normalizeDirectorySeparator(dirname(__DIR__)));
|
||||
define('SOURCE_PATH', PROJECT_PATH.'/src');
|
||||
define('TESTS_PATH', Helper::normalizeDirectorySeparator(__DIR__));
|
||||
|
||||
if (defined('TEST_REPO_PATH') && is_string(TEST_REPO_PATH)) {
|
||||
define('TESTS_TMP_PATH', Helper::normalizeDirectorySeparator(TEST_REPO_PATH).'/_tq_git_streamwrapper_tests');
|
||||
} else {
|
||||
define('TESTS_TMP_PATH', Helper::normalizeDirectorySeparator(sys_get_temp_dir()).'/_tq_git_streamwrapper_tests');
|
||||
}
|
||||
define('TESTS_REPO_PATH_1', TESTS_TMP_PATH.'/repo1');
|
||||
define('TESTS_REPO_PATH_2', TESTS_TMP_PATH.'/repo2');
|
||||
define('TESTS_REPO_PATH_3', TESTS_TMP_PATH.'/repo3');
|
||||
Reference in New Issue
Block a user