|
8 | 8 |
|
9 | 9 | use Cache\Adapter\PHPArray\ArrayCachePool; |
10 | 10 | use Cache\Adapter\Void\VoidCachePool; |
| 11 | +use Commercetools\Core\Cache\CacheAdapterFactory; |
11 | 12 | use GuzzleHttp\Client as HttpClient; |
12 | 13 | use GuzzleHttp\Handler\MockHandler; |
13 | 14 | use GuzzleHttp\HandlerStack; |
|
16 | 17 | use GuzzleHttp\Subscriber\Mock; |
17 | 18 | use Commercetools\Core\Cache\NullCacheAdapter; |
18 | 19 | use Commercetools\Core\Config; |
| 20 | +use Prophecy\Argument; |
| 21 | +use Psr\SimpleCache\CacheInterface; |
19 | 22 |
|
20 | 23 | class ManagerTest extends \PHPUnit_Framework_TestCase |
21 | 24 | { |
@@ -191,31 +194,44 @@ public function testCache() |
191 | 194 | $this->assertEmpty($manager->getToken()->getTtl()); // ttl should be empty as token comes from cache |
192 | 195 | } |
193 | 196 |
|
194 | | - public function testCacheAdapter() |
| 197 | + public function testPsrCacheAdapter() |
195 | 198 | { |
196 | 199 | $cache1 = new VoidCachePool(); |
197 | 200 | $manager = new Manager($this->getConfig(), $cache1); |
198 | 201 |
|
199 | | - $cache2 = new VoidCachePool(); |
| 202 | + $cache2 = new ArrayCachePool(); |
200 | 203 | $this->assertInstanceOf(Manager::class, $manager->setCacheAdapter($cache2)); |
201 | | - $this->assertSame($cache2, $manager->getCacheAdapter()); |
202 | 204 | } |
203 | 205 |
|
204 | | - public function testPsrCacheAdapter() |
| 206 | + public function testPsrSimpleCacheAdapter() |
205 | 207 | { |
206 | | - if (version_compare(phpversion(), '5.5.0', '<')) { |
207 | | - $this->markTestSkipped( |
208 | | - 'PHP >= 5.5 needed to run this test' |
209 | | - ); |
210 | | - } |
211 | | - $cache1 = new VoidCachePool(); |
212 | | - $manager = new Manager($this->getConfig(), $cache1); |
| 208 | + $cache = $this->prophesize(CacheInterface::class); |
| 209 | + $cache->get(Argument::type('string'), false)->willReturn('test')->shouldBeCalled(); |
| 210 | + $manager = new Manager($this->getConfig(), $cache->reveal()); |
213 | 211 |
|
214 | | - $cache2 = new ArrayCachePool(); |
215 | | - $this->assertInstanceOf(Manager::class, $manager->setCacheAdapter($cache2)); |
216 | | - $this->assertSame($cache2, $manager->getCacheAdapter()); |
| 212 | + $this->assertSame('test', $manager->getToken()->getToken()); |
| 213 | + } |
| 214 | + |
| 215 | + public function testSetPsrSimpleCacheAdapter() |
| 216 | + { |
| 217 | + $cache = $this->prophesize(CacheInterface::class); |
| 218 | + $cache->get(Argument::type('string'), false)->willReturn(false)->shouldBeCalled(); |
| 219 | + $cache->set(Argument::type('string'), 'myToken', 500)->shouldBeCalled(); |
| 220 | + |
| 221 | + $manager = $this->getManager( |
| 222 | + $this->getConfig(), |
| 223 | + [ |
| 224 | + "access_token" => "myToken", |
| 225 | + "token_type" => "Bearer", |
| 226 | + "expires_in" => 1000, |
| 227 | + "scope" => "manage_project:testCache" |
| 228 | + ] |
| 229 | + ); |
| 230 | + $manager->setCacheAdapter($cache->reveal()); |
| 231 | + $this->assertSame('myToken', $manager->getToken()->getToken()); |
217 | 232 | } |
218 | 233 |
|
| 234 | + |
219 | 235 | /** |
220 | 236 | * @expectedException \Commercetools\Core\Error\InvalidClientCredentialsException |
221 | 237 | */ |
|
0 commit comments