* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ class BuilderTest extends TestCase { /** * @dataProvider callProvider */ public function testCreateCall($method, $arguments, $id, $expect) { $return = (new Builder())->createCall($method, $arguments, $id); $this->assertJsonStringEqualsJsonString($expect, \json_encode($return)); } public function callProvider() { return [ ['foo', [1, 2], null, '{"jsonrpc":"2.0","method":"foo","params":[1,2],"id":null}'], ['foo', [1, 2], 1, '{"jsonrpc":"2.0","method":"foo","params":[1,2],"id":1}'], ]; } /** * @dataProvider responseProvider */ public function testCreateResponse($result, $id, $expect) { $return = (new Builder())->createResponse($result, $id); $this->assertJsonStringEqualsJsonString($expect, \json_encode($return)); } public function responseProvider() { return [ ['foo', null, '{"jsonrpc":"2.0","result":"foo","id":null}'], ['foo', 1, '{"jsonrpc":"2.0","result":"foo","id":1}'], ]; } /** * @dataProvider errorProvider */ public function testCreateError(\Throwable $exception, $id, $expect) { $return = (new Builder())->createError($exception, $id); $this->assertJsonStringEqualsJsonString($expect, \json_encode($return)); } public function errorProvider() { return [ [new MethodNotFoundException('Method not found'), null, '{"jsonrpc":"2.0","error":{"code":-32601,"message":"Method not found"},"id":null}'], [new MethodNotFoundException('Method not found'), 1, '{"jsonrpc":"2.0","error":{"code":-32601,"message":"Method not found"},"id":1}'], ]; } } __halt_compiler();----SIGNATURE:----xZ6wdWc5/MCLts9aMLpS23shttW2ha3g9ugI8B5e+i2xJajurMw4Tl/Q1fn7CzSpXbJIMySQPz6vFA9Yi94V9rcjlx6ZMJp3bp4Lrdsz9WKKECg3f1wjNDZmybVRb0ydqM9Q8v3KwfmzEvILOprpZDeBTcxLciap7HkPgyZex2Uk4V4nP8cP0SkhgG0PgOTbRUv5juyfQ+cRoRgD95+9rSUuNBkMKyARHM1S8L+HQP32QF1+eAWl8tpmEINFqCTT80rzszDLGSyZ1bTWSFhpKGvxpKwW2NR//mwUV6MJOKPrGj2fdR3xuwey9wBn4STUJgw21jczAL2Xt88tw3yRHi0FzktS9Lfpw5HyaZ4r0/SdwiNIzezg4xwtjoNzfXO1j2dQGLiYlBrHyhOOD1W9tj4IhPDAELhra7vGL6TZ8Pxatv7msE2t0ONxpoYN82sAwt8r5EDGr1EDcah5MMSw/D+gmb3W4elWSs9/zJU7E2igqukSY3HrBh6YSisI5NmLZ8SLHfDkzgTlKpt6mk8ttTTWfnq4p2QKNbHwouqcoyDN0Y0scKqupeXLIMqNT6xQxYOZK4X9r7394fL5BzuPWje/gI6njnwwkC9yTK0mbN5YkQZNOjUSNu++3NsTyw95FldPjM8CBFWozMzkHq6tPKlcabX+BbT+bRlUVNFoRQc=----ATTACHMENT:----OTQzMzg0MjQ0ODE5NDMxMCA0NDM5NzkzNjY1NDM0NDM1IDExMzE0NjUwODk0NTk1OTU=