Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

new phpdoc annotation feature: @assert instanceof <Class> #303

Closed
wants to merge 1 commit into from

2 participants

@lightsgoout

I think it might be useful feature.

Example:

/**
 * @assert ('TEST.COM') instanceof Domain
 */
public static function getByName($name) {

    /* code */
}

Then, when I generate skeleton:

/**
 * Generated from @assert ('TEST.COM') instanceof Domain.
 */
public function testGetByName2()
{
    $this->assertInstanceOf('Domain', Domain::getByName('TEST.COM'));
}

Wooh!

@sebastianbergmann

Please open a new pull request against the master branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 19, 2011
  1. @lightsgoout
This page is out of date. Refresh to see the latest.
View
8 PHPUnit/Util/Skeleton/Template/TestMethodInstance.tpl.dist
@@ -0,0 +1,8 @@
+
+ /**
+ * Generated from @assert {annotation}.
+ */
+ public function test{methodName}()
+ {
+ $this->assertInstanceOf('{expected}', $this->object->{origMethodName}({arguments}));
+ }
View
8 PHPUnit/Util/Skeleton/Template/TestMethodInstanceStatic.tpl.dist
@@ -0,0 +1,8 @@
+
+ /**
+ * Generated from @assert {annotation}.
+ */
+ public function test{methodName}()
+ {
+ $this->assertInstanceOf('{expected}', {className}::{origMethodName}({arguments}));
+ }
View
9 PHPUnit/Util/Skeleton/Test.php
@@ -215,6 +215,11 @@ public function generate($verbose = FALSE)
$assertion = 'exception';
}
break;
+
+ case 'instanceof': {
+ $assertion = 'instance';
+ }
+ break;
default: {
throw new PHPUnit_Framework_Exception(
@@ -229,6 +234,10 @@ public function generate($verbose = FALSE)
if ($assertion == 'exception') {
$template = 'TestMethodException';
}
+
+ else if ($assertion == 'instance') {
+ $template = 'TestMethodInstance';
+ }
else if ($assertion == 'Equals' &&
strtolower($matches[3]) == 'true') {
Something went wrong with that request. Please try again.