adam-paterson /
watson-common
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | |||
| 4 | namespace IBM\Watson\Common\Message; |
||
| 5 | |||
| 6 | use IBM\Watson\Tests\TestCase; |
||
| 7 | use Mockery as m; |
||
| 8 | |||
| 9 | class AbstractRequestTest extends TestCase |
||
| 10 | { |
||
| 11 | private $request; |
||
| 12 | |||
| 13 | public function setUp() |
||
| 14 | { |
||
| 15 | $this->request = m::mock('\IBM\Watson\Common\Message\AbstractRequest')->makePartial(); |
||
| 16 | $this->request->initialize(); |
||
| 17 | } |
||
| 18 | |||
| 19 | public function testConstruct() |
||
| 20 | { |
||
| 21 | $this->request = new AbstractRequestTest_MockAbstractRequest($this->getHttpClient(), $this->getHttpRequest()); |
||
| 22 | $this->assertSame([], $this->request->getParameters()); |
||
| 23 | } |
||
| 24 | |||
| 25 | public function testInitializeWithParams() |
||
| 26 | { |
||
| 27 | $this->assertSame($this->request, $this->request->initialize(['username' => 'adam', 'password' => '01234'])); |
||
|
0 ignored issues
–
show
|
|||
| 28 | $this->assertSame('adam', $this->request->getUsername()); |
||
|
0 ignored issues
–
show
The method
getUsername does only exist in IBM\Watson\Common\Messag...est_MockAbstractRequest, but not in Mockery\Mock.
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
Loading history...
|
|||
| 29 | $this->assertSame('01234', $this->request->getPassword()); |
||
|
0 ignored issues
–
show
The method
getPassword does only exist in IBM\Watson\Common\Messag...est_MockAbstractRequest, but not in Mockery\Mock.
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
Loading history...
|
|||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @expectedException \IBM\Watson\Common\Exception\RuntimeException |
||
| 34 | * @expectedExceptionMessage Request cannot be modified after it has been sent! |
||
| 35 | */ |
||
| 36 | public function testInitializeAfterRequestSent() |
||
| 37 | { |
||
| 38 | $this->request = new AbstractRequestTest_MockAbstractRequest($this->getHttpClient(), $this->getHttpRequest()); |
||
| 39 | $this->request->send(); |
||
| 40 | |||
| 41 | $this->request->initialize(); |
||
| 42 | } |
||
| 43 | |||
| 44 | public function testUsername() |
||
| 45 | { |
||
| 46 | $this->assertSame($this->request, $this->request->setUsername('adam')); |
||
|
0 ignored issues
–
show
The method
setUsername does only exist in IBM\Watson\Common\Messag...est_MockAbstractRequest, but not in Mockery\Mock.
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
Loading history...
|
|||
| 47 | $this->assertSame('adam', $this->request->getUsername()); |
||
|
0 ignored issues
–
show
The method
getUsername does only exist in IBM\Watson\Common\Messag...est_MockAbstractRequest, but not in Mockery\Mock.
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
Loading history...
|
|||
| 48 | } |
||
| 49 | |||
| 50 | public function testPassword() |
||
| 51 | { |
||
| 52 | $this->assertSame($this->request, $this->request->setPassword('01234')); |
||
|
0 ignored issues
–
show
The method
setPassword does only exist in IBM\Watson\Common\Messag...est_MockAbstractRequest, but not in Mockery\Mock.
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
Loading history...
|
|||
| 53 | $this->assertSame('01234', $this->request->getPassword()); |
||
|
0 ignored issues
–
show
The method
getPassword does only exist in IBM\Watson\Common\Messag...est_MockAbstractRequest, but not in Mockery\Mock.
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
Loading history...
|
|||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @expectedException \IBM\Watson\Common\Exception\RuntimeException |
||
| 58 | * @expectedExceptionMessage Request cannot be modified after it has been sent! |
||
| 59 | */ |
||
| 60 | public function testSetParameterAfterRequestSent() |
||
| 61 | { |
||
| 62 | $this->request = new AbstractRequestTest_MockAbstractRequest($this->getHttpClient(), $this->getHttpRequest()); |
||
| 63 | $this->request->send(); |
||
| 64 | |||
| 65 | $this->request->setUsername('adam'); |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @expectedException \IBM\Watson\Common\Exception\RuntimeException |
||
| 70 | * @expectedExceptionMessage You must call send() before accessing the response! |
||
| 71 | */ |
||
| 72 | public function testGetResponseBeforeRequestSent() |
||
| 73 | { |
||
| 74 | $this->request = new AbstractRequestTest_MockAbstractRequest($this->getHttpClient(), $this->getHttpRequest()); |
||
| 75 | $this->request->getResponse(); |
||
| 76 | } |
||
| 77 | |||
| 78 | public function testGetResponseAfterRequestSent() |
||
| 79 | { |
||
| 80 | $this->request = new AbstractRequestTest_MockAbstractRequest($this->getHttpClient(), $this->getHttpRequest()); |
||
| 81 | $this->request->send(); |
||
| 82 | |||
| 83 | $response = $this->request->getResponse(); |
||
| 84 | $this->assertInstanceOf('\IBM\Watson\Common\Message\ResponseInterface', $response); |
||
| 85 | } |
||
| 86 | |||
| 87 | public function testSend() |
||
| 88 | { |
||
| 89 | $response = m::mock('\IBM\Watson\Common\Message\ResponseInterface'); |
||
| 90 | $data = array('request data'); |
||
| 91 | |||
| 92 | $this->request->shouldReceive('getData')->once()->andReturn($data); |
||
| 93 | $this->request->shouldReceive('sendData')->once()->with($data)->andReturn($response); |
||
| 94 | |||
| 95 | $this->assertSame($response, $this->request->send()); |
||
|
0 ignored issues
–
show
The method
send does only exist in IBM\Watson\Common\Messag...est_MockAbstractRequest, but not in Mockery\Mock.
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
Loading history...
|
|||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | // @codingStandardsIgnoreStart |
||
| 100 | class AbstractRequestTest_MockAbstractRequest extends AbstractRequest |
||
| 101 | { |
||
| 102 | public function getData() |
||
| 103 | { |
||
| 104 | } |
||
| 105 | |||
| 106 | public function sendData($data) |
||
| 107 | { |
||
| 108 | $this->response = m::mock('\IBM\Watson\Common\Message\AbstractResponse'); |
||
| 109 | } |
||
| 110 | } |
||
| 111 | // @codingStandardsIgnoreEnd |
||
| 112 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: