|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Ladybug\Tests\Type\Object; |
| 4 | + |
| 5 | +use Ladybug\Inspector\InspectorManager; |
| 6 | +use Ladybug\Metadata\MetadataResolver; |
| 7 | +use Ladybug\Type; |
| 8 | + |
| 9 | +use \Mockery as m; |
| 10 | + |
| 11 | +class BadTypeHintedParameterContainerTest extends \PHPUnit_Framework_TestCase |
| 12 | +{ |
| 13 | + /** @var Type\Object $type */ |
| 14 | + protected $type; |
| 15 | + |
| 16 | + protected function setUp() |
| 17 | + { |
| 18 | + $factory = new Type\FactoryType(); |
| 19 | + $factory->add(new Type\Null(), 'type_null'); |
| 20 | + |
| 21 | + $managerInspectorMock = m::mock('Ladybug\Inspector\InspectorManager'); |
| 22 | + $managerInspectorMock->shouldReceive('get')->andReturn(null); |
| 23 | + |
| 24 | + $metadataResolverMock = m::mock('Ladybug\Metadata\MetadataResolver'); |
| 25 | + $metadataResolverMock->shouldReceive('has')->andReturn(false); |
| 26 | + |
| 27 | + $this->type = new Type\Object\Container(8, $factory, $managerInspectorMock, $metadataResolverMock); |
| 28 | + } |
| 29 | + |
| 30 | + protected function tearDown() |
| 31 | + { |
| 32 | + $this->type = null; |
| 33 | + } |
| 34 | + |
| 35 | + public function testDumperDoesNotCrashOnWrongTypeHints() |
| 36 | + { |
| 37 | + $var = new Problematic(); |
| 38 | + $this->type->load($var); |
| 39 | + |
| 40 | + // class info |
| 41 | + $this->assertEquals('Ladybug\Tests\Type\Object\Problematic', $this->type->getClassName()); |
| 42 | + $this->assertEquals(__FILE__, $this->type->getClassFile()); |
| 43 | + |
| 44 | + $this->assertCount(2, $this->type->getClassMethods()); |
| 45 | + |
| 46 | + $privateMethod = $this->type->getMethodByName('privateFunction'); |
| 47 | + $this->assertCount(2, $privateMethod->getParameters()); |
| 48 | + |
| 49 | + $parameter1 = $privateMethod->getParameterByName('that'); |
| 50 | + $this->assertNull($parameter1->getType()); |
| 51 | + $this->assertFalse($parameter1->isReference()); |
| 52 | + |
| 53 | + $badTypeHinted = $privateMethod->getParameterByName('badTypeHinted'); |
| 54 | + $this->assertEquals('Wrong_Typehint!', $badTypeHinted->getType()); |
| 55 | + $this->assertFalse($badTypeHinted->isReference()); |
| 56 | + $this->assertInstanceOf('Ladybug\Type\Null', $badTypeHinted->getDefaultValue()); |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +class Problematic |
| 61 | +{ |
| 62 | + public function publicFunction() |
| 63 | + { |
| 64 | + $this->privateFunction($this, null); |
| 65 | + } |
| 66 | + |
| 67 | + private function privateFunction($that, BadTypeHint $badTypeHinted = null) |
| 68 | + { |
| 69 | + } |
| 70 | +} |
0 commit comments