function it_calls_first_converter_in_chain_calls(ConverterInterface $first, ConverterInterface $second, ConverterInterface $third) { $first->convert('some_specific_value')->willReturn(false)->shouldBeCalled(); $second->convert('some_specific_value')->willReturn('expected_result')->shouldBeCalled(); $third->convert(Argument::any())->shouldNotBeCalled(); $this->beConstructedWith([$first, $second, $third]); $this->convert('some_specific_value')->shouldReturn('expected_result'); }
/** * Converts value into string for cache key * * In case if value is not convertible, it should return false * * @param mixed $value * * @return string|bool */ public function convert($value) { if (!is_array($value)) { return false; } if (empty($value)) { return false; } $result = ''; foreach ($value as $key => $item) { if (!is_scalar($item)) { return false; } if (empty($key) && !is_int($key) && empty($item) && !is_int($item)) { return false; } $result .= $this->converter->convert($key) . '_' . $this->converter->convert($item) . '_'; } return rtrim($result, '_'); }