Chris@0: createParamBuilder('test') Chris@0: ->setDefault($value) Chris@0: ->getNode() Chris@0: ; Chris@0: Chris@0: $this->assertEquals($expectedValueNode, $node->default); Chris@0: } Chris@0: Chris@0: public function provideTestDefaultValues() { Chris@0: return array( Chris@0: array( Chris@0: null, Chris@0: new Expr\ConstFetch(new Node\Name('null')) Chris@0: ), Chris@0: array( Chris@0: true, Chris@0: new Expr\ConstFetch(new Node\Name('true')) Chris@0: ), Chris@0: array( Chris@0: false, Chris@0: new Expr\ConstFetch(new Node\Name('false')) Chris@0: ), Chris@0: array( Chris@0: 31415, Chris@0: new Scalar\LNumber(31415) Chris@0: ), Chris@0: array( Chris@0: 3.1415, Chris@0: new Scalar\DNumber(3.1415) Chris@0: ), Chris@0: array( Chris@0: 'Hallo World', Chris@0: new Scalar\String_('Hallo World') Chris@0: ), Chris@0: array( Chris@0: array(1, 2, 3), Chris@0: new Expr\Array_(array( Chris@0: new Expr\ArrayItem(new Scalar\LNumber(1)), Chris@0: new Expr\ArrayItem(new Scalar\LNumber(2)), Chris@0: new Expr\ArrayItem(new Scalar\LNumber(3)), Chris@0: )) Chris@0: ), Chris@0: array( Chris@0: array('foo' => 'bar', 'bar' => 'foo'), Chris@0: new Expr\Array_(array( Chris@0: new Expr\ArrayItem( Chris@0: new Scalar\String_('bar'), Chris@0: new Scalar\String_('foo') Chris@0: ), Chris@0: new Expr\ArrayItem( Chris@0: new Scalar\String_('foo'), Chris@0: new Scalar\String_('bar') Chris@0: ), Chris@0: )) Chris@0: ), Chris@0: array( Chris@0: new Scalar\MagicConst\Dir, Chris@0: new Scalar\MagicConst\Dir Chris@0: ) Chris@0: ); Chris@0: } Chris@0: Chris@0: /** Chris@0: * @dataProvider provideTestTypeHints Chris@0: */ Chris@0: public function testTypeHints($typeHint, $expectedType) { Chris@0: $node = $this->createParamBuilder('test') Chris@0: ->setTypeHint($typeHint) Chris@0: ->getNode() Chris@0: ; Chris@0: $type = $node->type; Chris@0: Chris@0: /* Manually implement comparison to avoid __toString stupidity */ Chris@0: if ($expectedType instanceof Node\NullableType) { Chris@0: $this->assertInstanceOf(get_class($expectedType), $type); Chris@0: $expectedType = $expectedType->type; Chris@0: $type = $type->type; Chris@0: } Chris@0: Chris@0: if ($expectedType instanceof Node\Name) { Chris@0: $this->assertInstanceOf(get_class($expectedType), $type); Chris@0: $this->assertEquals($expectedType, $type); Chris@0: } else { Chris@0: $this->assertSame($expectedType, $type); Chris@0: } Chris@0: } Chris@0: Chris@0: public function provideTestTypeHints() { Chris@0: return array( Chris@0: array('array', 'array'), Chris@0: array('callable', 'callable'), Chris@0: array('bool', 'bool'), Chris@0: array('int', 'int'), Chris@0: array('float', 'float'), Chris@0: array('string', 'string'), Chris@0: array('iterable', 'iterable'), Chris@0: array('object', 'object'), Chris@0: array('Array', 'array'), Chris@0: array('CALLABLE', 'callable'), Chris@0: array('Some\Class', new Node\Name('Some\Class')), Chris@0: array('\Foo', new Node\Name\FullyQualified('Foo')), Chris@0: array('self', new Node\Name('self')), Chris@0: array('?array', new Node\NullableType('array')), Chris@0: array('?Some\Class', new Node\NullableType(new Node\Name('Some\Class'))), Chris@0: array(new Node\Name('Some\Class'), new Node\Name('Some\Class')), Chris@0: array(new Node\NullableType('int'), new Node\NullableType('int')), Chris@0: array( Chris@0: new Node\NullableType(new Node\Name('Some\Class')), Chris@0: new Node\NullableType(new Node\Name('Some\Class')) Chris@0: ), Chris@0: ); Chris@0: } Chris@0: Chris@0: /** Chris@0: * @expectedException \LogicException Chris@0: * @expectedExceptionMessage Parameter type cannot be void Chris@0: */ Chris@0: public function testVoidTypeError() { Chris@0: $this->createParamBuilder('test')->setTypeHint('void'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * @expectedException \LogicException Chris@0: * @expectedExceptionMessage Type must be a string, or an instance of Name or NullableType Chris@0: */ Chris@0: public function testInvalidTypeError() { Chris@0: $this->createParamBuilder('test')->setTypeHint(new \stdClass); Chris@0: } Chris@0: Chris@0: public function testByRef() { Chris@0: $node = $this->createParamBuilder('test') Chris@0: ->makeByRef() Chris@0: ->getNode() Chris@0: ; Chris@0: Chris@0: $this->assertEquals( Chris@0: new Node\Param('test', null, null, true), Chris@0: $node Chris@0: ); Chris@0: } Chris@0: Chris@0: public function testVariadic() { Chris@0: $node = $this->createParamBuilder('test') Chris@0: ->makeVariadic() Chris@0: ->getNode() Chris@0: ; Chris@0: Chris@0: $this->assertEquals( Chris@0: new Node\Param('test', null, null, false, true), Chris@0: $node Chris@0: ); Chris@0: } Chris@0: }