Skip to content

Commit 779e83b

Browse files
committed
add tests for contents create, update and rm methods
1 parent 3b08cd9 commit 779e83b

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

test/Github/Tests/Api/Repository/ContentsTest.php

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,122 @@ public function shouldShowReadme()
3838
$this->assertEquals($expectedValue, $api->readme('KnpLabs', 'php-github-api'));
3939
}
4040

41+
/**
42+
* @test
43+
*/
44+
public function shouldCreateNewFile()
45+
{
46+
$expectedArray = array('content' => 'some data');
47+
$content = '<?php //..';
48+
$message = 'a commit message';
49+
$branch = 'master';
50+
$committer = array('name' => 'committer name', 'email' => 'email@example.com');
51+
$parameters = array(
52+
'content' => base64_encode($content),
53+
'message' => $message,
54+
'committer' => $committer,
55+
'branch' => $branch,
56+
);
57+
58+
$api = $this->getApiMock();
59+
$api->expects($this->once())
60+
->method('put')
61+
->with('repos/KnpLabs/php-github-api/contents/test%2FGithub%2FTests%2FApi%2FRepository%2FContentsTest.php', $parameters)
62+
->will($this->returnValue($expectedArray));
63+
64+
$this->assertEquals($expectedArray, $api->create('KnpLabs', 'php-github-api', 'test/Github/Tests/Api/Repository/ContentsTest.php', $content, $message, $branch, $committer));
65+
}
66+
67+
/**
68+
* @test
69+
* @expectedException Github\Exception\MissingArgumentException
70+
* @expectedExceptionMessage One or more of required ("name", "email") parameters is missing!
71+
*/
72+
public function shouldThrowExceptionWhenCreateNewFileWithInvalidCommitter()
73+
{
74+
$committer = array('invalid_key' => 'some data');
75+
$api = $this->getApiMock();
76+
$api->create('KnpLabs', 'php-github-api', 'test/Github/Tests/Api/Repository/ContentsTest.php', 'some content', 'a commit message', null, $committer);
77+
}
78+
79+
/**
80+
* @test
81+
*/
82+
public function shouldUpdateFile()
83+
{
84+
$expectedArray = array('content' => 'some data');
85+
$content = '<?php //..';
86+
$message = 'a commit message';
87+
$sha = 'a sha';
88+
$branch = 'master';
89+
$committer = array('name' => 'committer name', 'email' => 'email@example.com');
90+
$parameters = array(
91+
'content' => base64_encode($content),
92+
'message' => $message,
93+
'committer' => $committer,
94+
'branch' => $branch,
95+
'sha' => $sha,
96+
);
97+
98+
$api = $this->getApiMock();
99+
$api->expects($this->once())
100+
->method('put')
101+
->with('repos/KnpLabs/php-github-api/contents/test%2FGithub%2FTests%2FApi%2FRepository%2FContentsTest.php', $parameters)
102+
->will($this->returnValue($expectedArray));
103+
104+
$this->assertEquals($expectedArray, $api->update('KnpLabs', 'php-github-api', 'test/Github/Tests/Api/Repository/ContentsTest.php', $content, $message, $sha, $branch, $committer));
105+
}
106+
107+
/**
108+
* @test
109+
* @expectedException Github\Exception\MissingArgumentException
110+
* @expectedExceptionMessage One or more of required ("name", "email") parameters is missing!
111+
*/
112+
public function shouldThrowExceptionWhenUpdateFileWithInvalidCommitter()
113+
{
114+
$committer = array('invalid_key' => 'some data');
115+
$api = $this->getApiMock();
116+
$api->update('KnpLabs', 'php-github-api', 'test/Github/Tests/Api/Repository/ContentsTest.php', 'some content', 'a commit message', null, null, $committer);
117+
}
118+
119+
/**
120+
* @test
121+
*/
122+
public function shouldDeleteFile()
123+
{
124+
$expectedArray = array('content' => 'some data');
125+
$message = 'a commit message';
126+
$sha = 'a sha';
127+
$branch = 'master';
128+
$committer = array('name' => 'committer name', 'email' => 'email@example.com');
129+
$parameters = array(
130+
'message' => $message,
131+
'committer' => $committer,
132+
'branch' => $branch,
133+
'sha' => $sha,
134+
);
135+
136+
$api = $this->getApiMock();
137+
$api->expects($this->once())
138+
->method('delete')
139+
->with('repos/KnpLabs/php-github-api/contents/test%2FGithub%2FTests%2FApi%2FRepository%2FContentsTest.php', $parameters)
140+
->will($this->returnValue($expectedArray));
141+
142+
$this->assertEquals($expectedArray, $api->rm('KnpLabs', 'php-github-api', 'test/Github/Tests/Api/Repository/ContentsTest.php', $message, $sha, $branch, $committer));
143+
}
144+
145+
/**
146+
* @test
147+
* @expectedException Github\Exception\MissingArgumentException
148+
* @expectedExceptionMessage One or more of required ("name", "email") parameters is missing!
149+
*/
150+
public function shouldThrowExceptionWhenDeleteFileWithInvalidCommitter()
151+
{
152+
$committer = array('invalid_key' => 'some data');
153+
$api = $this->getApiMock();
154+
$api->rm('KnpLabs', 'php-github-api', 'test/Github/Tests/Api/Repository/ContentsTest.php', 'a commit message', null, null, $committer);
155+
}
156+
41157
/**
42158
* @test
43159
*/

0 commit comments

Comments
 (0)