Merge pull request #162 from sstok/windows_tests_fix

Fixed tests on windows
This commit is contained in:
Klaus Silveira
2012-09-09 21:07:30 -07:00
5 changed files with 169 additions and 101 deletions

View File

@@ -1,6 +1,6 @@
<?php
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' && !defined('WINDOWS_BUILD')) {
define('WINDOWS_BUILD', 1);
}
@@ -17,4 +17,4 @@ $app->mount('', new GitList\Controller\BlobController());
$app->mount('', new GitList\Controller\CommitController());
$app->mount('', new GitList\Controller\TreeController());
return $app;
return $app;

View File

@@ -90,7 +90,9 @@ class Client
$isRepository = file_exists($file->getPathname() . '/.git/HEAD');
if ($isRepository || $isBare) {
if (in_array($file->getPathname(), $this->getHidden())) {
$pathName = str_replace('\\', '/', $file->getPathname());
if (in_array($pathName, $this->getHidden())) {
continue;
}
@@ -106,7 +108,7 @@ class Client
$description = 'There is no repository description file. Please, create one to remove this message.';
}
$repositories[] = array('name' => $file->getFilename(), 'path' => $file->getPathname(), 'description' => $description);
$repositories[] = array('name' => $file->getFilename(), 'path' => $pathName, 'description' => $description);
continue;
}
}

View File

@@ -8,22 +8,38 @@ use Symfony\Component\Filesystem\Filesystem;
class ClientTest extends PHPUnit_Framework_TestCase
{
const PATH = '/tmp/gitlist';
protected static $tmpdir;
protected $client;
public static function setUpBeforeClass()
{
mkdir(ClientTest::PATH);
if (getenv('TMP')) {
self::$tmpdir = getenv('TMP');
} elseif (getenv('TMPDIR')) {
self::$tmpdir = getenv('TMPDIR');
} else {
self::$tmpdir = '/tmp';
}
self::$tmpdir .= '/gitlist_' . md5(time() . mt_rand());
$fs = new Filesystem();
$fs->mkdir(self::$tmpdir);
if (!is_writable(self::$tmpdir)) {
$this->markTestSkipped('There are no write permissions in order to create test repositories.');
}
}
public function setUp()
{
if (!is_writable(ClientTest::PATH)) {
if (!is_writable(self::$tmpdir)) {
$this->markTestSkipped('There are no write permissions in order to create test repositories.');
}
$options['path'] = getenv('GIT_CLIENT') ?: '/usr/bin/git';
$options['hidden'] = array(ClientTest::PATH . '/hiddenrepo');
$options['hidden'] = array(self::$tmpdir . '/hiddenrepo');
$this->client = new Client($options);
}
@@ -32,7 +48,7 @@ class ClientTest extends PHPUnit_Framework_TestCase
*/
public function testIsNotFindingRepositories()
{
$this->client->getRepositories(ClientTest::PATH . '/testrepo');
$this->client->getRepositories(self::$tmpdir . '/testrepo');
}
/**
@@ -40,7 +56,7 @@ class ClientTest extends PHPUnit_Framework_TestCase
*/
public function testIsNotAbleToGetUnexistingRepository()
{
$this->client->getRepository(ClientTest::PATH . '/testrepo');
$this->client->getRepository(self::$tmpdir . '/testrepo');
}
/**
@@ -48,12 +64,12 @@ class ClientTest extends PHPUnit_Framework_TestCase
*/
public function testIsNotAbleToGetUnexistingRepositories()
{
$this->client->getRepositories('/tmp');
$this->client->getRepositories(self::$tmpdir);
}
public function testIsCreatingRepository()
{
$repository = $this->client->createRepository(ClientTest::PATH . '/testrepo');
$repository = $this->client->createRepository(self::$tmpdir . '/testrepo');
$this->assertRegExp("/nothing to commit/", $repository->getClient()->run($repository, 'status'));
}
@@ -62,14 +78,14 @@ class ClientTest extends PHPUnit_Framework_TestCase
*/
public function testIsNotAbleToCreateRepositoryDueToExistingOne()
{
$this->client->createRepository(ClientTest::PATH . '/testrepo');
$this->client->createRepository(self::$tmpdir . '/testrepo');
}
public function testIsListingRepositories()
{
$this->client->createRepository(ClientTest::PATH . '/anothertestrepo');
$this->client->createRepository(ClientTest::PATH . '/bigbadrepo');
$repositories = $this->client->getRepositories(ClientTest::PATH);
$this->client->createRepository(self::$tmpdir . '/anothertestrepo');
$this->client->createRepository(self::$tmpdir . '/bigbadrepo');
$repositories = $this->client->getRepositories(self::$tmpdir);
$this->assertEquals($repositories[0]['name'], 'anothertestrepo');
$this->assertEquals($repositories[1]['name'], 'bigbadrepo');
@@ -78,8 +94,8 @@ class ClientTest extends PHPUnit_Framework_TestCase
public function testIsNotListingHiddenRepositories()
{
$this->client->createRepository(ClientTest::PATH . '/hiddenrepo');
$repositories = $this->client->getRepositories(ClientTest::PATH);
$this->client->createRepository(self::$tmpdir . '/hiddenrepo');
$repositories = $this->client->getRepositories(self::$tmpdir);
$this->assertEquals($repositories[0]['name'], 'anothertestrepo');
$this->assertEquals($repositories[1]['name'], 'bigbadrepo');
@@ -92,7 +108,7 @@ class ClientTest extends PHPUnit_Framework_TestCase
*/
public function testIsNotOpeningHiddenRepositories()
{
$this->client->getRepository(ClientTest::PATH . '/hiddenrepo');
$this->client->getRepository(self::$tmpdir . '/hiddenrepo');
}
/**
@@ -100,13 +116,18 @@ class ClientTest extends PHPUnit_Framework_TestCase
*/
public function testIsCatchingGitCommandErrors()
{
$repository = $this->client->getRepository(ClientTest::PATH . '/testrepo');
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
$repository->getClient()->run($repository, 'wrong');
}
public static function tearDownAfterClass()
{
$fs = new Filesystem();
$fs->remove(ClientTest::PATH);
try {
//$fs->remove(self::$tmpdir);
} catch (IOException $e) {
// Ignore, file is not closed yet
}
}
}

View File

@@ -4,30 +4,41 @@ require 'vendor/autoload.php';
use Silex\WebTestCase;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Exception\IOException;
use GitList\Component\Git\Client;
class InterfaceTest extends WebTestCase
{
const PATH = '/tmp/gitlist/';
protected static $tmpdir;
public static function setUpBeforeClass()
{
$fs = new Filesystem();
$fs->mkdir(InterfaceTest::PATH);
if (getenv('TMP')) {
self::$tmpdir = getenv('TMP');
} elseif (getenv('TMPDIR')) {
self::$tmpdir = getenv('TMPDIR');
} else {
self::$tmpdir = '/tmp';
}
if (!is_writable(InterfaceTest::PATH)) {
self::$tmpdir .= '/gitlist_' . md5(time() . mt_rand()) . '/';
$fs = new Filesystem();
$fs->mkdir(self::$tmpdir);
if (!is_writable(self::$tmpdir)) {
$this->markTestSkipped('There are no write permissions in order to create test repositories.');
}
$options['path'] = getenv('GIT_CLIENT') ?: '/usr/bin/git';
$options['hidden'] = array(InterfaceTest::PATH . '/hiddenrepo');
$options['hidden'] = array(self::$tmpdir . '/hiddenrepo');
$git = new Client($options);
// GitTest repository fixture
$git->createRepository(InterfaceTest::PATH . 'GitTest');
$repository = $git->getRepository(InterfaceTest::PATH . 'GitTest');
file_put_contents(InterfaceTest::PATH . 'GitTest/README.md', "## GitTest\nGitTest is a *test* repository!");
file_put_contents(InterfaceTest::PATH . 'GitTest/test.php', "<?php\necho 'Hello World'; // This is a test");
$git->createRepository(self::$tmpdir . 'GitTest');
$repository = $git->getRepository(self::$tmpdir . 'GitTest');
file_put_contents(self::$tmpdir . 'GitTest/README.md', "## GitTest\nGitTest is a *test* repository!");
file_put_contents(self::$tmpdir . 'GitTest/test.php', "<?php\necho 'Hello World'; // This is a test");
$repository->setConfig('user.name', 'Luke Skywalker');
$repository->setConfig('user.email', 'luke@rebel.org');
$repository->addAll();
@@ -36,14 +47,14 @@ class InterfaceTest extends WebTestCase
$repository->createBranch('issue42');
// foobar repository fixture
$git->createRepository(InterfaceTest::PATH . 'foobar');
$repository = $git->getRepository(InterfaceTest::PATH . '/foobar');
file_put_contents(InterfaceTest::PATH . 'foobar/bar.json', "{\n\"name\": \"foobar\"\n}");
file_put_contents(InterfaceTest::PATH . 'foobar/.git/description', 'This is a test repo!');
$fs->mkdir(InterfaceTest::PATH . 'foobar/myfolder');
$fs->mkdir(InterfaceTest::PATH . 'foobar/testfolder');
file_put_contents(InterfaceTest::PATH . 'foobar/myfolder/mytest.php', "<?php\necho 'Hello World'; // This is my test");
file_put_contents(InterfaceTest::PATH . 'foobar/testfolder/test.php', "<?php\necho 'Hello World'; // This is a test");
$git->createRepository(self::$tmpdir . 'foobar');
$repository = $git->getRepository(self::$tmpdir . '/foobar');
file_put_contents(self::$tmpdir . 'foobar/bar.json', "{\n\"name\": \"foobar\"\n}");
file_put_contents(self::$tmpdir . 'foobar/.git/description', 'This is a test repo!');
$fs->mkdir(self::$tmpdir . 'foobar/myfolder');
$fs->mkdir(self::$tmpdir . 'foobar/testfolder');
file_put_contents(self::$tmpdir . 'foobar/myfolder/mytest.php', "<?php\necho 'Hello World'; // This is my test");
file_put_contents(self::$tmpdir . 'foobar/testfolder/test.php', "<?php\necho 'Hello World'; // This is a test");
$repository->setConfig('user.name', 'Luke Skywalker');
$repository->setConfig('user.email', 'luke@rebel.org');
$repository->addAll();
@@ -54,7 +65,7 @@ class InterfaceTest extends WebTestCase
{
$app = require 'boot.php';
$app['debug'] = true;
$app['git.repos'] = InterfaceTest::PATH;
$app['git.repos'] = self::$tmpdir;
return $app;
}
@@ -193,6 +204,11 @@ class InterfaceTest extends WebTestCase
public static function tearDownAfterClass()
{
$fs = new Filesystem();
$fs->remove(InterfaceTest::PATH);
try {
$fs->remove(self::$tmpdir);
} catch (IOException $e) {
// Ignore, file is not closed yet
}
}
}
}

View File

@@ -8,17 +8,33 @@ use Symfony\Component\Filesystem\Filesystem;
class RepositoryTest extends PHPUnit_Framework_TestCase
{
const PATH = '/tmp/gitlist';
protected static $tmpdir;
protected $client;
public static function setUpBeforeClass()
{
mkdir(RepositoryTest::PATH);
if (getenv('TMP')) {
self::$tmpdir = getenv('TMP');
} elseif (getenv('TMPDIR')) {
self::$tmpdir = getenv('TMPDIR');
} else {
self::$tmpdir = '/tmp';
}
self::$tmpdir .= '/gitlist_' . md5(time() . mt_rand());
$fs = new Filesystem();
$fs->mkdir(self::$tmpdir);
if (!is_writable(self::$tmpdir)) {
$this->markTestSkipped('There are no write permissions in order to create test repositories.');
}
}
public function setUp()
{
if (!is_writable(RepositoryTest::PATH)) {
if (!is_writable(self::$tmpdir)) {
$this->markTestSkipped('There are no write permissions in order to create test repositories.');
}
@@ -29,9 +45,9 @@ class RepositoryTest extends PHPUnit_Framework_TestCase
public function testIsCreatingRepositoryFixtures()
{
$a = $this->client->createRepository(RepositoryTest::PATH . '/testrepo');
$b = $this->client->createRepository(RepositoryTest::PATH . '/anothertestrepo');
$c = $this->client->createRepository(RepositoryTest::PATH . '/bigbadrepo');
$a = $this->client->createRepository(self::$tmpdir . '/testrepo');
$b = $this->client->createRepository(self::$tmpdir . '/anothertestrepo');
$c = $this->client->createRepository(self::$tmpdir . '/bigbadrepo');
$this->assertRegExp("/nothing to commit/", $a->getClient()->run($a, 'status'));
$this->assertRegExp("/nothing to commit/", $b->getClient()->run($b, 'status'));
$this->assertRegExp("/nothing to commit/", $c->getClient()->run($c, 'status'));
@@ -39,18 +55,18 @@ class RepositoryTest extends PHPUnit_Framework_TestCase
public function testIsConfiguratingRepository()
{
$repository = $this->client->getRepository(RepositoryTest::PATH . '/testrepo');
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
$repository->setConfig('user.name', 'Luke Skywalker');
$repository->setConfig('user.email', 'luke@rebel.org');
$this->assertEquals($repository->getConfig('user.name'), 'Luke Skywalker');
$this->assertEquals($repository->getConfig('user.email'), 'luke@rebel.org');
}
public function testIsAdding()
{
$repository = $this->client->getRepository(RepositoryTest::PATH . '/testrepo');
file_put_contents(RepositoryTest::PATH . '/testrepo/test_file.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
file_put_contents(self::$tmpdir . '/testrepo/test_file.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
$repository->add('test_file.txt');
$this->assertRegExp("/new file: test_file.txt/", $repository->getClient()->run($repository, 'status'));
}
@@ -60,11 +76,11 @@ class RepositoryTest extends PHPUnit_Framework_TestCase
*/
public function testIsAddingDot()
{
$repository = $this->client->getRepository(RepositoryTest::PATH . '/testrepo');
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
file_put_contents(RepositoryTest::PATH . '/testrepo/test_file1.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
file_put_contents(RepositoryTest::PATH . '/testrepo/test_file2.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
file_put_contents(RepositoryTest::PATH . '/testrepo/test_file3.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
file_put_contents(self::$tmpdir . '/testrepo/test_file1.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
file_put_contents(self::$tmpdir . '/testrepo/test_file2.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
file_put_contents(self::$tmpdir . '/testrepo/test_file3.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
$repository->add();
@@ -78,14 +94,14 @@ class RepositoryTest extends PHPUnit_Framework_TestCase
*/
public function testIsAddingAll()
{
$repository = $this->client->getRepository(RepositoryTest::PATH . '/testrepo');
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
file_put_contents(RepositoryTest::PATH . '/testrepo/test_file4.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
file_put_contents(RepositoryTest::PATH . '/testrepo/test_file5.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
file_put_contents(RepositoryTest::PATH . '/testrepo/test_file6.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
file_put_contents(self::$tmpdir . '/testrepo/test_file4.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
file_put_contents(self::$tmpdir . '/testrepo/test_file5.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
file_put_contents(self::$tmpdir . '/testrepo/test_file6.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
$repository->addAll();
$this->assertRegExp("/new file: test_file4.txt/", $repository->getClient()->run($repository, 'status'));
$this->assertRegExp("/new file: test_file5.txt/", $repository->getClient()->run($repository, 'status'));
$this->assertRegExp("/new file: test_file6.txt/", $repository->getClient()->run($repository, 'status'));
@@ -96,11 +112,11 @@ class RepositoryTest extends PHPUnit_Framework_TestCase
*/
public function testIsAddingArrayOfFiles()
{
$repository = $this->client->getRepository(RepositoryTest::PATH . '/testrepo');
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
file_put_contents(RepositoryTest::PATH . '/testrepo/test_file7.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
file_put_contents(RepositoryTest::PATH . '/testrepo/test_file8.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
file_put_contents(RepositoryTest::PATH . '/testrepo/test_file9.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
file_put_contents(self::$tmpdir . '/testrepo/test_file7.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
file_put_contents(self::$tmpdir . '/testrepo/test_file8.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
file_put_contents(self::$tmpdir . '/testrepo/test_file9.txt', 'Your mother is so ugly, glCullFace always returns TRUE.');
$repository->add(array('test_file7.txt', 'test_file8.txt', 'test_file9.txt'));
@@ -108,20 +124,20 @@ class RepositoryTest extends PHPUnit_Framework_TestCase
$this->assertRegExp("/new file: test_file8.txt/", $repository->getClient()->run($repository, 'status'));
$this->assertRegExp("/new file: test_file9.txt/", $repository->getClient()->run($repository, 'status'));
}
/**
* @depends testIsAddingArrayOfFiles
*/
public function testIsCommiting()
{
$repository = $this->client->getRepository(RepositoryTest::PATH . '/testrepo');
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
$repository->commit("The truth unveiled");
$this->assertRegExp("/The truth unveiled/", $repository->getClient()->run($repository, 'log'));
}
public function testIsCreatingBranches()
{
$repository = $this->client->getRepository(RepositoryTest::PATH . '/testrepo');
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
$repository->createBranch('issue12');
$repository->createBranch('issue42');
$branches = $repository->getBranches();
@@ -132,7 +148,7 @@ class RepositoryTest extends PHPUnit_Framework_TestCase
public function testIsGettingCurrentBranch()
{
$repository = $this->client->getRepository(RepositoryTest::PATH . '/testrepo');
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
$branch = $repository->getCurrentBranch();
$this->assertTrue($branch === 'master');
}
@@ -142,9 +158,9 @@ class RepositoryTest extends PHPUnit_Framework_TestCase
*/
public function testIsGettingCommits()
{
$repository = $this->client->getRepository(RepositoryTest::PATH . '/testrepo');
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
$commits = $repository->getCommits();
foreach ($commits as $commit) {
$this->assertInstanceOf('GitList\Component\Git\Commit\Commit', $commit);
$this->assertTrue($commit->getMessage() === 'The truth unveiled');
@@ -167,9 +183,9 @@ class RepositoryTest extends PHPUnit_Framework_TestCase
*/
public function testIsGettingCommitsFromSpecificFile()
{
$repository = $this->client->getRepository(RepositoryTest::PATH . '/testrepo');
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
$commits = $repository->getCommits('test_file4.txt');
foreach ($commits as $commit) {
$this->assertInstanceOf('GitList\Component\Git\Commit\Commit', $commit);
$this->assertTrue($commit->getMessage() === 'The truth unveiled');
@@ -181,9 +197,9 @@ class RepositoryTest extends PHPUnit_Framework_TestCase
public function testIsGettingTree()
{
$repository = $this->client->getRepository(RepositoryTest::PATH . '/testrepo');
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
$files = $repository->getTree('master');
foreach ($files as $file) {
$this->assertInstanceOf('GitList\Component\Git\Model\Blob', $file);
$this->assertRegExp('/test_file[0-9]*.txt/', $file->getName());
@@ -195,9 +211,9 @@ class RepositoryTest extends PHPUnit_Framework_TestCase
public function testIsGettingTreeOutput()
{
$repository = $this->client->getRepository(RepositoryTest::PATH . '/testrepo');
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
$files = $repository->getTree('master')->output();
foreach ($files as $file) {
$this->assertEquals('blob', $file['type']);
$this->assertRegExp('/test_file[0-9]*.txt/', $file['name']);
@@ -209,19 +225,19 @@ class RepositoryTest extends PHPUnit_Framework_TestCase
public function testIsGettingTreesWithinTree()
{
$repository = $this->client->getRepository(RepositoryTest::PATH . '/testrepo');
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
// Creating folders
mkdir(RepositoryTest::PATH . '/testrepo/MyFolder');
mkdir(RepositoryTest::PATH . '/testrepo/MyTest');
mkdir(RepositoryTest::PATH . '/testrepo/MyFolder/Tests');
mkdir(self::$tmpdir . '/testrepo/MyFolder');
mkdir(self::$tmpdir . '/testrepo/MyTest');
mkdir(self::$tmpdir . '/testrepo/MyFolder/Tests');
// Populating created folders
file_put_contents(RepositoryTest::PATH . '/testrepo/MyFolder/crazy.php', 'Lorem ipsum dolor sit amet');
file_put_contents(RepositoryTest::PATH . '/testrepo/MyFolder/skywalker.php', 'Lorem ipsum dolor sit amet');
file_put_contents(RepositoryTest::PATH . '/testrepo/MyTest/fortytwo.php', 'Lorem ipsum dolor sit amet');
file_put_contents(RepositoryTest::PATH . '/testrepo/MyFolder/Tests/web.php', 'Lorem ipsum dolor sit amet');
file_put_contents(RepositoryTest::PATH . '/testrepo/MyFolder/Tests/cli.php', 'Lorem ipsum dolor sit amet');
file_put_contents(self::$tmpdir . '/testrepo/MyFolder/crazy.php', 'Lorem ipsum dolor sit amet');
file_put_contents(self::$tmpdir . '/testrepo/MyFolder/skywalker.php', 'Lorem ipsum dolor sit amet');
file_put_contents(self::$tmpdir . '/testrepo/MyTest/fortytwo.php', 'Lorem ipsum dolor sit amet');
file_put_contents(self::$tmpdir . '/testrepo/MyFolder/Tests/web.php', 'Lorem ipsum dolor sit amet');
file_put_contents(self::$tmpdir . '/testrepo/MyFolder/Tests/cli.php', 'Lorem ipsum dolor sit amet');
// Adding and commiting
$repository->addAll();
@@ -251,7 +267,7 @@ class RepositoryTest extends PHPUnit_Framework_TestCase
public function testIsGettingBlobsWithinTrees()
{
$repository = $this->client->getRepository(RepositoryTest::PATH . '/testrepo');
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
$files = $repository->getTree('master:MyFolder/')->output();
$this->assertEquals('folder', $files[0]['type']);
@@ -275,7 +291,7 @@ class RepositoryTest extends PHPUnit_Framework_TestCase
public function testIsGettingBlobOutput()
{
$repository = $this->client->getRepository(RepositoryTest::PATH . '/testrepo');
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
$blob = $repository->getBlob('master:MyFolder/crazy.php')->output();
$this->assertEquals('Lorem ipsum dolor sit amet', $blob);
@@ -285,7 +301,7 @@ class RepositoryTest extends PHPUnit_Framework_TestCase
public function testIsGettingStatistics()
{
$repository = $this->client->getRepository(RepositoryTest::PATH . '/testrepo');
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
$stats = $repository->getStatistics('master');
$this->assertEquals('10', $stats['extensions']['.txt']);
@@ -296,7 +312,7 @@ class RepositoryTest extends PHPUnit_Framework_TestCase
public function testIsGettingAuthorStatistics()
{
$repository = $this->client->getRepository(RepositoryTest::PATH . '/testrepo');
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
$stats = $repository->getAuthorStatistics();
$this->assertEquals('Luke Skywalker', $stats[0]['name']);
@@ -305,7 +321,7 @@ class RepositoryTest extends PHPUnit_Framework_TestCase
$repository->setConfig('user.name', 'Princess Leia');
$repository->setConfig('user.email', 'sexyleia@republic.com');
file_put_contents(RepositoryTest::PATH . '/testrepo/MyFolder/crazy.php', 'Lorem ipsum dolor sit AMET');
file_put_contents(self::$tmpdir . '/testrepo/MyFolder/crazy.php', 'Lorem ipsum dolor sit AMET');
$repository->addAll();
$repository->commit("Fixing AMET case");
@@ -322,17 +338,21 @@ class RepositoryTest extends PHPUnit_Framework_TestCase
public function testIsGettingSymlinksWithinTrees()
{
$repository = $this->client->getRepository(RepositoryTest::PATH . '/testrepo');
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$this->markTestSkipped('Unable to run on Windows');
}
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
$fs = new Filesystem();
$fs->touch(RepositoryTest::PATH . '/testrepo/original_file.txt');
$fs->symlink(RepositoryTest::PATH . '/testrepo/original_file.txt', RepositoryTest::PATH . '/testrepo/link.txt');
$fs->touch(self::$tmpdir . '/testrepo/original_file.txt');
$fs->symlink(self::$tmpdir . '/testrepo/original_file.txt', self::$tmpdir . '/testrepo/link.txt');
$repository->addAll();
$repository->commit("Testing symlinks");
$files = $repository->getTree('master');
foreach ($files as $file) {
if ($file instanceof GitList\Component\Git\Model\Symlink) {
$this->assertEquals($file->getPath(), RepositoryTest::PATH . '/testrepo/original_file.txt');
$this->assertEquals($file->getPath(), self::$tmpdir . '/testrepo/original_file.txt');
$this->assertEquals($file->getName(), 'link.txt');
$this->assertEquals($file->getMode(), '120000');
return;
@@ -344,17 +364,21 @@ class RepositoryTest extends PHPUnit_Framework_TestCase
public function testIsGettingSymlinksWithinTreesOutput()
{
$repository = $this->client->getRepository(RepositoryTest::PATH . '/testrepo');
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$this->markTestSkipped('Unable to run on Windows');
}
$repository = $this->client->getRepository(self::$tmpdir . '/testrepo');
$fs = new Filesystem();
$fs->touch(RepositoryTest::PATH . '/testrepo/original_file.txt');
$fs->symlink(RepositoryTest::PATH . '/testrepo/original_file.txt', RepositoryTest::PATH . '/testrepo/link2.txt');
$fs->touch(self::$tmpdir . '/testrepo/original_file.txt');
$fs->symlink(self::$tmpdir . '/testrepo/original_file.txt', self::$tmpdir . '/testrepo/link2.txt');
$repository->addAll();
$repository->commit("Testing symlinks");
$files = $repository->getTree('master')->output();
foreach ($files as $file) {
if ($file['type'] == 'symlink') {
$this->assertEquals($file['path'], RepositoryTest::PATH . '/testrepo/original_file.txt');
$this->assertEquals($file['path'], self::$tmpdir . '/testrepo/original_file.txt');
$this->assertEquals($file['name'], 'link.txt');
$this->assertEquals($file['mode'], '120000');
return;
@@ -367,6 +391,11 @@ class RepositoryTest extends PHPUnit_Framework_TestCase
public static function tearDownAfterClass()
{
$fs = new Filesystem();
$fs->remove(RepositoryTest::PATH);
try {
$fs->remove(self::$tmpdir);
} catch (\Exception $e) {
// Ignore, file is not closed yet
}
}
}