Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

PHPUnit-ized

  • Loading branch information...
commit 774a0a06f53a65848276361f19e735aa4a99cbb8 0 parents
@kentaro authored
3  .gitignore
@@ -0,0 +1,3 @@
+composer.phar
+/vendor
+/bin
5 Bootstrap.php
@@ -0,0 +1,5 @@
+<?php
+
+// For composer
+require_once 'vendor/autoload.php';
+require_once 'src/Guard.php';
42 README.md
@@ -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
9 composer.json
@@ -0,0 +1,9 @@
+{
+ "config": {
+ "vendor-dir": "vendor",
+ "bin-dir": "bin"
+ },
+ "require": {
+ "EHER/PHPUnit": ">=1.6"
+ }
+}
92 composer.lock
@@ -0,0 +1,92 @@
+{
+ "hash": "f455baf5fe97f50374dfc955492e749b",
+ "packages": [
+ {
+ "name": "EHER/PHPUnit",
+ "version": "1.6",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/EHER/phpunit-all-in-one",
+ "reference": "1.6"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://github.com/EHER/phpunit-all-in-one/zipball/1.6",
+ "reference": "1.6",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.0",
+ "symfony/finder": "*"
+ },
+ "time": "2012-05-24 01:46:24",
+ "bin": [
+ "bin/dbunit",
+ "bin/phpcov",
+ "bin/phpcpd",
+ "bin/phpdcd",
+ "bin/phploc",
+ "bin/phpunit",
+ "bin/phpunit-skelgen"
+ ],
+ "type": "library",
+ "installation-source": "dist",
+ "description": "Unofficial version of PHPUnit to be handled with Composer."
+ },
+ {
+ "name": "symfony/finder",
+ "version": "v2.1.2",
+ "target-dir": "Symfony/Component/Finder",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/Finder",
+ "reference": "v2.1.0-RC2"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://github.com/symfony/Finder/zipball/v2.1.0-RC2",
+ "reference": "v2.1.0-RC2",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "time": "2012-08-22 13:48:41",
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.1-dev"
+ }
+ },
+ "installation-source": "dist",
+ "autoload": {
+ "psr-0": {
+ "Symfony\\Component\\Finder": ""
+ }
+ },
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "http://symfony.com/contributors"
+ }
+ ],
+ "description": "Symfony Finder Component",
+ "homepage": "http://symfony.com"
+ }
+ ],
+ "packages-dev": null,
+ "aliases": [
+
+ ],
+ "minimum-stability": "stable",
+ "stability-flags": [
+
+ ]
+}
42 phpunit.xml.dist
@@ -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>
16 src/Guard.php
@@ -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);
+ }
+}
24 test/GuardTest.php
@@ -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);
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.