Skip to content

Commit

Permalink
Merge pull request klaussilveira#5 from GromNaN/tests
Browse files Browse the repository at this point in the history
Reorganize tests dir to follow best pratices + add tests on commit import
  • Loading branch information
klaussilveira committed Sep 15, 2012
2 parents d962d30 + 3afe883 commit a86a927
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 28 deletions.
4 changes: 3 additions & 1 deletion tests/ClientTest.php → tests/Gitter/Tests/ClientTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php

namespace Gitter\Tests;

use Gitter\Client;
use Gitter\Repository;
use Symfony\Component\Filesystem\Filesystem;

class ClientTest extends PHPUnit_Framework_TestCase
class ClientTest extends \PHPUnit_Framework_TestCase
{
public static $tmpdir;
protected $client;
Expand Down
40 changes: 40 additions & 0 deletions tests/Gitter/Tests/Model/Commit/CommitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Gitter\Tests\Model\Commit;

use Gitter\Model\Commit\Commit;
use Gitter\PrettyFormat;

class CommitTest extends \PHPUnit_Framework_TestCase
{
public function testImportData()
{
$data = array (
'hash' => '209908f247194b1adc836f2e50f957cb1f11f41c',
'short_hash' => '209908f',
'tree' => '0a1f6638ccfc6d6b34be8a913144304355d23cc3',
'parents' => '6e6951114ccf7b162e2a57b0462b39ca972f476f 1e8fd833f71fd20f8b176c79c705b9f096434126',
'author' => 'The Author',
'author_email' => 'author@example.com',
'date' => '1347372763',
'commiter' => 'The Commiter',
'commiter_email' => 'commiter@example.com',
'commiter_date' => '1347372763',
'message' => 'Test commit',
);
$commit = new Commit();
$commit->importData($data);

$this->assertEquals('209908f247194b1adc836f2e50f957cb1f11f41c', $commit->getHash());
$this->assertEquals('209908f', $commit->getShortHash());
$this->assertEquals('0a1f6638ccfc6d6b34be8a913144304355d23cc3', $commit->getTreeHash());
$this->assertEquals(array('6e6951114ccf7b162e2a57b0462b39ca972f476f', '1e8fd833f71fd20f8b176c79c705b9f096434126'), $commit->getParentsHash());
$this->assertEquals('The Author', $commit->getAuthor()->getName());
$this->assertEquals('author@example.com', $commit->getAuthor()->getEmail());
$this->assertEquals(new \DateTime('@1347372763'), $commit->getDate());
$this->assertEquals('The Commiter', $commit->getCommiter()->getName());
$this->assertEquals('commiter@example.com', $commit->getCommiter()->getEmail());
$this->assertEquals(new \DateTime('@1347372763'), $commit->getCommiterDate());
$this->assertEquals('Test commit', $commit->getMessage());
}
}
49 changes: 49 additions & 0 deletions tests/Gitter/Tests/PrettyFormatTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Gitter\Tests;

use Gitter\PrettyFormat;

class PrettyFormatTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider dataForTestIsParsingPrettyXMLFormat
*/
public function testIsParsingPrettyXMLFormat($xml, $expected)
{
$format = new PrettyFormat();

$this->assertEquals($expected, $format->parse($xml));
}

public function dataForTestIsParsingPrettyXMLFormat()
{
return array(
array(
'<item><tag>value</tag><tag2>value2</tag2></item>',
array(array('tag' => 'value', 'tag2' => 'value2')),
),
array(
'<item><empty_tag></empty_tag></item>',
array(array('empty_tag' => '')),
),
array(
'<item><tag>item 1</tag></item><item><tag>item 2</tag></item>',
array(array('tag' => 'item 1'), array('tag' => 'item 2')),
),
array(
'<item><tag><inner_tag>value</inner_tag></tag></item>',
array(array('tag' => array(array('inner_tag' => 'value')))),
)
);
}

/**
* @expectedException RuntimeException
*/
public function testIsNotParsingWithoutData()
{
$format = new PrettyFormat;
$format->parse('');
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<?php

namespace Gitter\Tests;

use Gitter\Client;
use Gitter\Repository;
use Gitter\Model\Symlink;
use Symfony\Component\Filesystem\Filesystem;

class RepositoryTest extends PHPUnit_Framework_TestCase
class RepositoryTest extends \PHPUnit_Framework_TestCase
{
protected static $tmpdir;

Expand Down Expand Up @@ -340,7 +343,7 @@ public function testIsGettingSymlinksWithinTrees()
$files = $repository->getTree('master');

foreach ($files as $file) {
if ($file instanceof Gitter\Model\Symlink) {
if ($file instanceof Symlink) {
$this->assertEquals($file->getPath(), self::$tmpdir . '/testrepo/original_file.txt');
$this->assertEquals($file->getName(), 'link.txt');
$this->assertEquals($file->getMode(), '120000');
Expand Down
25 changes: 0 additions & 25 deletions tests/PrettyFormatTest.php

This file was deleted.

0 comments on commit a86a927

Please sign in to comment.