Permalink
Browse files

PHPUnit-ized

  • Loading branch information...
kentaro committed Oct 1, 2012
0 parents commit 774a0a06f53a65848276361f19e735aa4a99cbb8
Showing with 233 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +5 −0 Bootstrap.php
  3. +42 −0 README.md
  4. +9 −0 composer.json
  5. +92 −0 composer.lock
  6. +42 −0 phpunit.xml.dist
  7. +16 −0 src/Guard.php
  8. +24 −0 test/GuardTest.php
@@ -0,0 +1,3 @@
+composer.phar
+/vendor
+/bin
@@ -0,0 +1,5 @@
+<?php
+
+// For composer
+require_once 'vendor/autoload.php';
+require_once 'src/Guard.php';
@@ -0,0 +1,42 @@
+# Guard
+
+Simplly cleaning up resources with RAII pattern.
+
+# Synopsis
+
+## `unset()`
+
+```php
+$guard = new Guard(function () { echo "unset!\n"; });
+unset($guard); //=> unset!
+```
+
+## Function Scope
+
+```php
+function foo()
+{
+ $guard = new Guard(function () { echo "destructed!\n"; });
+ // ... do something ...
+}
+
+foo(); //=> echoed "destructed!" after function called
+```
+
+# Run Tests Using Composer
+
+```
+$ curl -s https://getcomposer.org/installer | php
+$ php composer.phar install
+$ bin/phpunit
+```
+
+# LICENSE
+
+## Copyright
+
+Copyright Kentaro Kuribayashi
+
+## LICENSE
+
+MIT LICENSE
@@ -0,0 +1,9 @@
+{
+ "config": {
+ "vendor-dir": "vendor",
+ "bin-dir": "bin"
+ },
+ "require": {
+ "EHER/PHPUnit": ">=1.6"
+ }
+}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<phpunit
+ bootstrap="Bootstrap.php"
+ processIsolation="false"
+ verbose="true"
+ strict="false"
+ colors="true">
+ <testsuites>
+ <testsuite name="PHPUnit">
+ <!-- テストケースがあるディレクトリを列挙する -->
+ <directory>test</directory>
+ <!-- <directory>MyProject2</directory> -->
+ <!-- <directory>MyProject3</directory> -->
+ <!-- <directory>MyProject4</directory> -->
+ </testsuite>
+ </testsuites>
+
+ <logging>
+ <!-- コードカバレッジ率 -->
+ <log
+ type="coverage-html"
+ target="Coverage"
+ charset="UTF-8"
+ yui="true"
+ highlight="false"
+ lowUpperBound="35"
+ highLowerBound="70" />
+ <log type="coverage-text" target="php://stdout" lowUpperBound="35" highLowerBound="70" />
+ <!-- 上行をアンコメントアウトするとカバレッジ率がプロンプトにも表示される -->
+ </logging>
+
+ <filter>
+ <!-- コードカバレッジ率を計測する対象の指定 -->
+ <whitelist>
+ <directory suffix=".php">./src</directory>
+ </whitelist>
+ <!-- コードカバレッジ測定対象から除外 -->
+ <blacklist>
+ <directory suffix=".php" group="PHPUNIT">./vendor</directory>
+ </blacklist>
+ </filter>
+</phpunit>
@@ -0,0 +1,16 @@
+<?php
+
+class Guard
+{
+ private $callback;
+
+ public function __construct(callable $callback)
+ {
+ $this->callback = $callback;
+ }
+
+ public function __destruct()
+ {
+ call_user_func($this->callback);
+ }
+}
@@ -0,0 +1,24 @@
+<?php
+
+class GuardTest extends PHPUnit_Framework_TestCase
+{
+ public function testFunctionScope()
+ {
+ $result = false;
+ $func = function () use (&$result) {
+ new Guard(function () use (&$result) { $result = true; });
+ };
+ call_user_func($func);
+
+ $this->assertTrue($result);
+ }
+
+ public function testUnsetGuard()
+ {
+ $result = false;
+ $guard = new Guard(function () use (&$result) { $result = true; });
+ unset($guard);
+
+ $this->assertTrue($result);
+ }
+}

0 comments on commit 774a0a0

Please sign in to comment.