Skip to content

Commit

Permalink
[WMS-1703] Base class for adapters tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kamil-iskierka-westwing-pl committed Feb 26, 2019
1 parent e39c991 commit 8306da5
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 60 deletions.
58 changes: 58 additions & 0 deletions tests/Adapter/BaseAdapterTests.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

use Cache\Factory\Config\Adapter\AdapterInterface as Config;
use Cache\Factory\Config\Loader;

abstract class BaseAdapterTests extends PHPUnit_Framework_TestCase
{
/**
* @var string Name of the adapter in the configuration
*/
protected $adapterName;

/**
* @var string Type of the cache pool adapter
*/
protected $adapterType;

/**
* @var string Path to the config file
*/
protected $configFile;

/**
* @var array
*/
protected $config;

/**
* Sets the config file
*/
protected function setUp()
{
if (!isset($this->adapterName)) {
throw new Exception(
sprintf('Provide $adapterName in %s', (new ReflectionClass($this))->getFileName())
);
} elseif (!isset($this->adapterType)) {
throw new Exception(
sprintf('Provide $adapterType in %s', (new ReflectionClass($this))->getFileName())
);
}

$this->configFile = __DIR__ . '/../cache.yml';

$configLoader = new Loader();
$config = $configLoader->load($this->configFile);

$configLoader->setAdapterName($this->adapterType);

$processedConfiguration = $configLoader->process($this->adapterName, $config);
$this->config = $processedConfiguration[Config::INDEX_ADAPTER][$this->adapterName];
}

/**
* Tests creation of the filesystem cache item pool
*/
abstract public function testMake();
}
30 changes: 1 addition & 29 deletions tests/Adapter/FilesystemAdapterTests.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?php

use Cache\Factory\Adapter\Filesystem;
use Cache\Factory\Config\Adapter\AdapterInterface as Config;
use Cache\Factory\Config\Loader;

class FilesystemAdapterTests extends PHPUnit_Framework_TestCase
class FilesystemAdapterTests extends BaseAdapterTests
{
/**
* @var string Name of the adapter in the configuration
Expand All @@ -16,32 +14,6 @@ class FilesystemAdapterTests extends PHPUnit_Framework_TestCase
*/
protected $adapterType = 'Filesystem';

/**
* @var string Path to the config file
*/
protected $configFile;

/**
* @var array
*/
protected $config;

/**
* Sets the config file
*/
protected function setUp()
{
$this->configFile = __DIR__ . '/../cache.yml';

$configLoader = new Loader();
$config = $configLoader->load($this->configFile);

$configLoader->setAdapterName($this->adapterType);

$processedConfiguration = $configLoader->process($this->adapterName, $config);
$this->config = $processedConfiguration[Config::INDEX_ADAPTER][$this->adapterName];
}

/**
* Tests creation of the filesystem cache item pool
*
Expand Down
32 changes: 1 addition & 31 deletions tests/Adapter/PHPArrayAdapterTests.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?php

use Cache\Factory\Adapter\PHPArray;
use Cache\Factory\Config\Adapter\AdapterInterface as Config;
use Cache\Factory\Config\Loader;

class PHPArrayAdapterTests extends PHPUnit_Framework_TestCase
class PHPArrayAdapterTests extends BaseAdapterTests
{
/**
* @var string Name of the adapter in the configuration
Expand All @@ -16,36 +14,8 @@ class PHPArrayAdapterTests extends PHPUnit_Framework_TestCase
*/
protected $adapterType = 'PHPArray';

/**
* @var string Path to the config file
*/
protected $configFile;

/**
* @var array
*/
protected $config;

/**
* Sets the config file
*/
protected function setUp()
{
$this->configFile = __DIR__ . '/../cache.yml';

$configLoader = new Loader();
$config = $configLoader->load($this->configFile);

$configLoader->setAdapterName($this->adapterType);

$processedConfiguration = $configLoader->process($this->adapterName, $config);
$this->config = $processedConfiguration[Config::INDEX_ADAPTER][$this->adapterName];
}

/**
* Tests creation of the filesystem cache item pool
*
* @author Damian Gręda <[email protected]>
*/
public function testMake()
{
Expand Down

0 comments on commit 8306da5

Please sign in to comment.