Skip to content

Commit 01a42ec

Browse files
Full test suite
1 parent d0930a7 commit 01a42ec

2 files changed

Lines changed: 61 additions & 3 deletions

File tree

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "get-stream/stream-zend",
33
"homepage": "https://getstream.io/",
4-
"description": "Build newsfeeds and activity feeds with Zend framework using getstream.io",
4+
"description": "Build newsfeeds and activity feeds with Zend Framework using getstream.io",
55
"keywords": ["stream", "feed", "feedly", "getstream", "activity", "newsfeed", "activity feed", "notification feed", "aggregated feed", "zend", "zf3"],
66
"license": "BSD",
77
"authors": [
@@ -29,7 +29,7 @@
2929
},
3030
"config": {
3131
"zf": {
32-
"component": "GetStream\\Stream\\"
32+
"component": "GetStream\\Stream"
3333
}
3434
},
3535
"minimum-stability": "stable"

tests/unit/ModuleTest.php

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,97 @@
22

33
namespace GetStream\Zend\Unit;
44

5+
use GetStream\Stream\Client;
6+
use GetStream\Zend\Module;
57
use PHPUnit\Framework\TestCase;
8+
use Psr\Container\ContainerInterface;
9+
use Zend\ModuleManager\Feature\ServiceProviderInterface;
610

711
class ModuleTest extends TestCase
812
{
913
/** @test */
1014
public function implementsServiceProviderInterface()
1115
{
1216
// Arrange
17+
$module = new Module();
18+
1319
// Act
1420
// Assert
21+
$this->assertInstanceOf(ServiceProviderInterface::class, $module);
1522
}
1623

1724
/** @test */
1825
public function setsClientFactory()
1926
{
2027
// Arrange
28+
$module = new Module();
29+
2130
// Act
31+
$config = $module->getServiceConfig();
32+
2233
// 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]);
2337
}
2438

2539
/** @test */
2640
public function sharesClient()
2741
{
2842
// 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+
2966
// Act
67+
$config = $module->getServiceConfig();
68+
$callable = $config['factories'][Client::class];
69+
3070
// Assert
71+
$response = $callable($container);
72+
73+
$this->assertInstanceOf(Client::class, $response);
3174
}
3275

3376
/** @test */
34-
public function factoryInitiatesClientFromConfig()
77+
public function factoryInitiatesClientFromCredentials()
3578
{
3679
// 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+
3789
// Act
90+
$config = $module->getServiceConfig();
91+
$callable = $config['factories'][Client::class];
92+
3893
// Assert
94+
$response = $callable($container);
95+
96+
$this->assertInstanceOf(Client::class, $response);
3997
}
4098
}

0 commit comments

Comments
 (0)