AbstractProxy.test.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> http://www.phpfastcache.com
  4. * @author Georges.L (Geolim4) <contact@geolim4.com>
  5. */
  6. use phpFastCache\Core\Item\ExtendedCacheItemInterface;
  7. use phpFastCache\Helper\TestHelper;
  8. use phpFastCache\Proxy\phpFastCacheAbstractProxy;
  9. chdir(__DIR__);
  10. require_once __DIR__ . '/../vendor/autoload.php';
  11. $testHelper = new TestHelper('phpFastCacheAbstractProxy class');
  12. $defaultDriver = (!empty($argv[1]) ? ucfirst($argv[1]) : 'Files');
  13. /**
  14. * Dynamic driver-based example
  15. * Class myCustomCacheClass
  16. * @package MyCustom\Project
  17. */
  18. class CustomMemcachedCacheClass extends phpFastCacheAbstractProxy
  19. {
  20. public function __construct($driver = '', array $config = [])
  21. {
  22. global $defaultDriver;
  23. $driver = $defaultDriver;
  24. parent::__construct($driver, $config);
  25. /**
  26. * That's all !! Your cache class is ready to use
  27. */
  28. }
  29. }
  30. /**
  31. * Testing memcached as it is declared in .travis.yml
  32. */
  33. $driverInstance = new CustomMemcachedCacheClass();
  34. if (!is_object($driverInstance->getItem('test'))) {
  35. $testHelper->printFailText('$driverInstance->getItem() returned an invalid var type:' . gettype($driverInstance));
  36. }else if(!($driverInstance->getItem('test') instanceof ExtendedCacheItemInterface)){
  37. $testHelper->printFailText('$driverInstance->getItem() returned an invalid class that does not implements ExtendedCacheItemInterface: ' . get_class($driverInstance));
  38. }else{
  39. $testHelper->printPassText('$driverInstance->getItem() returned a valid class that implements ExtendedCacheItemInterface: ' . get_class($driverInstance));
  40. }
  41. $testHelper->terminateTest();