Skip to content

Commit

Permalink
Merge pull request #3 from andrewandante/feature/ss4
Browse files Browse the repository at this point in the history
Fix tests, revert flush change
  • Loading branch information
scott1702 authored Nov 11, 2020
2 parents afe77cc + 1d41d3a commit 22fefdb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion code/Workable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion code/WorkableResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
5 changes: 3 additions & 2 deletions tests/TestWorkableRestfulService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
27 changes: 19 additions & 8 deletions tests/WorkableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,53 @@

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()
{
Config::inst()->remove(Workable::class, 'subdomain');
$this->setExpectedException('RuntimeException');

Workable::create()->callRestfulService('test');
Workable::create()->callHttpClient('test');
}

public function testThrowsIfNoApiKey()
{
Environment::setEnv('WORKABLE_API_KEY', null);
$this->setExpectedException('RuntimeException');

Workable::create()->callRestfulService('test');
Workable::create()->callHttpClient('test');
}

public function testConvertsSnakeCase()
Expand Down

0 comments on commit 22fefdb

Please sign in to comment.