Skip to content

Commit

Permalink
Merge branch 'vkhramtsov-feature-replace-zend-with-laminas'
Browse files Browse the repository at this point in the history
  • Loading branch information
compeak committed Feb 18, 2020
2 parents 56adfe2 + f9bd97a commit e7c1216
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ vendor/
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
# composer.lock
/.phpunit.result.cache
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ The following configuration options are available:

| Key | Type | Description |
|-------------|------|-------------|
| `cacheClass` | `string` | *Optional* Cache class name. Has to implement `Heise\Shariff\CacheInterface`. Defaults to internal Zend Cache. |
| `cacheClass` | `string` | *Optional* Cache class name. Has to implement `Heise\Shariff\CacheInterface`. Defaults to internal Laminas Cache. |
| `cache` | `object` | File cache settings, which are passed on to the Cache class. See description below. |
| `domains` | `array` | Domains for which share counts may be requested. If empty, all domains are allowed. |
| `services` | `array` | List of services to be enabled. See [Supported services](#supported-services). |

##### Cache settings:

By default Shariff uses the Filesystem cache. By specifying a different adapter from Zend\Cache\Storage\Adapter you can tell Shariff to use another cache. Also you can specify options for that cache adapter
By default Shariff uses the Filesystem cache. By specifying a different adapter from Laminas\Cache\Storage\Adapter you can tell Shariff to use another cache. Also you can specify options for that cache adapter

| Key | Type | Description |
|-------------|------|-------------|
Expand All @@ -57,7 +57,7 @@ By default Shariff uses the Filesystem cache. By specifying a different adapter
| `adapter` | `string` | Name of cache adapter (e.g. Apc, Memcache, etc.) |
| `adapterOptions` | `object` | Options for the cache adapter |

*These option apply for the default Cache class (`ZendCache`) only. If you implement custom caching, you can specify your own options.*
*These option apply for the default Cache class (`LaminasCache`) only. If you implement custom caching, you can specify your own options.*

##### Client options

Expand Down Expand Up @@ -88,13 +88,14 @@ To use the graph api id method to fetch the share count you need to set up an ap
##### Full config example

```php
use Heise\Shariff\LaminasCache;
/**
* Sample configuration
*
* @var array
*/
private static $configuration = [
'cacheClass' => 'Heise\\Shariff\\ZendCache',
'cacheClass' => LaminasCache::class,
'cache' => [
'ttl' => 60,
'cacheDir' => '/tmp/shariff/cache',
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"php": "^7.2",
"guzzlehttp/guzzle": "^6.1",
"psr/log": "^1.0",
"zendframework/zend-cache": "^2.7"
"laminas/laminas-cache": "^2.7"
},
"require-dev": {
"phpunit/phpunit": "^8.5"
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct($config)
if (isset($config['cacheClass'])) {
$cacheClass = $config['cacheClass'];
} else {
$cacheClass = 'Heise\\Shariff\\ZendCache';
$cacheClass = LaminasCache::class;
}
$cache = new $cacheClass($config['cache']);

Expand Down
16 changes: 8 additions & 8 deletions src/ZendCache.php → src/LaminasCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace Heise\Shariff;

use Zend\Cache\Storage\Adapter\FilesystemOptions;
use Zend\Cache\Storage\ClearExpiredInterface;
use Zend\Cache\Storage\StorageInterface;
use Zend\Cache\StorageFactory;
use Laminas\Cache\Storage\Adapter\FilesystemOptions;
use Laminas\Cache\Storage\ClearExpiredInterface;
use Laminas\Cache\Storage\StorageInterface;
use Laminas\Cache\StorageFactory;

/**
* Implement ZendCache.
* Implement LaminasCache.
*/
class ZendCache implements CacheInterface
class LaminasCache implements CacheInterface
{
/**
* @var StorageInterface
Expand All @@ -20,8 +20,8 @@ class ZendCache implements CacheInterface
/**
* @param array $configuration
*
* @throws \Zend\Cache\Exception\InvalidArgumentException
* @throws \Zend\Cache\Exception\RuntimeException
* @throws \Laminas\Cache\Exception\InvalidArgumentException
* @throws \Laminas\Cache\Exception\RuntimeException
*/
public function __construct(array $configuration)
{
Expand Down
14 changes: 9 additions & 5 deletions tests/FacebookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,30 @@

use GuzzleHttp\ClientInterface;
use Heise\Shariff\Backend\Facebook;
use Psr\Http\Message\ResponseInterface;
use PHPUnit\Framework as PHPUnit;

/**
* Class FacebookTest
*/
class FacebookTest extends \PHPUnit\Framework\TestCase
class FacebookTest extends PHPUnit\TestCase
{
public function testConfig()
{
/** @var ClientInterface|\PHPUnit_Framework_MockObject_MockObject $client */
/** @var ClientInterface|PHPUnit\MockObject\MockObject $client */
$client = $this->getMockBuilder(ClientInterface::class)->getMock();

$facebook = new Facebook($client);
$facebook->setConfig(array('app_id' => 'foo', 'secret' => 'bar'));
$facebook->getRequest('http://www.heise.de');
$request = $facebook->getRequest('http://www.heise.de');
$this->assertEquals(
'id='.urlencode('http://www.heise.de').'&fields=engagement&access_token=foo%7Cbar',
$request->getUri()->getQuery()
);
}

public function testUsesGraphApi()
{
/** @var \GuzzleHttp\Client|\PHPUnit_Framework_MockObject_MockObject $client */
/** @var \GuzzleHttp\Client|PHPUnit\MockObject\MockObject $client */
$client = $this->getMockBuilder(ClientInterface::class)->getMock();

$facebook = new Facebook($client);
Expand Down
11 changes: 6 additions & 5 deletions tests/ServiceFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,25 @@
use GuzzleHttp\ClientInterface;
use Heise\Shariff\Backend\ServiceFactory;
use Heise\Shariff\Backend\ServiceInterface;
use PHPUnit\Framework as PHPUnit;

/**
* Class ServiceFactoryTest
*/
class ServiceFactoryTest extends \PHPUnit\Framework\TestCase
class ServiceFactoryTest extends PHPUnit\TestCase
{

public function testSetConfig()
{
/** @var ServiceInterface|\PHPUnit_Framework_MockObject_MockObject $mockService */
/** @var ServiceInterface|PHPUnit\MockObject\MockObject $mockService */
$mockService = $this->getMockBuilder(ServiceInterface::class)->getMock();

$mockService->expects($this->once())
->method('setConfig')
->with(array('foo' => 'bar'))
;

/** @var ClientInterface|\PHPUnit_Framework_MockObject_MockObject $mockClient */
/** @var ClientInterface|PHPUnit\MockObject\MockObject $mockClient */
$mockClient = $this->getMockBuilder(ClientInterface::class)->getMock();

$serviceFactory = new ServiceFactory($mockClient);
Expand All @@ -37,12 +38,12 @@ public function testSetConfig()

public function testConfigNotSet()
{
/** @var ServiceInterface|\PHPUnit_Framework_MockObject_MockObject $mockService */
/** @var ServiceInterface|PHPUnit\MockObject\MockObject $mockService */
$mockService = $this->getMockBuilder(ServiceInterface::class)->getMock();

$mockService->expects($this->never())->method('setConfig');

/** @var ClientInterface|\PHPUnit_Framework_MockObject_MockObject $mockClient */
/** @var ClientInterface|PHPUnit\MockObject\MockObject $mockClient */
$mockClient = $this->getMockBuilder(ClientInterface::class)->getMock();

$serviceFactory = new ServiceFactory($mockClient);
Expand Down
5 changes: 3 additions & 2 deletions tests/ShariffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
namespace Heise\Tests\Shariff;

use Heise\Shariff\Backend;
use Zend\Cache\Exception\OutOfSpaceException;
use Laminas\Cache\Exception\OutOfSpaceException;
use PHPUnit\Framework as PHPUnit;

/**
* Class ShariffTest
*/
class ShariffTest extends \PHPUnit\Framework\TestCase
class ShariffTest extends PHPUnit\TestCase
{
/***
* @var string[]
Expand Down

0 comments on commit e7c1216

Please sign in to comment.