/** * @covers \PHP\Manipulator\Helper\SetWhitespaceAfterToken::getWhitespaceForToken * @covers \Exception */ public function testNonExistingTokenInWhitespaceListThrowsExceptionInGetWhitespaceForToken() { $container = new TokenContainer("<?php echo 'hellow world'; ?>"); $tokens = array($container[2], $container[3]); $whitespace = array(T_ECHO => 'blub'); $manipulator = new SetWhitespaceAfterToken(); try { $manipulator->run($container, $tokens, $whitespace); $this->fail('Expected exception not thrown'); } catch (\Exception $e) { $this->assertEquals('No option found for: T_WHITESPACE (' . T_WHITESPACE . ')', $e->getMessage(), 'Wrong exception message'); } }
/** * @param \PHP\Manipulator\TokenContainer $container * @param mixed $params */ public function run(TokenContainer $container) { $iterator = $container->getIterator(); $operatorTokens = array(); while ($iterator->valid()) { $token = $iterator->current(); if ($this->evaluateConstraint('IsOperator', $token)) { $operatorTokens[] = $token; } $iterator->next(); } $setWhitespaceAfterToken = new SetWhitespaceAfterToken(); $setWhitespaceAfterToken->run($container, $operatorTokens, $this->getOption('afterOperator')); $setWhitespaceBeforeToken = new SetWhitespaceBeforeToken(); $setWhitespaceBeforeToken->run($container, $operatorTokens, $this->getOption('beforeOperator')); }