Skip to content

Commit

Permalink
[#13439] - Added more tests for Cache AdapterFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
niden committed May 5, 2019
1 parent fb32aaa commit 414fcb1
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 5 deletions.
35 changes: 35 additions & 0 deletions tests/unit/Cache/AdapterFactory/ConstructCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);

/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalconphp.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

namespace Phalcon\Test\Unit\Cache\AdapterFactory;

use Phalcon\Cache\AdapterFactory;
use Phalcon\Storage\SerializerFactory;
use UnitTester;

class ConstructCest
{
/**
* Tests Phalcon\Cache\AdapterFactory :: __construct()
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2019-05-04
*/
public function storageAdapterFactoryConstruct(UnitTester $I)
{
$I->wantToTest('Cache\AdapterFactory - __construct()');

$factory = new SerializerFactory();
$service = new AdapterFactory($factory);
$I->assertInstanceOf(AdapterFactory::class, $service);
}
}
49 changes: 49 additions & 0 deletions tests/unit/Cache/AdapterFactory/GetSetHasCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);

/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalconphp.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

namespace Phalcon\Test\Unit\Cache\AdapterFactory;

use Phalcon\Cache\AdapterFactory;
use Phalcon\Storage\SerializerFactory;
use Phalcon\Test\Fixtures\Cache\Adapter\None;
use UnitTester;

class GetSetHasCest
{
/**
* Tests Phalcon\Cache\AdapterFactory :: get()
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2019-05-04
*/
public function storageAdapterFactoryGetSetHas(UnitTester $I)
{
$I->wantToTest('Cache\AdapterFactory - get()/set()/has()');
$I->skipTest('TODO - Check this');
$mappers = ['none' => 'Phalcon\Test\Fixtures\Cache\Adapter\None'];
$factory = new SerializerFactory();
$service = new AdapterFactory($factory, $mappers);

$actual = $service->has('unknown');
$I->assertFalse($actual);

$actual = $service->has('none');
$I->assertTrue($actual);

$actual = $service->has('redis');
$I->assertTrue($actual);

$actual = $service->get('none');
$class = None::class;
$I->assertInstanceOf($class, $actual);
}
}
61 changes: 61 additions & 0 deletions tests/unit/Cache/AdapterFactory/NewInstanceCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
declare(strict_types=1);

/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalconphp.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

namespace Phalcon\Test\Unit\Cache\AdapterFactory;

use Phalcon\Service\Exception;
use Phalcon\Cache\Adapter\Apcu;
use Phalcon\Cache\Adapter\Php;
use Phalcon\Cache\AdapterFactory;
use Phalcon\Storage\SerializerFactory;
use UnitTester;

class NewInstanceCest
{
/**
* Tests Phalcon\Cache\AdapterFactory :: newInstance()
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2019-05-04
*/
public function storageAdapterFactoryNewInstance(UnitTester $I)
{
$I->wantToTest('Cache\AdapterFactory - newInstance()');

$factory = new SerializerFactory();
$service = new AdapterFactory($factory);

$service = $service->newInstance('apcu');
$class = Apcu::class;
$I->assertInstanceOf($class, $service);
}

/**
* Tests Phalcon\Cache\AdapterFactory :: newInstance() - exception
*
* @author Phalcon Team <team@phalconphp.com>
* @since 2019-05-04
*/
public function storageAdapterFactoryNewInstanceException(UnitTester $I)
{
$I->wantToTest('Cache\AdapterFactory - newInstance() - exception');

$I->expectThrowable(
new Exception('The service unknown has not been found in the locator'),
function () {
$factory = new SerializerFactory();
$service = new AdapterFactory($factory);
$service = $service->newInstance('unknown');
}
);
}
}
10 changes: 5 additions & 5 deletions tests/unit/Cache/CacheFactory/NewInstanceCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Phalcon\Test\Unit\Cache\CacheFactory;

use Phalcon\Cache\Adapter\Apcu;
use Phalcon\Cache\AdapterFactory;
use Phalcon\Cache\Cache;
use Phalcon\Cache\CacheFactory;
use Phalcon\Storage\SerializerFactory;
Expand All @@ -31,10 +31,10 @@ public function cacheCacheFactoryNewInstance(UnitTester $I)
{
$I->wantToTest('Cache\CacheFactory - newInstance()');

$serializer = new SerializerFactory();
$apcu = new Apcu($serializer);
$factory = new CacheFactory();
$adapter = $factory->newInstance($apcu);
$serializer = new SerializerFactory();
$adapterFactory = new AdapterFactory($serializer);
$factory = new CacheFactory($adapterFactory);
$adapter = $factory->newInstance('apcu');

$class = Cache::class;
$I->assertInstanceOf($class, $adapter);
Expand Down

0 comments on commit 414fcb1

Please sign in to comment.