Ejemplo n.º 1
0
 /**
  * @test
  */
 public function parse_passes_identifier_from_specialized_parser()
 {
     $value = 'VALUE';
     $expectedIdentifier = 'IDENTIFIER';
     $specializedParser = $this->getMock(ParserInterface::class);
     $specializedParser->expects($this->once())->method('parse')->with($value)->willReturn($expectedIdentifier);
     $parser = new Parser([$specializedParser]);
     $identifier = $parser->parse($value);
     $this->assertEquals($expectedIdentifier, $identifier);
 }
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);
    }
}