|
2 | 2 |
|
3 | 3 | namespace GetStream\Zend\Unit; |
4 | 4 |
|
| 5 | +use GetStream\Stream\Client; |
| 6 | +use GetStream\Zend\Module; |
5 | 7 | use PHPUnit\Framework\TestCase; |
| 8 | +use Psr\Container\ContainerInterface; |
| 9 | +use Zend\ModuleManager\Feature\ServiceProviderInterface; |
6 | 10 |
|
7 | 11 | class ModuleTest extends TestCase |
8 | 12 | { |
9 | 13 | /** @test */ |
10 | 14 | public function implementsServiceProviderInterface() |
11 | 15 | { |
12 | 16 | // Arrange |
| 17 | + $module = new Module(); |
| 18 | + |
13 | 19 | // Act |
14 | 20 | // Assert |
| 21 | + $this->assertInstanceOf(ServiceProviderInterface::class, $module); |
15 | 22 | } |
16 | 23 |
|
17 | 24 | /** @test */ |
18 | 25 | public function setsClientFactory() |
19 | 26 | { |
20 | 27 | // Arrange |
| 28 | + $module = new Module(); |
| 29 | + |
21 | 30 | // Act |
| 31 | + $config = $module->getServiceConfig(); |
| 32 | + |
22 | 33 | // Assert |
| 34 | + $this->assertContains('factories', array_keys($config)); |
| 35 | + $this->assertContains(Client::class, array_keys($config['factories'])); |
| 36 | + $this->assertInternalType('callable', $config['factories'][Client::class]); |
23 | 37 | } |
24 | 38 |
|
25 | 39 | /** @test */ |
26 | 40 | public function sharesClient() |
27 | 41 | { |
28 | 42 | // Arrange |
| 43 | + $module = new Module(); |
| 44 | + |
| 45 | + // Act |
| 46 | + $config = $module->getServiceConfig(); |
| 47 | + |
| 48 | + // Assert |
| 49 | + $this->assertContains('shared', array_keys($config)); |
| 50 | + $this->assertContains(Client::class, array_keys($config['shared'])); |
| 51 | + $this->assertTrue($config['shared'][Client::class]); |
| 52 | + } |
| 53 | + |
| 54 | + /** @test */ |
| 55 | + public function factoryInitiatesClientFromURL() |
| 56 | + { |
| 57 | + // Arrange |
| 58 | + $module = new Module(); |
| 59 | + $container = $this->createMock(ContainerInterface::class); |
| 60 | + $container->expects($this->once())->method('get')->with('config')->willReturn([ |
| 61 | + 'stream' => [ |
| 62 | + 'url' => 'https://blabla:blabla@api.stream-api.com/', |
| 63 | + ], |
| 64 | + ]); |
| 65 | + |
29 | 66 | // Act |
| 67 | + $config = $module->getServiceConfig(); |
| 68 | + $callable = $config['factories'][Client::class]; |
| 69 | + |
30 | 70 | // Assert |
| 71 | + $response = $callable($container); |
| 72 | + |
| 73 | + $this->assertInstanceOf(Client::class, $response); |
31 | 74 | } |
32 | 75 |
|
33 | 76 | /** @test */ |
34 | | - public function factoryInitiatesClientFromConfig() |
| 77 | + public function factoryInitiatesClientFromCredentials() |
35 | 78 | { |
36 | 79 | // Arrange |
| 80 | + $module = new Module(); |
| 81 | + $container = $this->createMock(ContainerInterface::class); |
| 82 | + $container->expects($this->once())->method('get')->with('config')->willReturn([ |
| 83 | + 'stream' => [ |
| 84 | + 'app_key' => 'mock key', |
| 85 | + 'app_secret' => 'mock secret', |
| 86 | + ], |
| 87 | + ]); |
| 88 | + |
37 | 89 | // Act |
| 90 | + $config = $module->getServiceConfig(); |
| 91 | + $callable = $config['factories'][Client::class]; |
| 92 | + |
38 | 93 | // Assert |
| 94 | + $response = $callable($container); |
| 95 | + |
| 96 | + $this->assertInstanceOf(Client::class, $response); |
39 | 97 | } |
40 | 98 | } |
0 commit comments