|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Github\Tests\Api\Repository; |
| 4 | + |
| 5 | +use Github\Tests\Api\TestCase; |
| 6 | + |
| 7 | +class StatusesTest extends TestCase |
| 8 | +{ |
| 9 | + /** |
| 10 | + * @test |
| 11 | + */ |
| 12 | + public function shouldShowCommitStatuses() |
| 13 | + { |
| 14 | + $expectedValue = array( |
| 15 | + array('state' => 'success', 'context' => 'Travis'), |
| 16 | + array('state' => 'pending', 'context' => 'Travis') |
| 17 | + ); |
| 18 | + |
| 19 | + $api = $this->getApiMock(); |
| 20 | + $api->expects($this->once()) |
| 21 | + ->method('get') |
| 22 | + ->with('repos/KnpLabs/php-github-api/commits/commitSHA123456/statuses') |
| 23 | + ->will($this->returnValue($expectedValue)); |
| 24 | + |
| 25 | + $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 'commitSHA123456')); |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * @test |
| 30 | + */ |
| 31 | + public function shouldShowCombinedCommitStatuses() |
| 32 | + { |
| 33 | + $expectedValue = array( |
| 34 | + array( |
| 35 | + 'state' => 'success', |
| 36 | + 'statuses' => array( |
| 37 | + array( |
| 38 | + 'state' => 'success', |
| 39 | + 'context' => 'Travis' |
| 40 | + ), |
| 41 | + array( |
| 42 | + 'state' => 'success', |
| 43 | + 'context' => 'Jenkins' |
| 44 | + ) |
| 45 | + ) |
| 46 | + ) |
| 47 | + ); |
| 48 | + |
| 49 | + $api = $this->getApiMock(); |
| 50 | + $api->expects($this->once()) |
| 51 | + ->method('get') |
| 52 | + ->with('repos/KnpLabs/php-github-api/commits/commitSHA123456/status') |
| 53 | + ->will($this->returnValue($expectedValue)); |
| 54 | + |
| 55 | + $this->assertEquals($expectedValue, $api->combined('KnpLabs', 'php-github-api', 'commitSHA123456')); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * @test |
| 60 | + * @expectedException Github\Exception\MissingArgumentException |
| 61 | + */ |
| 62 | + public function shouldNotCreateWithoutStatus() |
| 63 | + { |
| 64 | + $data = array(); |
| 65 | + |
| 66 | + $api = $this->getApiMock(); |
| 67 | + $api->expects($this->never()) |
| 68 | + ->method('post'); |
| 69 | + |
| 70 | + $api->create('KnpLabs', 'php-github-api', 'commitSHA123456', $data); |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * @test |
| 75 | + */ |
| 76 | + public function shouldCreateCommitStatus() |
| 77 | + { |
| 78 | + $expectedValue = array('state' => 'success'); |
| 79 | + $data = array('state' => 'success'); |
| 80 | + |
| 81 | + $api = $this->getApiMock(); |
| 82 | + $api->expects($this->once()) |
| 83 | + ->method('post') |
| 84 | + ->with('repos/KnpLabs/php-github-api/statuses/commitSHA123456', $data) |
| 85 | + ->will($this->returnValue($expectedValue)); |
| 86 | + |
| 87 | + $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', 'commitSHA123456', $data)); |
| 88 | + } |
| 89 | + |
| 90 | + protected function getApiClass() |
| 91 | + { |
| 92 | + return 'Github\Api\Repository\Statuses'; |
| 93 | + } |
| 94 | +} |
0 commit comments