Advertisement
itsabird

Untitled

Nov 11th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. /**
  2. * @dataProvider mockProviderGetParamsValidation
  3. * @param AddressBalance $obj
  4. * @param $mockApiContext
  5. * @param $params
  6. * @expectedException \InvalidArgumentException
  7. */
  8. public function testGetParamsValidationForParams(
  9. $obj, /** @noinspection PhpDocSignatureInspection */
  10. $mockApiContext,
  11. $params
  12. )
  13. {
  14. $mockBlockCypherRestCall = $this->getMockBuilder('\BlockCypher\Transport\BlockCypherRestCall')
  15. ->setMethods(array('getBaseChainUrl'))
  16. ->disableOriginalConstructor()
  17. ->getMock();
  18.  
  19. $mockBlockCypherRestCall->expects($this->any())
  20. ->method('execute')
  21. ->will($this->returnValue(
  22. AddressBalanceTest::getJson()
  23. ));
  24.  
  25. /** @noinspection PhpUndefinedVariableInspection */
  26. /** @noinspection PhpParamsInspection */
  27. $obj->get("1DEP8i3QJCsomS4BSMY2RpU1upv62aGvhD", $params, $mockApiContext, $mockBlockCypherRestCall);
  28. }
  29.  
  30.  
  31. PHPUNit Run..
  32. PHPUnit 8.4.3 by Sebastian Bergmann and contributors.
  33.  
  34.  
  35. Failed asserting that exception of type "PHPUnit\Framework\MockObject\RuntimeException" matches expected exception "\InvalidArgumentException". Message was: "Trying to configure method "execute" which cannot be configured because it does not exist, has not been specified, is final, or is static" at
  36. C:\Users\avion\projects\blockcypher\php-client\tests\BlockCypher\Test\Api\AddressBalanceTest.php:123
  37. .
  38.  
  39.  
  40. Time: 2.0699999999999998 seconds, Memory: 16.00 MB
  41.  
  42.  
  43.  
  44. Interesting enough took a look at the class that is being mocked... execute is this..
  45.  
  46. /**
  47. * @param array $handlers Array of handlers
  48. * @param string $path Resource path relative to base service endpoint
  49. * @param string $method HTTP method - one of GET, POST, PUT, DELETE, PATCH etc
  50. * @param string $data Request payload
  51. * @param array $headers HTTP headers
  52. * @return mixed
  53. * @throws \BlockCypher\Exception\BlockCypherConnectionException
  54. */
  55. public function execute($handlers = array(), $path, $method, $data = '', $headers = array())
  56. {
  57. $config = $this->apiContext->getConfig();
  58. $httpConfig = new BlockCypherHttpConfig(null, $method, $config);
  59. $headers = $headers ? $headers : array();
  60. $httpConfig->setHeaders($headers +
  61. array(
  62. 'Content-Type' => 'application/json'
  63. )
  64. );
  65.  
  66. /** @var \BlockCypher\Handler\IBlockCypherHandler $handler */
  67. foreach ($handlers as $handler) {
  68. if (!is_object($handler)) {
  69. $fullHandler = "\\" . (string)$handler;
  70. $handler = new $fullHandler($this->apiContext);
  71. }
  72. $handler->handle($httpConfig, $data, array('path' => $path, 'apiContext' => $this->apiContext));
  73. }
  74.  
  75. $connection = new BlockCypherHttpConnection($httpConfig, $config);
  76. $response = $connection->execute($data);
  77.  
  78. return $response;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement