diff --git a/code/Workable.php b/code/Workable.php index 9a89bc5..c820449 100644 --- a/code/Workable.php +++ b/code/Workable.php @@ -173,7 +173,7 @@ public function callHttpClient(string $url, array $params = [], string $method = */ public static function flush() { - static::singleton()->getCache()->clear(); + Injector::inst()->get(CacheInterface::class . '.workable')->clear(); } /** diff --git a/code/WorkableResult.php b/code/WorkableResult.php index 84e6e5c..2b7bd04 100644 --- a/code/WorkableResult.php +++ b/code/WorkableResult.php @@ -28,7 +28,7 @@ public function __get($prop) $data = $this->apiData[$snaked] ?? null; - if (is_array($this->apiData[$snaked])) { + if (is_array($data)) { return new WorkableResult($data); } diff --git a/tests/TestWorkableRestfulService.php b/tests/TestWorkableRestfulService.php index 7967265..a50a243 100644 --- a/tests/TestWorkableRestfulService.php +++ b/tests/TestWorkableRestfulService.php @@ -2,11 +2,12 @@ namespace SilverStripe\Workable\Tests; +use GuzzleHttp\Client; use GuzzleHttp\Psr7\Response; -class TestWorkableRestfulService +class TestWorkableRestfulService extends Client { - public function request($method, $url, $params = []) + public function request($method, $url = '', $params = []) { switch ($url) { case 'jobs': diff --git a/tests/WorkableTest.php b/tests/WorkableTest.php index 7124e6d..2127ed0 100644 --- a/tests/WorkableTest.php +++ b/tests/WorkableTest.php @@ -2,26 +2,37 @@ namespace SilverStripe\Workable\Tests; +use GuzzleHttp\ClientInterface; use Psr\Log\LoggerInterface; +use Psr\SimpleCache\CacheInterface; +use SilverStripe\Config\Collections\CachedConfigCollection; +use SilverStripe\Core\Cache\DefaultCacheFactory; use SilverStripe\Core\Environment; +use SilverStripe\Core\Injector\InjectorLoader; use SilverStripe\Dev\SapphireTest; +use SilverStripe\Versioned\Caching\VersionedCacheAdapter; +use SilverStripe\Workable\Tests\TestWorkableRestfulService; use SilverStripe\Workable\Workable; use SilverStripe\Core\Config\Config; use SilverStripe\Core\Injector\Injector; +use SilverStripe\Workable\WorkableRestfulServiceFactory; use SilverStripe\Workable\WorkableResult; -use SilverStripe\Workable\Tests\TestWorkableRestfulService; class WorkableTest extends SapphireTest { - public function setUp() + public static function setUpBeforeClass() { - parent::setUp(); - $config = Config::inst()->get(Injector::class, 'WorkableRestfulService'); + parent::setUpBeforeClass(); + Workable::config()->set('subdomain', 'example'); + $config = Config::inst()->get(Injector::class, 'GuzzleHttp\ClientInterface.workable'); $config['class'] = TestWorkableRestfulService::class; - Config::inst()->update(Injector::class, 'WorkableRestfulService', $config); + Config::inst()->merge(Injector::class, 'GuzzleHttp\ClientInterface.workable', $config); + } + protected function setUp() + { + parent::setUp(); Environment::setEnv('WORKABLE_API_KEY', 'test'); - Config::inst()->update(Workable::class, 'subdomain', 'example'); } public function testThrowsIfNoSubdomain() @@ -29,7 +40,7 @@ public function testThrowsIfNoSubdomain() Config::inst()->remove(Workable::class, 'subdomain'); $this->setExpectedException('RuntimeException'); - Workable::create()->callRestfulService('test'); + Workable::create()->callHttpClient('test'); } public function testThrowsIfNoApiKey() @@ -37,7 +48,7 @@ public function testThrowsIfNoApiKey() Environment::setEnv('WORKABLE_API_KEY', null); $this->setExpectedException('RuntimeException'); - Workable::create()->callRestfulService('test'); + Workable::create()->callHttpClient('test'); } public function testConvertsSnakeCase()