/** * @test */ public function itShouldRemoveNullValues() { $array = [0 => 'foo', 1 => 'bar', 2 => null, 3 => [0 => 'foo', 1 => null, 2 => 'bar', 3 => []], 4 => null, 5 => [], 6 => ['array' => []], 7 => [[]], 'foo' => null, 'foo' => []]; $expected = [0 => 'foo', 1 => 'bar', 3 => [0 => 'foo', 2 => 'bar']]; $this->assertEquals($expected, ArrayFunctions::withoutNullValues($array)); }
/** * @test */ public function itShouldCreateAnIdealOrder() { $order = Order::create(1234, 'EUR', 'ideal', ['issuer_id' => 'ABNANL2A'], 'A nice description', 'my-order-id', 'http://www.example.com', 'PT10M'); $this->httpClient->shouldReceive('post')->once()->with('orders/', m::on(function (array $options) use($order) { $this->assertEquals(3, $options['timeout']); $this->assertEquals('application/json', $options['headers']['Content-Type']); $this->assertEquals(ArrayFunctions::withoutNullValues($order->toArray()), json_decode($options['body'], true)); return true; }))->andReturn($this->httpResponse); $this->httpResponse->shouldReceive('json')->once()->andReturn(ArrayFunctions::withoutNullValues($order->toArray())); $this->assertInstanceOf('GingerPayments\\Payment\\Order', $this->client->createIdealOrder(1234, 'EUR', 'ABNANL2A', 'A nice description', 'my-order-id', 'http://www.example.com', 'PT10M')); }
/** * Post a new order. * * @param Order $order * @return Order */ private function postOrder(Order $order) { try { $response = $this->httpClient->post('orders/', ['timeout' => 3, 'headers' => ['Content-Type' => 'application/json'], 'body' => json_encode(ArrayFunctions::withoutNullValues($order->toArray()))]); } catch (RequestException $exception) { throw new ClientException('An error occurred while posting the order: ' . $exception->getMessage(), $exception->getCode(), $exception); } return Order::fromArray($response->json()); }