/** * @test */ public function convert_passes_identifier_from_specialized_converter() { $value = 'VALUE'; $identifier = new Ean13($value); $expectedIdentifier = new Ean8($value); $specializedConverter = $this->getMock(ConverterInterface::class); $specializedConverter->expects($this->once())->method('convert')->with($identifier)->willReturn($expectedIdentifier); $converter = new Converter([Ean13::class => [$specializedConverter]]); $convertedIdentifier = $converter->convert($identifier); $this->assertEquals($expectedIdentifier, $convertedIdentifier); }
function compareIdentifiers($value1, $value2) { $parser = new Parser(); $converter = new Converter(); try { $identifier1 = $parser->parse($value1); $identifier2 = $parser->parse($value2); $identifiersAreEqual = $identifier1->equals($identifier2); try { $conversion = $converter->convert($identifier1); $identifiersAreConvertible = $conversion->equals($identifier2); } catch (ConversionException $exception) { $identifiersAreConvertible = false; } if ($identifiersAreEqual || $identifiersAreConvertible) { printf('Identifiers "%s" and "%s" refer to the same product' . PHP_EOL, $identifier1, $identifier2); } else { printf('Identifiers "%s" and "%s" refer to different products' . PHP_EOL, $identifier1, $identifier2); } } catch (ParseException $e) { printf($e->getMessage() . PHP_EOL); } }