Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unittest actions #272

Closed
thekid opened this issue May 13, 2013 · 7 comments
Closed

Unittest actions #272

thekid opened this issue May 13, 2013 · 7 comments

Comments

@thekid
Copy link
Member

thekid commented May 13, 2013

Scope of Change

Unittest actions will be introduced to be able to create reusable beforeClass / afterClass / setUp / tearDown handling.

Rationale

Repeated code inside the beforeClass / afterClass / setUp / tearDown methods, like

  • PHP Extension prerequisites checking
  • Platform prerequisites checking
  • Server bootup for integration tests
  • PHP version prerequisites tests

Functionality

Usage

For all tests of a given class:

#[@action(new \unittest\VerifyExtensionAvailability('gd'))]
abstract class AbstractImageWriterTest extends TestCase {
  // ...
}

For only a single test:

class PathTest extends TestCase {

  #[@test, @action(new \unittest\IsPlatForm('Windows'))]
  public function leading_backslash_yields_current_drive() {
    // ...
  }
}

Example implementation

The test action itself:

class VerifyExtensionAvailability extends Object implements TestAction {
  protected $extension;

  public function  __construct($extension) {
    $this->extension= $extension;
  }

  public function beforeTest(TestCase $t) {
    if (!Runtime::getInstance()->extensionAvailable($this->extension)) {
      throw new PrerequisitesNotMetError('Extension "'.$this->extension.'" not available');
    }
  }

  public function afterTest(TestCase $t) {
    // Empty
  }
}

Security considerations

Speed impact

Dependencies

Related documents

http://nunit.org/index.php?p=actionAttributes&r=2.6.2
https://github.com/junit-team/junit/wiki/4.12-release-notes#pull-request-552-stopwatch-rule

@thekid
Copy link
Member Author

thekid commented Jun 29, 2013

@thekid
Copy link
Member Author

thekid commented Jun 29, 2013

It's kind of weird getting used to @unittest.PlatForm('Windows') ... so far, all our annotations have been lower-case. In the above pull request, I've used a derivation as seen in @expect:

class PathTest extends TestCase {

  #[@test, @action(class= 'unittest.action.IsPlatform', args= array('WIN'))]
  public function leading_backslash_yields_current_drive() {
    // ...
  }
}

Unfortunately, it's much longer...

@thekid
Copy link
Member Author

thekid commented Oct 13, 2013

Instead of this action annotation with key/value pairs:

[@test, @action(class= 'unittest.action.IsPlatform', args= array('WIN'))]

...we could now - since xp-framework/xp-framework#328 - also use:

[@test, @action(new IsPlatform('WIN'))]

...and use unittest\action\IsPlatform statements at the top.

Will rewrite the RFC accordingly 🕐

@thekid
Copy link
Member Author

thekid commented Oct 13, 2013

  • Rewrote RFC 🕔
  • Updated implementation - thekid/xp-framework@399303561ec2fe17f3455dac151bd0b2af0510c0 🕗
  • Updated pull request Unittest actions xp-framework#318 accordingly 🕙
  • Performed Last QA 🕚
  • Checked Travis 🕛

@thekid
Copy link
Member Author

thekid commented Oct 13, 2013

✅ Set status to accepted.

thekid added a commit to xp-framework/xp-framework that referenced this issue Oct 13, 2013
@thekid
Copy link
Member Author

thekid commented Oct 13, 2013

Merged successfully.

@thekid thekid closed this as completed Oct 13, 2013
thekid added a commit to xp-framework/xp-framework that referenced this issue Oct 19, 2013
thekid added a commit to xp-framework/xp-framework that referenced this issue Oct 19, 2013
@thekid
Copy link
Member Author

thekid commented Oct 19, 2013

Added possibility for multiple actions by supplying an array to @action for both classes and methods in xp-framework/xp-framework@203cf24:

#[@action([
#  new \unittest\action\ExtensionAvailable('mssql'),
#  new \unittest\action\IsPlatform('WIN')
#])]
class MsSqlWindowsDriverTest extends TestCase {
 // ...
}

thekid added a commit to xp-framework/core that referenced this issue Nov 9, 2013
thekid added a commit to xp-framework/remote that referenced this issue Nov 10, 2013
thekid added a commit to xp-framework/remote that referenced this issue Nov 10, 2013
thekid added a commit to xp-framework/remote that referenced this issue Nov 10, 2013
thekid added a commit to xp-framework/remote that referenced this issue Nov 10, 2013
thekid added a commit to xp-framework/doclet that referenced this issue Nov 10, 2013
thekid added a commit to xp-framework/doclet that referenced this issue Nov 10, 2013
thekid added a commit to xp-framework/doclet that referenced this issue Nov 10, 2013
thekid added a commit to xp-framework/doclet that referenced this issue Nov 10, 2013
thekid added a commit to xp-framework/zip that referenced this issue Nov 10, 2013
thekid added a commit to xp-framework/zip that referenced this issue Nov 10, 2013
thekid added a commit to xp-framework/zip that referenced this issue Nov 10, 2013
thekid added a commit to xp-framework/zip that referenced this issue Nov 10, 2013
thekid added a commit to xp-framework/rdbms that referenced this issue Nov 11, 2013
thekid added a commit to xp-framework/rdbms that referenced this issue Nov 11, 2013
thekid added a commit to xp-framework/rdbms that referenced this issue Nov 11, 2013
thekid added a commit to xp-framework/rdbms that referenced this issue Nov 11, 2013
thekid added a commit to xp-framework/csv that referenced this issue Nov 11, 2013
thekid added a commit to xp-framework/mail that referenced this issue Nov 12, 2013
thekid added a commit to xp-framework/news that referenced this issue Nov 12, 2013
thekid added a commit to xp-framework/news that referenced this issue Nov 12, 2013
thekid added a commit to xp-framework/news that referenced this issue Nov 12, 2013
thekid added a commit to xp-framework/news that referenced this issue Nov 12, 2013
thekid added a commit to xp-framework/irc that referenced this issue Nov 12, 2013
thekid added a commit to xp-framework/irc that referenced this issue Nov 12, 2013
thekid added a commit to xp-framework/irc that referenced this issue Nov 12, 2013
thekid added a commit to xp-framework/irc that referenced this issue Nov 12, 2013
thekid added a commit to xp-framework/sieve that referenced this issue Nov 12, 2013
thekid added a commit to xp-framework/sieve that referenced this issue Nov 12, 2013
thekid added a commit to xp-framework/sieve that referenced this issue Nov 12, 2013
thekid added a commit to xp-framework/sieve that referenced this issue Nov 12, 2013
thekid added a commit to xp-framework/webdav that referenced this issue Nov 12, 2013
thekid added a commit to xp-framework/webdav that referenced this issue Nov 12, 2013
thekid added a commit to xp-framework/webdav that referenced this issue Nov 12, 2013
thekid added a commit to xp-framework/webdav that referenced this issue Nov 12, 2013
thekid added a commit to xp-framework/spelling that referenced this issue Nov 12, 2013
thekid added a commit to xp-framework/spelling that referenced this issue Nov 12, 2013
thekid added a commit to xp-framework/spelling that referenced this issue Nov 12, 2013
thekid added a commit to xp-framework/spelling that referenced this issue Nov 12, 2013
thekid added a commit to xp-framework/xml that referenced this issue Nov 12, 2013
thekid added a commit to xp-framework/xml that referenced this issue Nov 12, 2013
thekid added a commit to xp-framework/xml that referenced this issue Nov 12, 2013
thekid added a commit to xp-framework/xml that referenced this issue Nov 12, 2013
thekid added a commit to xp-framework/telephony that referenced this issue Nov 12, 2013
thekid added a commit to xp-framework/telephony that referenced this issue Nov 12, 2013
thekid added a commit to xp-framework/telephony that referenced this issue Nov 12, 2013
thekid added a commit to xp-framework/telephony that referenced this issue Nov 12, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant