Skip to content

Commit 9029121

Browse files
peter279kGrahamCampbell
authored andcommitted
Test enhancement (#146)
1 parent e027bfe commit 9029121

12 files changed

+60
-59
lines changed

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
<testsuites>
1616
<testsuite name="Test Suite">
17-
<directory>tests/Gitonomy/Git/Tests</directory>
17+
<directory suffix="Test.php">tests/Gitonomy/Git/Tests</directory>
1818
</testsuite>
1919
</testsuites>
2020

tests/Gitonomy/Git/Tests/AdminTest.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ class AdminTest extends AbstractTest
2020
{
2121
private $tmpDir;
2222

23-
public function setUp()
23+
protected function setUp()
2424
{
2525
$this->tmpDir = self::createTempDir();
2626
}
2727

28-
public function tearDown()
28+
protected function tearDown()
2929
{
3030
$this->deleteDir(self::createTempDir());
3131
}
@@ -37,8 +37,8 @@ public function testBare()
3737
$objectDir = $this->tmpDir.'/objects';
3838

3939
$this->assertTrue($repository->isBare(), 'Repository is bare');
40-
$this->assertTrue(is_dir($objectDir), 'objects/ folder is present');
41-
$this->assertTrue($repository instanceof Repository, 'Admin::init returns a repository');
40+
$this->assertDirectoryExists($objectDir, 'objects/ folder is present');
41+
$this->assertInstanceOf(Repository::class, $repository, 'Admin::init returns a repository');
4242
$this->assertEquals($this->tmpDir, $repository->getGitDir(), 'The folder passed as argument is git dir');
4343
$this->assertNull($repository->getWorkingDir(), 'No working dir in bare repository');
4444
}
@@ -50,8 +50,8 @@ public function testNotBare()
5050
$objectDir = $this->tmpDir.'/.git/objects';
5151

5252
$this->assertFalse($repository->isBare(), 'Repository is not bare');
53-
$this->assertTrue(is_dir($objectDir), 'objects/ folder is present');
54-
$this->assertTrue($repository instanceof Repository, 'Admin::init returns a repository');
53+
$this->assertDirectoryExists($objectDir, 'objects/ folder is present');
54+
$this->assertInstanceOf(Repository::class, $repository, 'Admin::init returns a repository');
5555
$this->assertEquals($this->tmpDir.'/.git', $repository->getGitDir(), 'git dir as subfolder of argument');
5656
$this->assertEquals($this->tmpDir, $repository->getWorkingDir(), 'working dir present in bare repository');
5757
}
@@ -67,12 +67,12 @@ public function testClone($repository)
6767

6868
$newRefs = array_keys($new->getReferences()->getAll());
6969

70-
$this->assertTrue(in_array('refs/heads/master', $newRefs));
71-
$this->assertTrue(in_array('refs/tags/0.1', $newRefs));
70+
$this->assertContains('refs/heads/master', $newRefs);
71+
$this->assertContains('refs/tags/0.1', $newRefs);
7272

7373
if ($repository->isBare()) {
7474
$this->assertEquals($newDir, $new->getGitDir());
75-
$this->assertTrue(in_array('refs/heads/new-feature', $newRefs));
75+
$this->assertContains('refs/heads/new-feature', $newRefs);
7676
} else {
7777
$this->assertEquals($newDir.'/.git', $new->getGitDir());
7878
$this->assertEquals($newDir, $new->getWorkingDir());
@@ -90,7 +90,7 @@ public function testCloneBranchBare()
9090
self::registerDeletion($new);
9191

9292
$head = $new->getHead();
93-
$this->assertTrue($head instanceof Branch, 'HEAD is a branch');
93+
$this->assertInstanceOf(Branch::class, $head, 'HEAD is a branch');
9494
$this->assertEquals('new-feature', $head->getName(), 'HEAD is branch new-feature');
9595
}
9696

@@ -105,7 +105,7 @@ public function testCloneBranchNotBare()
105105
self::registerDeletion($new);
106106

107107
$head = $new->getHead();
108-
$this->assertTrue($head instanceof Branch, 'HEAD is a branch');
108+
$this->assertInstanceOf(Branch::class, $head, 'HEAD is a branch');
109109
$this->assertEquals('new-feature', $head->getName(), 'HEAD is branch new-feature');
110110
}
111111

@@ -120,14 +120,14 @@ public function testMirror($repository)
120120

121121
$newRefs = array_keys($new->getReferences()->getAll());
122122

123-
$this->assertTrue(in_array('refs/heads/master', $newRefs));
124-
$this->assertTrue(in_array('refs/tags/0.1', $newRefs));
123+
$this->assertContains('refs/heads/master', $newRefs);
124+
$this->assertContains('refs/tags/0.1', $newRefs);
125125
$this->assertEquals($newDir, $new->getGitDir());
126126

127127
if ($repository->isBare()) {
128-
$this->assertTrue(in_array('refs/heads/new-feature', $newRefs));
128+
$this->assertContains('refs/heads/new-feature', $newRefs);
129129
} else {
130-
$this->assertTrue(in_array('refs/remotes/origin/new-feature', $newRefs));
130+
$this->assertContains('refs/remotes/origin/new-feature', $newRefs);
131131
}
132132
}
133133

@@ -169,8 +169,8 @@ public function testCloneRepository()
169169

170170
$newRefs = array_keys($new->getReferences()->getAll());
171171

172-
$this->assertTrue(in_array('refs/heads/master', $newRefs));
173-
$this->assertTrue(in_array('refs/tags/0.1', $newRefs));
172+
$this->assertContains('refs/heads/master', $newRefs);
173+
$this->assertContains('refs/tags/0.1', $newRefs);
174174

175175
$this->assertEquals($newDir.'/.git', $new->getGitDir());
176176
$this->assertEquals($newDir, $new->getWorkingDir());

tests/Gitonomy/Git/Tests/CommitTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
namespace Gitonomy\Git\Tests;
1414

1515
use Gitonomy\Git\Commit;
16+
use Gitonomy\Git\Tree;
1617
use Gitonomy\Git\Diff\Diff;
1718

1819
class CommitTest extends AbstractTest
@@ -26,7 +27,7 @@ public function testGetDiff($repository)
2627

2728
$diff = $commit->getDiff();
2829

29-
$this->assertTrue($diff instanceof Diff, 'getDiff() returns a Diff object');
30+
$this->assertInstanceOf(Diff::class, $diff, 'getDiff() returns a Diff object');
3031
}
3132

3233
/**
@@ -47,7 +48,7 @@ public function testGetHash($repository)
4748
*/
4849
public function testInvalideHashThrowException($repository)
4950
{
50-
$commit = new Commit($repository, 'that-hash-doest-not-exists');
51+
new Commit($repository, 'that-hash-doest-not-exists');
5152
}
5253

5354
/**
@@ -67,7 +68,7 @@ public function testGetParentHashes_WithNoParent($repository)
6768
{
6869
$commit = $repository->getCommit(self::INITIAL_COMMIT);
6970

70-
$this->assertEquals(0, count($commit->getParentHashes()), 'No parent on initial commit');
71+
$this->assertCount(0, $commit->getParentHashes(), 'No parent on initial commit');
7172
}
7273

7374
/**
@@ -78,7 +79,7 @@ public function testGetParentHashes_WithOneParent($repository)
7879
$commit = $repository->getCommit(self::LONGFILE_COMMIT);
7980
$parents = $commit->getParentHashes();
8081

81-
$this->assertEquals(1, count($parents), 'One parent found');
82+
$this->assertCount(1, $parents, 'One parent found');
8283
$this->assertEquals(self::BEFORE_LONGFILE_COMMIT, $parents[0], 'Parent hash is correct');
8384
}
8485

@@ -90,8 +91,8 @@ public function testGetParents_WithOneParent($repository)
9091
$commit = $repository->getCommit(self::LONGFILE_COMMIT);
9192
$parents = $commit->getParents();
9293

93-
$this->assertEquals(1, count($parents), 'One parent found');
94-
$this->assertTrue($parents[0] instanceof Commit, 'First parent is a Commit object');
94+
$this->assertCount(1, $parents, 'One parent found');
95+
$this->assertInstanceOf(Commit::class, $parents[0], 'First parent is a Commit object');
9596
$this->assertEquals(self::BEFORE_LONGFILE_COMMIT, $parents[0]->getHash(), "First parents's hash is correct");
9697
}
9798

@@ -112,7 +113,7 @@ public function testGetTree($repository)
112113
{
113114
$commit = $repository->getCommit(self::LONGFILE_COMMIT);
114115

115-
$this->assertInstanceOf('Gitonomy\Git\Tree', $commit->getTree(), 'Tree is a tree');
116+
$this->assertInstanceOf(Tree::class, $commit->getTree(), 'Tree is a tree');
116117
$this->assertEquals('b06890c7b10904979d2f69613c2ccda30aafe262', $commit->getTree()->getHash(), 'Tree hash is correct');
117118
}
118119

tests/Gitonomy/Git/Tests/DiffTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected function verifyCreateCommitDiff(Diff $diff)
4545
{
4646
$files = $diff->getFiles();
4747

48-
$this->assertEquals(2, count($files), '1 file in diff');
48+
$this->assertCount(2, $files, '1 file in diff');
4949

5050
$this->assertTrue($files[0]->isCreation(), 'script_A.php created');
5151

@@ -65,7 +65,7 @@ public function testGetFiles_Modification($repository)
6565
{
6666
$files = $repository->getCommit(self::BEFORE_LONGFILE_COMMIT)->getDiff()->getFiles();
6767

68-
$this->assertEquals(1, count($files), '1 files in diff');
68+
$this->assertCount(1, $files, '1 files in diff');
6969

7070
$this->assertTrue($files[0]->isModification(), 'image.jpg modified');
7171

@@ -86,7 +86,7 @@ public function testGetFiles_Deletion($repository)
8686
{
8787
$files = $repository->getCommit(self::DELETE_COMMIT)->getDiff()->getFiles();
8888

89-
$this->assertEquals(1, count($files), '1 files modified');
89+
$this->assertCount(1, $files, '1 files modified');
9090

9191
$this->assertTrue($files[0]->isDeletion(), 'File deletion');
9292
$this->assertEquals('script_B.php', $files[0]->getOldName(), 'verify old filename');
@@ -100,7 +100,7 @@ public function testGetFiles_Rename($repository)
100100
{
101101
$files = $repository->getCommit(self::RENAME_COMMIT)->getDiff()->getFiles();
102102

103-
$this->assertEquals(1, count($files), '1 files modified');
103+
$this->assertCount(1, $files, '1 files modified');
104104

105105
$this->assertTrue($files[0]->isModification());
106106
$this->assertTrue($files[0]->isRename());
@@ -116,7 +116,7 @@ public function testGetFiles_Changemode($repository)
116116
{
117117
$files = $repository->getCommit(self::CHANGEMODE_COMMIT)->getDiff()->getFiles();
118118

119-
$this->assertEquals(1, count($files), '1 files modified');
119+
$this->assertCount(1, $files, '1 files modified');
120120

121121
$this->assertTrue($files[0]->isModification());
122122
$this->assertTrue($files[0]->isChangeMode());

tests/Gitonomy/Git/Tests/HooksTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ public function assertHasHook($repository, $hook)
4949
$file = $this->hookPath($repository, $hook);
5050

5151
$this->assertTrue($repository->getHooks()->has($hook), "hook $hook in repository");
52-
$this->assertTrue(file_exists($file), "Hook $hook is present");
52+
$this->assertFileExists($file, "Hook $hook is present");
5353
}
5454

5555
public function assertNoHook($repository, $hook)
5656
{
5757
$file = $this->hookPath($repository, $hook);
5858

5959
$this->assertFalse($repository->getHooks()->has($hook), "No hook $hook in repository");
60-
$this->assertFalse(file_exists($file), "Hook $hook is not present");
60+
$this->assertFileNotExists($file, "Hook $hook is not present");
6161
}
6262

6363
/**
@@ -154,7 +154,7 @@ public function testRemove($repository)
154154
touch($file);
155155

156156
$repository->getHooks()->remove('foo');
157-
$this->assertFalse(file_exists($file));
157+
$this->assertFileNotExists($file);
158158
}
159159

160160
/**

tests/Gitonomy/Git/Tests/LogTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public function testRevisionAndPath($repository)
2222
$logReadme = $repository->getLog(self::LONGFILE_COMMIT, 'README');
2323
$logImage = $repository->getLog(self::LONGFILE_COMMIT, 'image.jpg');
2424

25-
$this->assertEquals(3, count($logReadme));
26-
$this->assertEquals(2, count($logImage));
25+
$this->assertCount(3, $logReadme);
26+
$this->assertCount(2, $logImage);
2727
}
2828

2929
/**
@@ -35,7 +35,7 @@ public function testGetCommits($repository)
3535

3636
$commits = $log->getCommits();
3737

38-
$this->assertEquals(3, count($commits), '3 commits in log');
38+
$this->assertCount(3, $commits, '3 commits in log');
3939
$this->assertEquals(self::LONGFILE_COMMIT, $commits[0]->getHash(), 'First is requested one');
4040
$this->assertEquals(self::BEFORE_LONGFILE_COMMIT, $commits[1]->getHash(), "Second is longfile parent\'s");
4141
}

tests/Gitonomy/Git/Tests/PushReferenceTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function testLog($repository)
5252
$ref = new PushReference($repository, 'foo', self::INITIAL_COMMIT, self::LONGFILE_COMMIT);
5353

5454
$log = $ref->getLog()->getCommits();
55-
$this->assertEquals(7, count($log), '7 commits in log');
55+
$this->assertCount(7, $log, '7 commits in log');
5656
$this->assertEquals('add a long file', $log[0]->getShortMessage(), 'First commit is correct');
5757
}
5858

@@ -65,7 +65,7 @@ public function testSignedLog($repository)
6565
{
6666
$ref = new PushReference($repository, 'foo', self::INITIAL_COMMIT, self::SIGNED_COMMIT);
6767
$log = $ref->getLog()->getCommits();
68-
$this->assertEquals(16, count($log), '16 commits in log');
68+
$this->assertCount(16, $log, '16 commits in log');
6969
$this->assertEquals('signed commit', $log[0]->getShortMessage(), 'Last commit is correct');
7070
}
7171

@@ -77,7 +77,7 @@ public function testLogWithExclude($repository)
7777
$ref = new PushReference($repository, 'foo', PushReference::ZERO, self::LONGFILE_COMMIT);
7878

7979
$log = $ref->getLog([self::INITIAL_COMMIT])->getCommits();
80-
$this->assertEquals(7, count($log), '7 commits in log');
80+
$this->assertCount(7, $log, '7 commits in log');
8181
$this->assertEquals('add a long file', $log[0]->getShortMessage(), 'First commit is correct');
8282
}
8383
}

tests/Gitonomy/Git/Tests/ReferenceTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function testGetBranch($repository)
3535
{
3636
$branch = $repository->getReferences()->getBranch('master');
3737

38-
$this->assertTrue($branch instanceof Branch, 'Branch object is correct type');
38+
$this->assertInstanceOf(Branch::class, $branch, 'Branch object is correct type');
3939
$this->assertEquals($branch->getCommitHash(), $branch->getCommit()->getHash(), 'Hash is correctly resolved');
4040
}
4141

@@ -63,7 +63,7 @@ public function testHasTag($repository)
6363
*/
6464
public function testGetBranch_NotExisting_Error($repository)
6565
{
66-
$branch = $repository->getReferences()->getBranch('notexisting');
66+
$repository->getReferences()->getBranch('notexisting');
6767
}
6868

6969
/**
@@ -73,7 +73,7 @@ public function testGetTag($repository)
7373
{
7474
$tag = $repository->getReferences()->getTag('0.1');
7575

76-
$this->assertTrue($tag instanceof Tag, 'Tag object is correct type');
76+
$this->assertInstanceOf(Tag::class, $tag, 'Tag object is correct type');
7777
$this->assertFalse($tag->isAnnotated(), 'Tag is not annotated');
7878

7979
$this->assertEquals(self::LONGFILE_COMMIT, $tag->getCommitHash(), 'Commit hash is correct');
@@ -87,7 +87,7 @@ public function testAnnotatedTag($repository)
8787
{
8888
$tag = $repository->getReferences()->getTag('annotated');
8989

90-
$this->assertTrue($tag instanceof Tag, 'Tag object is correct type');
90+
$this->assertInstanceOf(Tag::class, $tag, 'Tag object is correct type');
9191
$this->assertTrue($tag->isAnnotated(), 'Tag is annotated');
9292
$this->assertFalse($tag->isSigned(), 'Tag is not signed');
9393

@@ -105,7 +105,7 @@ public function testAnnotatedTag($repository)
105105
*/
106106
public function testGetTag_NotExisting_Error($repository)
107107
{
108-
$branch = $repository->getReferences()->getTag('notexisting');
108+
$repository->getReferences()->getTag('notexisting');
109109
}
110110

111111
/**
@@ -116,8 +116,8 @@ public function testResolve($repository)
116116
$commit = $repository->getReferences()->getTag('0.1')->getCommit();
117117
$resolved = $repository->getReferences()->resolve($commit->getHash());
118118

119-
$this->assertEquals(1, count($resolved), '1 revision resolved');
120-
$this->assertTrue(reset($resolved) instanceof Tag, 'Resolved object is a tag');
119+
$this->assertCount(1, $resolved, '1 revision resolved');
120+
$this->assertInstanceOf(Tag::class, reset($resolved), 'Resolved object is a tag');
121121
}
122122

123123
/**
@@ -128,8 +128,8 @@ public function testResolveTags($repository)
128128
$commit = $repository->getReferences()->getTag('0.1')->getCommit();
129129
$resolved = $repository->getReferences()->resolveTags($commit->getHash());
130130

131-
$this->assertEquals(1, count($resolved), '1 revision resolved');
132-
$this->assertTrue(reset($resolved) instanceof Tag, 'Resolved object is a tag');
131+
$this->assertCount(1, $resolved, '1 revision resolved');
132+
$this->assertInstanceOf(Tag::class, reset($resolved), 'Resolved object is a tag');
133133
}
134134

135135
/**
@@ -142,12 +142,12 @@ public function testResolveBranches($repository)
142142
$resolved = $repository->getReferences()->resolveBranches($master->getCommitHash());
143143

144144
if ($repository->isBare()) {
145-
$this->assertEquals(1, count($resolved), '1 revision resolved');
145+
$this->assertCount(1, $resolved, '1 revision resolved');
146146
} else {
147-
$this->assertEquals(2, count($resolved), '2 revision resolved');
147+
$this->assertCount(2, $resolved, '2 revision resolved');
148148
}
149149

150-
$this->assertTrue(reset($resolved) instanceof Branch, 'Resolved object is a branch');
150+
$this->assertInstanceOf(Branch::class, reset($resolved), 'Resolved object is a branch');
151151
}
152152

153153
/**

tests/Gitonomy/Git/Tests/RepositoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function testGetBlob_WithExisting_Works($repository)
2424
{
2525
$blob = $repository->getCommit(self::LONGFILE_COMMIT)->getTree()->resolvePath('README.md');
2626

27-
$this->assertTrue($blob instanceof Blob, 'getBlob() returns a Blob object');
27+
$this->assertInstanceOf(Blob::class, $blob, 'getBlob() returns a Blob object');
2828
$this->assertContains('Foo Bar project', $blob->getContent(), 'file is correct');
2929
}
3030

0 commit comments

Comments
 (0)