|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Muffin\Webservice\Model; |
| 4 | + |
| 5 | +use Cake\TestSuite\TestCase; |
| 6 | +use Muffin\Webservice\Connection; |
| 7 | + |
| 8 | +class EndpointRegistryTest extends TestCase |
| 9 | +{ |
| 10 | + public function tearDown() |
| 11 | + { |
| 12 | + EndpointRegistry::clear(); |
| 13 | + } |
| 14 | + |
| 15 | + /** |
| 16 | + * Test to ensure that an endpoint can be added/retrieved from the registry |
| 17 | + * |
| 18 | + * @return void |
| 19 | + */ |
| 20 | + public function testAddingEndpoint() |
| 21 | + { |
| 22 | + $result = EndpointRegistry::get('Test', [ |
| 23 | + 'connection' => new Connection([ |
| 24 | + 'name' => 'test', |
| 25 | + 'service' => 'test' |
| 26 | + ]) |
| 27 | + ]); |
| 28 | + |
| 29 | + $this->assertInstanceOf(\Muffin\Webservice\Model\Endpoint::class, $result); |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * Ensure that if you try and set the options for an already configured Endpoint instance an |
| 34 | + * exception is thrown |
| 35 | + * |
| 36 | + * @expectedException \RuntimeException |
| 37 | + */ |
| 38 | + public function testAddingSameEndpoint() |
| 39 | + { |
| 40 | + $result = EndpointRegistry::get('Test', [ |
| 41 | + 'connection' => new Connection([ |
| 42 | + 'name' => 'test', |
| 43 | + 'service' => 'test' |
| 44 | + ]) |
| 45 | + ]); |
| 46 | + |
| 47 | + $this->assertInstanceOf(\Muffin\Webservice\Model\Endpoint::class, $result); |
| 48 | + |
| 49 | + $result = EndpointRegistry::get('Test', [ |
| 50 | + 'connection' => new Connection([ |
| 51 | + 'name' => 'exception', |
| 52 | + 'service' => 'exception' |
| 53 | + ]) |
| 54 | + ]); |
| 55 | + } |
| 56 | + |
| 57 | + public function testRemovingInstance() |
| 58 | + { |
| 59 | + $result = EndpointRegistry::get('Test', [ |
| 60 | + 'connection' => new Connection([ |
| 61 | + 'name' => 'test', |
| 62 | + 'service' => 'test' |
| 63 | + ]) |
| 64 | + ]); |
| 65 | + |
| 66 | + $this->assertInstanceOf(\Muffin\Webservice\Model\Endpoint::class, $result); |
| 67 | + |
| 68 | + EndpointRegistry::remove('Test'); |
| 69 | + |
| 70 | + $ref = new \ReflectionClass(EndpointRegistry::class); |
| 71 | + $this->assertEmpty($ref->getStaticProperties()['_instances']); |
| 72 | + $this->assertEmpty($ref->getStaticProperties()['_options']); |
| 73 | + } |
| 74 | + |
| 75 | + public function testClearing() |
| 76 | + { |
| 77 | + $result = EndpointRegistry::get('Test', [ |
| 78 | + 'connection' => new Connection([ |
| 79 | + 'name' => 'test', |
| 80 | + 'service' => 'test' |
| 81 | + ]) |
| 82 | + ]); |
| 83 | + |
| 84 | + $this->assertInstanceOf(\Muffin\Webservice\Model\Endpoint::class, $result); |
| 85 | + |
| 86 | + EndpointRegistry::clear(); |
| 87 | + |
| 88 | + $ref = new \ReflectionClass(EndpointRegistry::class); |
| 89 | + $this->assertEmpty($ref->getStaticProperties()['_instances']); |
| 90 | + $this->assertEmpty($ref->getStaticProperties()['_options']); |
| 91 | + } |
| 92 | +} |
0 commit comments