-
-
Notifications
You must be signed in to change notification settings - Fork 453
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved extension mechanism performances
- Loading branch information
Showing
8 changed files
with
222 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
lib/Phpfastcache/Exceptions/PhpfastcacheExtensionNotInstalledException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
/** | ||
* | ||
* This file is part of Phpfastcache. | ||
* | ||
* @license MIT License (MIT) | ||
* | ||
* For full copyright and license information, please see the docs/CREDITS.txt and LICENCE files. | ||
* | ||
* @author Georges.L (Geolim4) <[email protected]> | ||
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Phpfastcache\Exceptions; | ||
|
||
class PhpfastcacheExtensionNotInstalledException extends PhpfastcacheDriverNotFoundException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
/** | ||
* | ||
* This file is part of Phpfastcache. | ||
* | ||
* @license MIT License (MIT) | ||
* | ||
* For full copyright and license information, please see the docs/CREDITS.txt and LICENCE files. | ||
* | ||
* @author Georges.L (Geolim4) <[email protected]> | ||
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors | ||
*/ | ||
|
||
use Phpfastcache\CacheManager; | ||
use Phpfastcache\Exceptions\PhpfastcacheDriverNotFoundException; | ||
use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException; | ||
use Phpfastcache\Exceptions\PhpfastcacheExtensionNotInstalledException; | ||
use Phpfastcache\Tests\Helper\TestHelper; | ||
|
||
chdir(__DIR__); | ||
require_once __DIR__ . '/../../vendor/autoload.php'; | ||
require_once __DIR__ . '/../mock/Autoload.php'; | ||
$testHelper = new TestHelper('Apcu test (CRUD)'); | ||
|
||
try { | ||
$pool = CacheManager::getInstance('Arangodb'); | ||
$testHelper->assertFail('CacheManager didnt thrown an Exception'); | ||
} catch (PhpfastcacheExtensionNotInstalledException) { | ||
$testHelper->assertPass('CacheManager thrown a PhpfastcacheExtensionNotInstalledException.'); | ||
} catch (\Throwable $e) { | ||
$testHelper->assertFail('CacheManager thrown a ' . $e::class); | ||
} | ||
|
||
try { | ||
$pool = CacheManager::getInstance(bin2hex(random_bytes(8))); | ||
$testHelper->assertFail('CacheManager didnt thrown an Exception'); | ||
} catch (PhpfastcacheDriverNotFoundException $e) { | ||
if ($e::class === PhpfastcacheDriverNotFoundException::class) { | ||
$testHelper->assertPass('CacheManager thrown a PhpfastcacheDriverNotFoundException.'); | ||
} else { | ||
$testHelper->assertFail('CacheManager thrown a ' . $e::class); | ||
} | ||
} catch (\Throwable $e) { | ||
$testHelper->assertFail('CacheManager thrown a ' . $e::class); | ||
} | ||
|
||
try { | ||
\Phpfastcache\ExtensionManager::registerExtension( | ||
'Extensiontest', | ||
\Phpfastcache\Extensions\Drivers\Extensiontest\Driver::class | ||
); | ||
$testHelper->assertPass('Registered a test extension.'); | ||
} catch (PhpfastcacheInvalidArgumentException) { | ||
$testHelper->assertFail('Failed to register a test extension.'); | ||
} | ||
|
||
try { | ||
CacheManager::getInstance('Extensiontest'); | ||
$testHelper->assertPass('Retrieved a test extension cache pool.'); | ||
} catch (PhpfastcacheDriverNotFoundException) { | ||
$testHelper->assertFail('Failed to retrieve a test extension cache pool.'); | ||
} | ||
|
||
|
||
$testHelper->terminateTest(); |
42 changes: 42 additions & 0 deletions
42
tests/mock/Phpfastcache/Extensions/Drivers/Extensiontest/Config.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* | ||
* This file is part of Phpfastcache. | ||
* | ||
* @license MIT License (MIT) | ||
* | ||
* For full copyright and license information, please see the docs/CREDITS.txt and LICENCE files. | ||
* | ||
* @author Georges.L (Geolim4) <[email protected]> | ||
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors | ||
*/ | ||
|
||
namespace Phpfastcache\Extensions\Drivers\Extensiontest; | ||
|
||
use Phpfastcache\Drivers\Files\Config as FilesConfig; | ||
|
||
class Config extends FilesConfig | ||
{ | ||
/** | ||
* @var bool | ||
*/ | ||
protected bool $customOption = true; | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isCustomOption(): bool | ||
{ | ||
return $this->customOption; | ||
} | ||
|
||
/** | ||
* @param bool $customOption | ||
* @return Config | ||
*/ | ||
public function setCustomOption(bool $customOption): Config | ||
{ | ||
$this->customOption = $customOption; | ||
return $this; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
tests/mock/Phpfastcache/Extensions/Drivers/Extensiontest/Driver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
/** | ||
* | ||
* This file is part of Phpfastcache. | ||
* | ||
* @license MIT License (MIT) | ||
* | ||
* For full copyright and license information, please see the docs/CREDITS.txt and LICENCE files. | ||
* | ||
* @author Georges.L (Geolim4) <[email protected]> | ||
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors | ||
*/ | ||
|
||
namespace Phpfastcache\Extensions\Drivers\Extensiontest; | ||
|
||
use Phpfastcache\Drivers\Files\Driver as FilesDriver; | ||
|
||
class Driver extends FilesDriver | ||
{ | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
tests/mock/Phpfastcache/Extensions/Drivers/Extensiontest/Item.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
/** | ||
* | ||
* This file is part of Phpfastcache. | ||
* | ||
* @license MIT License (MIT) | ||
* | ||
* For full copyright and license information, please see the docs/CREDITS.txt and LICENCE files. | ||
* | ||
* @author Georges.L (Geolim4) <[email protected]> | ||
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors | ||
*/ | ||
|
||
namespace Phpfastcache\Extensions\Drivers\Extensiontest; | ||
|
||
use Phpfastcache\Drivers\Files\Item as FilesItem; | ||
|
||
|
||
class Item extends FilesItem | ||
{ | ||
|
||
} |