|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace PrivatePackagist\ApiClient\Api; |
| 4 | + |
| 5 | +class ProjectsTest extends ApiTestCase |
| 6 | +{ |
| 7 | + public function testAll() |
| 8 | + { |
| 9 | + $expected = [ |
| 10 | + $this->getProjectDefinition(), |
| 11 | + ]; |
| 12 | + |
| 13 | + /** @var Projects&\PHPUnit_Framework_MockObject_MockObject $api */ |
| 14 | + $api = $this->getApiMock(); |
| 15 | + $api->expects($this->once()) |
| 16 | + ->method('get') |
| 17 | + ->with($this->equalTo('/projects/')) |
| 18 | + ->will($this->returnValue($expected)); |
| 19 | + |
| 20 | + $this->assertSame($expected, $api->all()); |
| 21 | + } |
| 22 | + |
| 23 | + public function testShow() |
| 24 | + { |
| 25 | + $expected = $this->getProjectDefinition(); |
| 26 | + |
| 27 | + $projectId = 1; |
| 28 | + |
| 29 | + /** @var Projects&\PHPUnit_Framework_MockObject_MockObject $api */ |
| 30 | + $api = $this->getApiMock(); |
| 31 | + $api->expects($this->once()) |
| 32 | + ->method('get') |
| 33 | + ->with($this->equalTo('/projects/1/')) |
| 34 | + ->will($this->returnValue($expected)); |
| 35 | + |
| 36 | + $this->assertSame($expected, $api->show($projectId)); |
| 37 | + } |
| 38 | + |
| 39 | + public function testCreate() |
| 40 | + { |
| 41 | + $expected = $this->getProjectDefinition(); |
| 42 | + |
| 43 | + /** @var Projects&\PHPUnit_Framework_MockObject_MockObject $api */ |
| 44 | + $api = $this->getApiMock(); |
| 45 | + $api->expects($this->once()) |
| 46 | + ->method('post') |
| 47 | + ->with($this->equalTo('/projects/'), $this->equalTo(['name' => 'ACME Websites'])) |
| 48 | + ->will($this->returnValue($expected)); |
| 49 | + |
| 50 | + $this->assertSame($expected, $api->create('ACME Websites')); |
| 51 | + } |
| 52 | + |
| 53 | + public function testRemove() |
| 54 | + { |
| 55 | + $expected = ''; |
| 56 | + |
| 57 | + /** @var Projects&\PHPUnit_Framework_MockObject_MockObject $api */ |
| 58 | + $api = $this->getApiMock(); |
| 59 | + $api->expects($this->once()) |
| 60 | + ->method('delete') |
| 61 | + ->with($this->equalTo('/projects/1/')) |
| 62 | + ->will($this->returnValue($expected)); |
| 63 | + |
| 64 | + $this->assertSame($expected, $api->remove(1)); |
| 65 | + } |
| 66 | + |
| 67 | + public function testListTeams() |
| 68 | + { |
| 69 | + $expected = [ |
| 70 | + [ |
| 71 | + 'id' => 42, |
| 72 | + 'name' => 'Owners', |
| 73 | + 'permission' => 'owner', |
| 74 | + 'members' => [], |
| 75 | + 'projects' => [], |
| 76 | + ], |
| 77 | + ]; |
| 78 | + |
| 79 | + /** @var Projects&\PHPUnit_Framework_MockObject_MockObject $api */ |
| 80 | + $api = $this->getApiMock(); |
| 81 | + $api->expects($this->once()) |
| 82 | + ->method('get') |
| 83 | + ->with($this->equalTo('/projects/1/teams/')) |
| 84 | + ->will($this->returnValue($expected)); |
| 85 | + |
| 86 | + $this->assertSame($expected, $api->listTeams(1)); |
| 87 | + } |
| 88 | + |
| 89 | + public function testAddOrUpdateTeam() |
| 90 | + { |
| 91 | + $expected = [ |
| 92 | + [ |
| 93 | + 'id' => 42, |
| 94 | + 'name' => 'Owners', |
| 95 | + 'permission' => 'owner', |
| 96 | + 'members' => [], |
| 97 | + 'projects' => [], |
| 98 | + ], |
| 99 | + ]; |
| 100 | + |
| 101 | + $teams = [['id' => 42, 'permission' => 'owner']]; |
| 102 | + |
| 103 | + /** @var Projects&\PHPUnit_Framework_MockObject_MockObject $api */ |
| 104 | + $api = $this->getApiMock(); |
| 105 | + $api->expects($this->once()) |
| 106 | + ->method('post') |
| 107 | + ->with($this->equalTo('/projects/1/teams/'), $this->equalTo($teams)) |
| 108 | + ->will($this->returnValue($expected)); |
| 109 | + |
| 110 | + $this->assertSame($expected, $api->addOrUpdateTeams(1, $teams)); |
| 111 | + } |
| 112 | + |
| 113 | + public function testRemoveTeam() |
| 114 | + { |
| 115 | + $expected = ''; |
| 116 | + |
| 117 | + /** @var Projects&\PHPUnit_Framework_MockObject_MockObject $api */ |
| 118 | + $api = $this->getApiMock(); |
| 119 | + $api->expects($this->once()) |
| 120 | + ->method('delete') |
| 121 | + ->with($this->equalTo('/projects/1/teams/42/')) |
| 122 | + ->will($this->returnValue($expected)); |
| 123 | + |
| 124 | + $this->assertSame($expected, $api->removeTeam(1, 42)); |
| 125 | + } |
| 126 | + |
| 127 | + public function testListPackages() |
| 128 | + { |
| 129 | + $expected = [ |
| 130 | + [ |
| 131 | + 'name' => 'composer/composer', |
| 132 | + 'origin' => 'private', |
| 133 | + 'versionConstraint' => null, |
| 134 | + 'expirationDate' => null, |
| 135 | + ], |
| 136 | + ]; |
| 137 | + |
| 138 | + /** @var Projects&\PHPUnit_Framework_MockObject_MockObject $api */ |
| 139 | + $api = $this->getApiMock(); |
| 140 | + $api->expects($this->once()) |
| 141 | + ->method('get') |
| 142 | + ->with($this->equalTo('/projects/1/packages/')) |
| 143 | + ->will($this->returnValue($expected)); |
| 144 | + |
| 145 | + $this->assertSame($expected, $api->listPackages(1)); |
| 146 | + } |
| 147 | + |
| 148 | + private function getProjectDefinition() |
| 149 | + { |
| 150 | + return [ |
| 151 | + 'id' => 1, |
| 152 | + 'name' => 'ACME Websites', |
| 153 | + 'urlName' => 'acme-websites', |
| 154 | + 'teams' => [ |
| 155 | + [ |
| 156 | + 'id' => 1, |
| 157 | + 'name' => 'Owners', |
| 158 | + 'permission' => 'owner', |
| 159 | + 'members' => [ |
| 160 | + [ |
| 161 | + 'id' => 12, |
| 162 | + 'username' => 'username' |
| 163 | + ] |
| 164 | + ], |
| 165 | + ] |
| 166 | + ] |
| 167 | + ]; |
| 168 | + } |
| 169 | + |
| 170 | + /** |
| 171 | + * @return string |
| 172 | + */ |
| 173 | + protected function getApiClass() |
| 174 | + { |
| 175 | + return Projects::class; |
| 176 | + } |
| 177 | +} |
0 commit comments