|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * (c) Packagist Conductors GmbH <[email protected]> |
| 5 | + * |
| 6 | + * For the full copyright and license information, please view the LICENSE |
| 7 | + * file that was distributed with this source code. |
| 8 | + */ |
| 9 | + |
| 10 | +namespace PrivatePackagist\ApiClient\Api; |
| 11 | + |
| 12 | +use PHPUnit\Framework\MockObject\MockObject; |
| 13 | + |
| 14 | +class VendorBundlesTest extends ApiTestCase |
| 15 | +{ |
| 16 | + public function testAll() |
| 17 | + { |
| 18 | + $expected = [ |
| 19 | + [ |
| 20 | + 'id' => 1, |
| 21 | + 'name' => 'Bundle', |
| 22 | + 'versionConstraint' => null, |
| 23 | + 'minimumAccessibleStability' => null, |
| 24 | + 'assignAllPackages' => false, |
| 25 | + 'synchronizations' => [], |
| 26 | + ], |
| 27 | + ]; |
| 28 | + |
| 29 | + /** @var VendorBundles&MockObject $api */ |
| 30 | + $api = $this->getApiMock(); |
| 31 | + $api->expects($this->once()) |
| 32 | + ->method('get') |
| 33 | + ->with($this->identicalTo('/vendor-bundles/')) |
| 34 | + ->willReturn($expected); |
| 35 | + |
| 36 | + $this->assertSame($expected, $api->all()); |
| 37 | + } |
| 38 | + |
| 39 | + public function testShow() |
| 40 | + { |
| 41 | + $expected = [ |
| 42 | + 'id' => 1, |
| 43 | + 'name' => 'Bundle', |
| 44 | + 'versionConstraint' => null, |
| 45 | + 'minimumAccessibleStability' => null, |
| 46 | + 'assignAllPackages' => false, |
| 47 | + 'synchronizations' => [], |
| 48 | + ]; |
| 49 | + |
| 50 | + /** @var VendorBundles&MockObject $api */ |
| 51 | + $api = $this->getApiMock(); |
| 52 | + $api->expects($this->once()) |
| 53 | + ->method('get') |
| 54 | + ->with($this->identicalTo('/vendor-bundles/1/')) |
| 55 | + ->willReturn($expected); |
| 56 | + |
| 57 | + $this->assertSame($expected, $api->show(1)); |
| 58 | + } |
| 59 | + |
| 60 | + public function testCreate() |
| 61 | + { |
| 62 | + $expected = [ |
| 63 | + 'id' => 1, |
| 64 | + 'name' => 'Bundle', |
| 65 | + 'versionConstraint' => null, |
| 66 | + 'minimumAccessibleStability' => null, |
| 67 | + 'assignAllPackages' => false, |
| 68 | + 'synchronizations' => [], |
| 69 | + ]; |
| 70 | + |
| 71 | + /** @var VendorBundles&MockObject $api */ |
| 72 | + $api = $this->getApiMock(); |
| 73 | + $api->expects($this->once()) |
| 74 | + ->method('post') |
| 75 | + ->with($this->identicalTo('/vendor-bundles/'), $this->identicalTo([ |
| 76 | + 'name' => 'Bundle', |
| 77 | + 'minimumAccessibleStability' => null, |
| 78 | + 'versionConstraint' => null, |
| 79 | + 'assignAllPackages' => false, |
| 80 | + 'synchronizationIds' => [], |
| 81 | + ])) |
| 82 | + ->willReturn($expected); |
| 83 | + |
| 84 | + $this->assertSame($expected, $api->create('Bundle')); |
| 85 | + } |
| 86 | + |
| 87 | + public function testCreateAllParameters() |
| 88 | + { |
| 89 | + $expected = [ |
| 90 | + 'id' => 1, |
| 91 | + 'name' => 'Bundle', |
| 92 | + 'versionConstraint' => '^1.0', |
| 93 | + 'minimumAccessibleStability' => 'stable', |
| 94 | + 'assignAllPackages' => true, |
| 95 | + 'synchronizations' => [ |
| 96 | + ['id' => 123], |
| 97 | + ], |
| 98 | + ]; |
| 99 | + |
| 100 | + /** @var VendorBundles&MockObject $api */ |
| 101 | + $api = $this->getApiMock(); |
| 102 | + $api->expects($this->once()) |
| 103 | + ->method('post') |
| 104 | + ->with($this->identicalTo('/vendor-bundles/'), $this->identicalTo([ |
| 105 | + 'name' => 'Bundle', |
| 106 | + 'minimumAccessibleStability' => 'stable', |
| 107 | + 'versionConstraint' => '^1.0', |
| 108 | + 'assignAllPackages' => true, |
| 109 | + 'synchronizationIds' => [123], |
| 110 | + ])) |
| 111 | + ->willReturn($expected); |
| 112 | + |
| 113 | + $this->assertSame($expected, $api->create('Bundle', 'stable', '^1.0', true, [123])); |
| 114 | + } |
| 115 | + |
| 116 | + public function tesEdit() |
| 117 | + { |
| 118 | + $expected = [ |
| 119 | + 'id' => 1, |
| 120 | + 'name' => 'Bundle', |
| 121 | + 'versionConstraint' => '^1.0', |
| 122 | + 'minimumAccessibleStability' => 'stable', |
| 123 | + 'assignAllPackages' => true, |
| 124 | + 'synchronizations' => [ |
| 125 | + ['id' => 123], |
| 126 | + ], |
| 127 | + ]; |
| 128 | + |
| 129 | + $bundle = [ |
| 130 | + 'id' => 1, |
| 131 | + 'name' => 'Bundle', |
| 132 | + 'versionConstraint' => '^1.0', |
| 133 | + 'minimumAccessibleStability' => 'stable', |
| 134 | + 'assignAllPackages' => true, |
| 135 | + 'synchronizationIds' => [123], |
| 136 | + ]; |
| 137 | + |
| 138 | + /** @var VendorBundles&MockObject $api */ |
| 139 | + $api = $this->getApiMock(); |
| 140 | + $api->expects($this->once()) |
| 141 | + ->method('put') |
| 142 | + ->with($this->identicalTo('/vendor-bundles/1/'), $this->identicalTo($bundle)) |
| 143 | + ->willReturn($expected); |
| 144 | + |
| 145 | + $this->assertSame($expected, $api->edit(1, $bundle)); |
| 146 | + } |
| 147 | + |
| 148 | + public function testRemove() |
| 149 | + { |
| 150 | + $expected = ''; |
| 151 | + |
| 152 | + /** @var VendorBundles&MockObject $api */ |
| 153 | + $api = $this->getApiMock(); |
| 154 | + $api->expects($this->once()) |
| 155 | + ->method('delete') |
| 156 | + ->with($this->identicalTo('/vendor-bundles/1/')) |
| 157 | + ->willReturn($expected); |
| 158 | + |
| 159 | + $this->assertSame($expected, $api->remove(1)); |
| 160 | + } |
| 161 | + |
| 162 | + protected function getApiClass() |
| 163 | + { |
| 164 | + return VendorBundles::class; |
| 165 | + } |
| 166 | +} |
0 commit comments