/** * Compare Containers * * Returns string-presentation of both containers next to each other * * @param \PHP\Manipulator\TokenContainer $expected * @param \PHP\Manipulator\TokenContainer $secod */ public static function compareContainers(TokenContainer $expectedContainer, TokenContainer $actualContainer, $strict) { $expectedIterator = new \ArrayIterator($expectedContainer->toArray()); $actualIterator = new \ArrayIterator($actualContainer->toArray()); $values = array(); $longest = 0; while ($actualIterator->valid() || $expectedIterator->valid()) { $expected = ''; $actual = ''; $missmatch = true; if ($expectedIterator->valid()) { $expected = (string) self::dumpToken($expectedIterator->current(), false); } if ($actualIterator->valid()) { $actual = (string) self::dumpToken($actualIterator->current(), false); } if ($actualIterator->valid() && $expectedIterator->valid()) { $constraint = new TokensMatchConstraint($expectedIterator->current(), $strict); $missmatch = !$constraint->evaluate($actualIterator->current(), '', true); } $values[] = array('actual' => $actual, 'expected' => $expected, 'missmatch' => $missmatch); if (strlen($actual) > $longest) { $longest = strlen($actual); } if (strlen($expected) > $longest) { $longest = strlen($expected); } $expectedIterator->next(); $actualIterator->next(); } $comparision = ' '; $comparision .= str_pad('Tokens: ' . count($expectedContainer), $longest + 2, ' ', STR_PAD_BOTH); $comparision .= ' | '; $comparision .= str_pad('Tokens: ' . count($actualContainer), $longest + 2, ' ', STR_PAD_BOTH); $comparision .= PHP_EOL; $comparision .= PHP_EOL; $i = 0; foreach ($values as $val) { if (true === $val['missmatch']) { $comparision .= '####### NEXT IS DIFFERENT ## ' . PHP_EOL; } $comparision .= str_pad($i . ') ', 4, ' '); $comparision .= str_pad($val['expected'], $longest + 2, ' '); $comparision .= ' | '; $comparision .= str_pad($val['actual'], $longest + 2, ' '); $comparision .= PHP_EOL; $i++; } $comparision = rtrim($comparision); return $comparision; }
/** * @covers \Tests\Constraint\TokensMatch::failureDescription */ public function testFailAndFailureDescriptionWithDifferentLinenumbers() { $expected = new Token('blub', null, '5'); $other = new Token('blub', null, '4'); $tokenMatch = new TokensMatch($expected, true); $message = PHP_EOL . \PHPUnit_Util_Diff::diff((string) $expected, (string) $other); $message = 'Failed asserting that Tokens are different: [linenumber]' . $message . '.'; try { $tokenMatch->evaluate($other); $this->fail('no exception thrown'); } catch (\PHPUnit_Framework_ExpectationFailedException $e) { $this->assertEquals($message, $e->getMessage()); } }