/** * @param \Mattsches\VersionEyeBundle\Client\VersionEyeClient $client * @param string $apiKey * @param \Doctrine\Common\Cache\Cache $cache */ public function __construct(VersionEyeClient $client, $apiKey, Cache $cache = null) { $this->client = $client; if ($cache !== null) { $adapter = new DoctrineCacheAdapter($cache); $options = array('adapter' => $adapter, 'can_cache' => new CallbackCanCacheStrategy(function () { return true; }, function () { return true; })); $cachePlugin = new CachePlugin($options); $this->client->addSubscriber($cachePlugin); } $this->apiKey = $apiKey; }
/** * Setup */ public function setUp() { $plugin = new MockPlugin(); $response = new GuzzleResponse(200); $response->setBody(file_get_contents(__DIR__ . '/Fixtures/response_projects.json')); $plugin->addResponse($response); $client = new VersionEyeClient('foo'); $client->addSubscriber($plugin); $this->object = new VersionEyeApi($client, 'foo'); }
/** * @test */ public function testCollectOffline() { $plugin = new MockPlugin(); $plugin->addResponse($this->getFixtureResponse('response.json', 404)); $client = new VersionEyeClient('foo'); $client->addSubscriber($plugin); $api = new VersionEyeApi($client, 'api_key'); $loader = new ComposerLoader(__DIR__ . '/Fixtures/composer.json'); $this->object = new VersionEyeDataCollector($api, $loader); $this->object->collect(new Request(), new Response()); /* @var VersionEyeResult $data */ $data = $this->object->getData(); $this->assertInstanceOf('Mattsches\\VersionEyeBundle\\Util\\VersionEyeResult', $data); $this->assertSame('version_eye', $this->object->getName()); $this->assertObjectHasAttribute('dependencies', $data); $this->assertObjectHasAttribute('status', $data); $this->assertObjectHasAttribute('outNumber', $data); $this->assertObjectHasAttribute('depNumber', $data); $this->assertObjectNotHasAttribute('foobar', $data); $this->assertEquals(0, $data->getStatus()); $this->assertNull($data->getDepNumber()); $this->assertNull($data->getOutNumber()); }