Skip to content

Commit 09d51b5

Browse files
author
Alexandre Salomé
committed
Merge pull request #38 from hason/tests
Fixed typos and tests on Windows
2 parents de59c78 + 4b8e18d commit 09d51b5

File tree

7 files changed

+61
-14
lines changed

7 files changed

+61
-14
lines changed

phpunit.xml.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
processIsolation = "false"
1111
stopOnFailure = "false"
1212
syntaxCheck = "false"
13-
bootstrap = "vendor/autoload.php" >
13+
bootstrap = "tests/bootstrap.php" >
1414

1515
<testsuites>
1616
<testsuite name="Test Suite">

src/Gitonomy/Git/Admin.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static function init($path, $bare = true, array $options = array())
3838
$command = isset($options['command']) ? $options['command'] : 'git';
3939

4040
// command-line
41-
$builder = ProcessBuilder::create(array('git', 'init', '-q'));
41+
$builder = ProcessBuilder::create(array($command, 'init', '-q'));
4242
if ($bare) {
4343
$builder->add('--bare');
4444
}
@@ -112,11 +112,11 @@ private static function cloneRepository($path, $url, array $args = array(), arra
112112
$builder->add($path);
113113

114114
$builder->inheritEnvironmentVariables(false);
115+
$process = $builder->getProcess();
115116
if (isset($options['environment_variables'])) {
116-
$builder->setEnv($options['environment_variables']);
117+
$process->setEnv($options['environment_variables']);
117118
}
118119

119-
$process = $builder->getProcess();
120120
$process->run();
121121

122122
if (!$process->isSuccessFul()) {

tests/Gitonomy/Git/Tests/AbstractTest.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
abstract class AbstractTest extends \PHPUnit_Framework_TestCase
1919
{
20-
const REPOSITORY_URL = 'git://github.com/gitonomy/foobar.git';
20+
const REPOSITORY_URL = 'http://github.com/gitonomy/foobar.git';
2121

2222
const LONGFILE_COMMIT = '4f17752acc9b7c54ba679291bf24cb7d354f0f4f';
2323
const BEFORE_LONGFILE_COMMIT = 'e0ec50e2af75fa35485513f60b2e658e245227e9';
@@ -64,7 +64,7 @@ public static function provideFoobar()
6464
public static function createFoobarRepository($bare = true)
6565
{
6666
if (null === self::$localRepository) {
67-
self::$localRepository = Admin::cloneTo(self::createTempDir(), self::REPOSITORY_URL, self::getOptions());
67+
self::$localRepository = Admin::cloneTo(self::createTempDir(), self::REPOSITORY_URL, $bare, self::getOptions());
6868
}
6969

7070
$repository = self::$localRepository->cloneTo(self::createTempDir(), $bare, self::getOptions());
@@ -119,12 +119,14 @@ public static function deleteDir($dir)
119119
rmdir($dir);
120120
}
121121

122-
private static function getOptions()
122+
protected static function getOptions()
123123
{
124124
$command = isset($_SERVER['GIT_COMMAND']) ? $_SERVER['GIT_COMMAND'] : 'git';
125+
$envs = isset($_SERVER['GIT_ENVS']) ? (array) $_SERVER['GIT_ENVS'] : array();
125126

126127
return array(
127-
'command' => $command
128+
'command' => $command,
129+
'environment_variables' => $envs,
128130
);
129131
}
130132
}

tests/Gitonomy/Git/Tests/AdminTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function tearDown()
3131

3232
public function testBare()
3333
{
34-
$repository = Admin::init($this->tmpDir);
34+
$repository = Admin::init($this->tmpDir, true, self::getOptions());
3535

3636
$objectDir = $this->tmpDir.'/objects';
3737

@@ -44,7 +44,7 @@ public function testBare()
4444

4545
public function testNotBare()
4646
{
47-
$repository = Admin::init($this->tmpDir, false);
47+
$repository = Admin::init($this->tmpDir, false, self::getOptions());
4848

4949
$objectDir = $this->tmpDir.'/.git/objects';
5050

@@ -61,7 +61,7 @@ public function testNotBare()
6161
public function testClone($repository)
6262
{
6363
$newDir = self::createTempDir();
64-
$new = $repository->cloneTo($newDir, $repository->isBare());
64+
$new = $repository->cloneTo($newDir, $repository->isBare(), self::getOptions());
6565
self::registerDeletion($new);
6666

6767
$newRefs = array_keys($new->getReferences()->getAll());
@@ -84,7 +84,7 @@ public function testClone($repository)
8484
public function testMirror($repository)
8585
{
8686
$newDir = self::createTempDir();
87-
$new = Admin::mirrorTo($newDir, $repository->getGitDir());
87+
$new = Admin::mirrorTo($newDir, $repository->getGitDir(), self::getOptions());
8888
self::registerDeletion($new);
8989

9090
$newRefs = array_keys($new->getReferences()->getAll());
@@ -108,6 +108,6 @@ public function testExistingFile()
108108
$file = $this->tmpDir.'/test';
109109
touch($file);
110110

111-
Admin::init($file);
111+
Admin::init($file, true, self::getOptions());
112112
}
113113
}

tests/Gitonomy/Git/Tests/HooksTest.php

+32
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@
1414

1515
class HooksTest extends AbstractTest
1616
{
17+
private static $symlinkOnWindows = null;
18+
19+
public static function setUpBeforeClass()
20+
{
21+
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
22+
self::$symlinkOnWindows = true;
23+
$originDir = tempnam(sys_get_temp_dir(), 'sl');
24+
$targetDir = tempnam(sys_get_temp_dir(), 'sl');
25+
if (true !== @symlink($originDir, $targetDir)) {
26+
$report = error_get_last();
27+
if (is_array($report) && false !== strpos($report['message'], 'error code(1314)')) {
28+
self::$symlinkOnWindows = false;
29+
}
30+
}
31+
}
32+
}
33+
1734
public function hookPath($repository, $hook)
1835
{
1936
return $repository->getGitDir().'/hooks/'.$hook;
@@ -77,6 +94,8 @@ public function testGet($repository)
7794
*/
7895
public function testSymlink($repository)
7996
{
97+
$this->markAsSkippedIfSymlinkIsMissing();
98+
8099
$file = $this->touchHook($repository, 'bar', 'barbarbar');
81100
$repository->getHooks()->setSymlink('foo', $file);
82101

@@ -90,6 +109,8 @@ public function testSymlink($repository)
90109
*/
91110
public function testSymlink_WithExisting_ThrowsLogicException($repository)
92111
{
112+
$this->markAsSkippedIfSymlinkIsMissing();
113+
93114
$file = $this->hookPath($repository, 'target-symlink');
94115
$fooFile = $this->hookPath($repository, 'foo');
95116

@@ -144,4 +165,15 @@ public function testRemove_NotExisting_ThrowsLogicException($repository)
144165
{
145166
$repository->getHooks()->remove('foo');
146167
}
168+
169+
private function markAsSkippedIfSymlinkIsMissing()
170+
{
171+
if (!function_exists('symlink')) {
172+
$this->markTestSkipped('symlink is not supported');
173+
}
174+
175+
if (defined('PHP_WINDOWS_VERSION_MAJOR') && false === self::$symlinkOnWindows) {
176+
$this->markTestSkipped('symlink requires "Create symbolic links" privilege on windows');
177+
}
178+
}
147179
}

tests/Gitonomy/Git/Tests/WorkingCopyTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class WorkingCopyTest extends AbstractTest
2323
public function testNoWorkingCopyInBare()
2424
{
2525
$path = self::createTempDir();
26-
$repo = Admin::init($path);
26+
$repo = Admin::init($path, true, self::getOptions());
2727

2828
$repo->getWorkingCopy();
2929
}

tests/bootstrap.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
require __DIR__.'/../vendor/autoload.php';
3+
4+
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
5+
$server = array_change_key_case($_SERVER);
6+
$_SERVER['GIT_ENVS'] = array();
7+
foreach (array('PATH', 'SYSTEMROOT') as $key) {
8+
if (isset($server[strtolower($key)])) {
9+
$_SERVER['GIT_ENVS'][strtoupper($key)] = $server[strtolower($key)];
10+
}
11+
}
12+
unset($server);
13+
}

0 commit comments

Comments
 (0)