Skip to content

Commit

Permalink
add tests for ReflectionTest
Browse files Browse the repository at this point in the history
  • Loading branch information
PBXg33k committed Jul 22, 2017
1 parent 41d1286 commit 5e7d14e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ReflectionTrait.php
Expand Up @@ -47,7 +47,7 @@ public static function getClassFromDocComment($comment, $includeNamespaces = tru
}
return $matches[1];
}
return join('', array_slice(explode('\\', $matches[1]), -1));
return implode('', array_slice(explode('\\', $matches[1]), -1));
}

return false;
Expand Down
39 changes: 39 additions & 0 deletions tests/ReflectionTest.php
@@ -0,0 +1,39 @@
<?php
require_once(__DIR__.'/stubs/ReflectionStub.php');

class ReflectionTest extends PHPUnit_Framework_TestCase
{
/**
* @var ReflectionStub
*/
protected $testClass;

public function setUp()
{
$this->testClass = new ReflectionStub();
}

public function testExceptionOnClassNotFound()
{
$className = "thisClassDoesNotExist";

$this->expectExceptionMessage(sprintf("%s not found or does not exist", $className));

$this->testClass->getClassFromClassProperty($className, 'foo');
}

public function testExceptionOnPropertyNotFound()
{
$propertyName = "NonExistingProperty";
$className = ReflectionStub::class;

$this->expectExceptionMessage(sprintf("%s has no property with the name %s", $className, $propertyName));

$this->testClass->getClassFromClassProperty($className, $propertyName);
}

//public function testGetClassNameWithoutNamespaceFromComment()
//{
//
//}
}
18 changes: 18 additions & 0 deletions tests/stubs/ReflectionStub.php
@@ -0,0 +1,18 @@
<?php
require_once(__DIR__.'/../../src/ReflectionTrait.php');


class ReflectionStub
{
use \Pbxg33k\Traits\ReflectionTrait;

/**
* @var Exclude\Namespace
*/
public $nonNamespacedClass;

/**
* @var ThisClassDoesNotExist
*/
public $thisClassDoesNotExist;
}

0 comments on commit 5e7d14e

Please sign in to comment.