/** * Test all getters for the values set with the constructor. */ public function testConstructorAccessors() { $ifCode = mt_rand(1, 100); $elseCode = mt_rand(1, 100); $precedence = mt_rand(1, 100); $allowShorthand = mt_rand(0, 1); $closure = function () { }; $operator = new TernaryOperator($ifCode, $elseCode, $precedence, TernaryOperator::LEFT, $allowShorthand, $closure); $this->assertSame($ifCode, $operator->getIfCode()); $this->assertSame($elseCode, $operator->getElseCode()); $this->assertSame($precedence, $operator->getPrecedence()); $this->assertSame($allowShorthand, $operator->isShorthandAllowed()); $this->assertSame($closure, $operator->getNode()); }
/** * Test if the `isTernary` method returns true if the given token is the `else` token of a ternary operator. */ public function testIsTernaryReturnsTrueForElseToken() { $operator = new TernaryOperator(1, 2, 10, TernaryOperator::RIGHT, true, function () { }); $token = new Token($operator->getIfCode(), ':', 2); $table = new OperatorTable(); $table->addOperator($operator); $this->assertTrue($table->isTernary($token)); }