|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Github\Tests\Api\Organization; |
| 4 | + |
| 5 | +use Github\Tests\Api\TestCase; |
| 6 | + |
| 7 | +class HooksTest extends TestCase |
| 8 | +{ |
| 9 | + /** |
| 10 | + * @test |
| 11 | + */ |
| 12 | + public function shouldGetAllOrganizationsHooks() |
| 13 | + { |
| 14 | + $expectedValue = array(array('name' => 'hook')); |
| 15 | + |
| 16 | + $api = $this->getApiMock(); |
| 17 | + $api->expects($this->once()) |
| 18 | + ->method('get') |
| 19 | + ->with('orgs/KnpLabs/hooks') |
| 20 | + ->will($this->returnValue($expectedValue)); |
| 21 | + |
| 22 | + $this->assertEquals($expectedValue, $api->all('KnpLabs')); |
| 23 | + } |
| 24 | + |
| 25 | + /** |
| 26 | + * @test |
| 27 | + */ |
| 28 | + public function shouldShowHook() |
| 29 | + { |
| 30 | + $expectedValue = array('hook' => 'somename'); |
| 31 | + |
| 32 | + $api = $this->getApiMock(); |
| 33 | + $api->expects($this->once()) |
| 34 | + ->method('get') |
| 35 | + ->with('orgs/KnpLabs/hooks/123') |
| 36 | + ->will($this->returnValue($expectedValue)); |
| 37 | + |
| 38 | + $this->assertEquals($expectedValue, $api->show('KnpLabs', 123)); |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * @test |
| 43 | + */ |
| 44 | + public function shouldRemoveHook() |
| 45 | + { |
| 46 | + $expectedValue = array('someOutput'); |
| 47 | + |
| 48 | + $api = $this->getApiMock(); |
| 49 | + $api->expects($this->once()) |
| 50 | + ->method('delete') |
| 51 | + ->with('orgs/KnpLabs/hooks/123') |
| 52 | + ->will($this->returnValue($expectedValue)); |
| 53 | + |
| 54 | + $this->assertEquals($expectedValue, $api->remove('KnpLabs', 123)); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * @test |
| 59 | + * @expectedException \Github\Exception\MissingArgumentException |
| 60 | + */ |
| 61 | + public function shouldNotCreateHookWithoutName() |
| 62 | + { |
| 63 | + $data = array('config' => 'conf'); |
| 64 | + |
| 65 | + $api = $this->getApiMock(); |
| 66 | + $api->expects($this->never()) |
| 67 | + ->method('post'); |
| 68 | + |
| 69 | + $api->create('KnpLabs', $data); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * @test |
| 74 | + * @expectedException \Github\Exception\MissingArgumentException |
| 75 | + */ |
| 76 | + public function shouldNotCreateHookWithoutConfig() |
| 77 | + { |
| 78 | + $data = array('name' => 'test'); |
| 79 | + |
| 80 | + $api = $this->getApiMock(); |
| 81 | + $api->expects($this->never()) |
| 82 | + ->method('post'); |
| 83 | + |
| 84 | + $api->create('KnpLabs', $data); |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * @test |
| 89 | + */ |
| 90 | + public function shouldCreateHook() |
| 91 | + { |
| 92 | + $expectedValue = array('hook' => 'somename'); |
| 93 | + $data = array('name' => 'test', 'config' => 'someconfig'); |
| 94 | + |
| 95 | + $api = $this->getApiMock(); |
| 96 | + $api->expects($this->once()) |
| 97 | + ->method('post') |
| 98 | + ->with('orgs/KnpLabs/hooks', $data) |
| 99 | + ->will($this->returnValue($expectedValue)); |
| 100 | + |
| 101 | + $this->assertEquals($expectedValue, $api->create('KnpLabs', $data)); |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * @test |
| 106 | + * @expectedException \Github\Exception\MissingArgumentException |
| 107 | + */ |
| 108 | + public function shouldNotUpdateHookWithoutConfig() |
| 109 | + { |
| 110 | + $data = array(); |
| 111 | + |
| 112 | + $api = $this->getApiMock(); |
| 113 | + $api->expects($this->never()) |
| 114 | + ->method('patch'); |
| 115 | + |
| 116 | + $api->update('KnpLabs', 123, $data); |
| 117 | + } |
| 118 | + |
| 119 | + /** |
| 120 | + * @test |
| 121 | + */ |
| 122 | + public function shouldUpdateHook() |
| 123 | + { |
| 124 | + $expectedValue = array('hook' => 'somename'); |
| 125 | + $data = array('config' => 'config'); |
| 126 | + |
| 127 | + $api = $this->getApiMock(); |
| 128 | + $api->expects($this->once()) |
| 129 | + ->method('patch') |
| 130 | + ->with('orgs/KnpLabs/hooks/123', $data) |
| 131 | + ->will($this->returnValue($expectedValue)); |
| 132 | + |
| 133 | + $this->assertEquals($expectedValue, $api->update('KnpLabs', 123, $data)); |
| 134 | + } |
| 135 | + |
| 136 | + /** |
| 137 | + * @test |
| 138 | + */ |
| 139 | + public function shouldPingHook() |
| 140 | + { |
| 141 | + $expectedValue = null; |
| 142 | + |
| 143 | + $api = $this->getApiMock(); |
| 144 | + $api->expects($this->once()) |
| 145 | + ->method('post') |
| 146 | + ->with('orgs/KnpLabs/hooks/123/pings') |
| 147 | + ->will($this->returnValue($expectedValue)); |
| 148 | + |
| 149 | + $this->assertEquals($expectedValue, $api->ping('KnpLabs', 123)); |
| 150 | + } |
| 151 | + |
| 152 | + protected function getApiClass() |
| 153 | + { |
| 154 | + return 'Github\Api\Organization\Hooks'; |
| 155 | + } |
| 156 | +} |
0 commit comments