/**
  * Mock Watson Bridge.
  */
 public function mockBridge()
 {
     $this->bridge = $this->getMockBuilder(Bridge::class)->disableOriginalConstructor()->setMethods(['post'])->getMock();
     $this->bridge->expects($this->any())->method('post')->with($this->equalTo('v1/dilemmas?generate_visualization=true'), $this->anything())->willReturn(new Response(200, ['X-Foo' => 'Bar'], $this->getResolutionResponseBody()));
     //Override bridge in IOC
     $this->app->instance('TradeoffAnalyticsBridge', $this->bridge);
 }
 /**
  * Setup Test.
  */
 public function setUp()
 {
     parent::setUp();
     // Mock Watson Bridge
     $this->bridge = $this->getMockBuilder('FindBrok\\WatsonBridge\\Bridge')->disableOriginalConstructor()->setMethods(['post'])->getMock();
     // Mock Contents
     $this->contentItems = json_decode(file_get_contents(__DIR__ . '/Mocks/content-items.json'), true)['contentItems'];
     // Mock Response Body
     $this->jsonResponse = file_get_contents(__DIR__ . '/Mocks/profile-response.json');
     // Set return value of post method
     $this->bridge->method('post')->withAnyParameters()->willReturn(new Response(200, [], $this->jsonResponse));
     // Override Bridge in IOC
     $this->app->instance('PersonalityInsightsBridge', $this->bridge);
 }
 /**
  * Test the bulkTranslate method throws WatsonBridgeException.
  *
  * @expectedException \FindBrok\WatsonBridge\Exceptions\WatsonBridgeException
  */
 public function testBulkTranslate_WithGetTranslation_ThrowsClientException_ReturnsNull()
 {
     //Set return value of post method
     $this->bridge->method('post')->withAnyParameters()->will($this->throwException(new \FindBrok\WatsonBridge\Exceptions\WatsonBridgeException('Foo', 400)));
     //Override Bridge in IOC
     $this->app->instance('WatsonTranslateBridge', $this->bridge);
     $this->translator->bulkTranslate(['lorem', 'nam'])->getTranslation();
 }
예제 #4
0
 /**
  * Test that we can set and reset the client correctly.
  *
  * @return void
  */
 public function testSetClientMethodClientCorrectlySet()
 {
     $bridge = new Bridge('username', 'password', 'https://gateway.watsonplatform.net/service/api/');
     $this->assertInstanceOf(Client::class, $bridge->getClient());
     $client = new Client(['base_uri' => 'https://gateway.watsonplatform.net/service/api/']);
     $this->assertEquals($client->getConfig('base_uri'), $bridge->getClient()->getConfig('base_uri'));
     $bridge->setClient($bridge->getAuthorizationEndpoint());
     $this->assertNotEquals($client->getConfig('base_uri'), $bridge->getClient()->getConfig('base_uri'));
 }