diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..361083c --- /dev/null +++ b/.php_cs @@ -0,0 +1,15 @@ +in(__DIR__); + +return Symfony\CS\Config\Config::create() + ->fixers(array( + '-concat_without_spaces', + '-empty_return', + '-new_with_braces', + 'align_double_arrow', + 'align_equals', + 'ordered_use', + )) + ->finder($finder); diff --git a/CHANGELOG.md b/CHANGELOG.md index 9befecd..8cd97c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Isolator Changelog +### 3.0.2 (2015-03-23) + +* **[FIXED]** Generated code directory is now created with the correct mode + ### 3.0.1 (2014-10-21) * **[FIXED]** References are now preserved when calling functions with variable arguments diff --git a/README.md b/README.md index 49bd51f..455fd66 100644 --- a/README.md +++ b/README.md @@ -172,4 +172,4 @@ PHP 5.6. [Build Status]: http://img.shields.io/travis/IcecaveStudios/isolator/develop.svg?style=flat-square [Test Coverage]: http://img.shields.io/coveralls/IcecaveStudios/isolator/develop.svg?style=flat-square -[SemVer]: http://img.shields.io/:semver-3.0.1-brightgreen.svg?style=flat-square +[SemVer]: http://img.shields.io/:semver-3.0.2-brightgreen.svg?style=flat-square diff --git a/composer.lock b/composer.lock index 38d1d4b..a969d5b 100644 --- a/composer.lock +++ b/composer.lock @@ -68,16 +68,16 @@ }, { "name": "guzzle/guzzle", - "version": "v3.9.2", + "version": "v3.9.3", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle3.git", - "reference": "54991459675c1a2924122afbb0e5609ade581155" + "reference": "0645b70d953bc1c067bbc8d5bc53194706b628d9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle3/zipball/54991459675c1a2924122afbb0e5609ade581155", - "reference": "54991459675c1a2924122afbb0e5609ade581155", + "url": "https://api.github.com/repos/guzzle/guzzle3/zipball/0645b70d953bc1c067bbc8d5bc53194706b628d9", + "reference": "0645b70d953bc1c067bbc8d5bc53194706b628d9", "shasum": "" }, "require": { @@ -118,6 +118,9 @@ "zendframework/zend-cache": "2.*,<2.3", "zendframework/zend-log": "2.*,<2.3" }, + "suggest": { + "guzzlehttp/guzzle": "Guzzle 5 has moved to a new package name. The package you have installed, Guzzle 3, is deprecated." + }, "type": "library", "extra": { "branch-alias": { @@ -145,7 +148,7 @@ "homepage": "https://github.com/guzzle/guzzle/contributors" } ], - "description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients", + "description": "PHP HTTP client. This library is deprecated in favor of https://packagist.org/packages/guzzlehttp/guzzle", "homepage": "http://guzzlephp.org/", "keywords": [ "client", @@ -156,20 +159,20 @@ "rest", "web service" ], - "time": "2014-08-11 04:32:36" + "time": "2015-03-18 18:23:50" }, { "name": "icecave/archer", - "version": "1.3.0", + "version": "1.3.1", "source": { "type": "git", "url": "https://github.com/IcecaveStudios/archer.git", - "reference": "5b1b4748d0fd6a8f977486d15d10e52e68349379" + "reference": "a17abd703a794aefcc56816e4d0a169b29500c66" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/IcecaveStudios/archer/zipball/5b1b4748d0fd6a8f977486d15d10e52e68349379", - "reference": "5b1b4748d0fd6a8f977486d15d10e52e68349379", + "url": "https://api.github.com/repos/IcecaveStudios/archer/zipball/a17abd703a794aefcc56816e4d0a169b29500c66", + "reference": "a17abd703a794aefcc56816e4d0a169b29500c66", "shasum": "" }, "require": { @@ -234,7 +237,7 @@ "testing", "unit" ], - "time": "2014-09-18 03:05:28" + "time": "2014-11-10 21:59:53" }, { "name": "nikic/php-parser", @@ -283,16 +286,16 @@ }, { "name": "phake/phake", - "version": "v1.0.5", + "version": "1.0.8", "source": { "type": "git", "url": "https://github.com/mlively/Phake.git", - "reference": "14e4788698e4a21774220c22f3dcaa2e97648b61" + "reference": "c5a3d7a75fc7431e8a5e21a922f084af95456bc6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/mlively/Phake/zipball/14e4788698e4a21774220c22f3dcaa2e97648b61", - "reference": "14e4788698e4a21774220c22f3dcaa2e97648b61", + "url": "https://api.github.com/repos/mlively/Phake/zipball/c5a3d7a75fc7431e8a5e21a922f084af95456bc6", + "reference": "c5a3d7a75fc7431e8a5e21a922f084af95456bc6", "shasum": "" }, "require": { @@ -301,7 +304,7 @@ "require-dev": { "doctrine/common": "2.3.*", "ext-soap": "*", - "hamcrest/hamcrest-php": "1.1.*", + "hamcrest/hamcrest-php": "1.1.0", "phpunit/phpunit": "3.7.*" }, "type": "library", @@ -329,7 +332,7 @@ "mock", "testing" ], - "time": "2014-04-16 14:49:56" + "time": "2015-01-27 15:48:39" }, { "name": "pimple/pimple", @@ -542,27 +545,30 @@ }, { "name": "symfony/config", - "version": "v2.5.5", + "version": "v2.6.5", "target-dir": "Symfony/Component/Config", "source": { "type": "git", "url": "https://github.com/symfony/Config.git", - "reference": "0316364bfebc8b080077c731a99f189341476bd7" + "reference": "7a47189c7667ca69bcaafd19ef8a8941db449a2c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Config/zipball/0316364bfebc8b080077c731a99f189341476bd7", - "reference": "0316364bfebc8b080077c731a99f189341476bd7", + "url": "https://api.github.com/repos/symfony/Config/zipball/7a47189c7667ca69bcaafd19ef8a8941db449a2c", + "reference": "7a47189c7667ca69bcaafd19ef8a8941db449a2c", "shasum": "" }, "require": { "php": ">=5.3.3", "symfony/filesystem": "~2.3" }, + "require-dev": { + "symfony/phpunit-bridge": "~2.7" + }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.5-dev" + "dev-master": "2.6-dev" } }, "autoload": { @@ -586,21 +592,21 @@ ], "description": "Symfony Config Component", "homepage": "http://symfony.com", - "time": "2014-09-23 05:25:11" + "time": "2015-03-12 10:28:44" }, { "name": "symfony/console", - "version": "v2.5.5", + "version": "v2.6.5", "target-dir": "Symfony/Component/Console", "source": { "type": "git", "url": "https://github.com/symfony/Console.git", - "reference": "ca053eaa031c93afb68a71e4eb1f4168dfd4a661" + "reference": "53f86497ccd01677e22435cfb7262599450a90d1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Console/zipball/ca053eaa031c93afb68a71e4eb1f4168dfd4a661", - "reference": "ca053eaa031c93afb68a71e4eb1f4168dfd4a661", + "url": "https://api.github.com/repos/symfony/Console/zipball/53f86497ccd01677e22435cfb7262599450a90d1", + "reference": "53f86497ccd01677e22435cfb7262599450a90d1", "shasum": "" }, "require": { @@ -608,16 +614,19 @@ }, "require-dev": { "psr/log": "~1.0", - "symfony/event-dispatcher": "~2.1" + "symfony/event-dispatcher": "~2.1", + "symfony/phpunit-bridge": "~2.7", + "symfony/process": "~2.1" }, "suggest": { "psr/log": "For using the console logger", - "symfony/event-dispatcher": "" + "symfony/event-dispatcher": "", + "symfony/process": "" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.5-dev" + "dev-master": "2.6-dev" } }, "autoload": { @@ -641,21 +650,21 @@ ], "description": "Symfony Console Component", "homepage": "http://symfony.com", - "time": "2014-09-25 09:53:56" + "time": "2015-03-13 17:37:22" }, { "name": "symfony/event-dispatcher", - "version": "v2.5.5", + "version": "v2.6.5", "target-dir": "Symfony/Component/EventDispatcher", "source": { "type": "git", "url": "https://github.com/symfony/EventDispatcher.git", - "reference": "f6281337bf5f985f585d1db6a83adb05ce531f46" + "reference": "70f7c8478739ad21e3deef0d977b38c77f1fb284" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/f6281337bf5f985f585d1db6a83adb05ce531f46", - "reference": "f6281337bf5f985f585d1db6a83adb05ce531f46", + "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/70f7c8478739ad21e3deef0d977b38c77f1fb284", + "reference": "70f7c8478739ad21e3deef0d977b38c77f1fb284", "shasum": "" }, "require": { @@ -663,9 +672,11 @@ }, "require-dev": { "psr/log": "~1.0", - "symfony/config": "~2.0", - "symfony/dependency-injection": "~2.0,<2.6.0", - "symfony/stopwatch": "~2.2" + "symfony/config": "~2.0,>=2.0.5", + "symfony/dependency-injection": "~2.6", + "symfony/expression-language": "~2.6", + "symfony/phpunit-bridge": "~2.7", + "symfony/stopwatch": "~2.3" }, "suggest": { "symfony/dependency-injection": "", @@ -674,7 +685,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.5-dev" + "dev-master": "2.6-dev" } }, "autoload": { @@ -698,30 +709,33 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "http://symfony.com", - "time": "2014-09-28 15:56:11" + "time": "2015-03-13 17:37:22" }, { "name": "symfony/filesystem", - "version": "v2.5.5", + "version": "v2.6.5", "target-dir": "Symfony/Component/Filesystem", "source": { "type": "git", "url": "https://github.com/symfony/Filesystem.git", - "reference": "4e62fab0060a826561c78b665925b37c870c45f5" + "reference": "fdc5f151bc2db066b51870d5bea3773d915ced0b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Filesystem/zipball/4e62fab0060a826561c78b665925b37c870c45f5", - "reference": "4e62fab0060a826561c78b665925b37c870c45f5", + "url": "https://api.github.com/repos/symfony/Filesystem/zipball/fdc5f151bc2db066b51870d5bea3773d915ced0b", + "reference": "fdc5f151bc2db066b51870d5bea3773d915ced0b", "shasum": "" }, "require": { "php": ">=5.3.3" }, + "require-dev": { + "symfony/phpunit-bridge": "~2.7" + }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.5-dev" + "dev-master": "2.6-dev" } }, "autoload": { @@ -745,30 +759,33 @@ ], "description": "Symfony Filesystem Component", "homepage": "http://symfony.com", - "time": "2014-09-22 09:14:18" + "time": "2015-03-12 10:28:44" }, { "name": "symfony/finder", - "version": "v2.5.5", + "version": "v2.6.5", "target-dir": "Symfony/Component/Finder", "source": { "type": "git", "url": "https://github.com/symfony/Finder.git", - "reference": "d5033742b9a6206ef6d06e813870bca18e9205df" + "reference": "bebc7479c566fa4f14b9bcef9e32e719eabec74e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Finder/zipball/d5033742b9a6206ef6d06e813870bca18e9205df", - "reference": "d5033742b9a6206ef6d06e813870bca18e9205df", + "url": "https://api.github.com/repos/symfony/Finder/zipball/bebc7479c566fa4f14b9bcef9e32e719eabec74e", + "reference": "bebc7479c566fa4f14b9bcef9e32e719eabec74e", "shasum": "" }, "require": { "php": ">=5.3.3" }, + "require-dev": { + "symfony/phpunit-bridge": "~2.7" + }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.5-dev" + "dev-master": "2.6-dev" } }, "autoload": { @@ -792,30 +809,33 @@ ], "description": "Symfony Finder Component", "homepage": "http://symfony.com", - "time": "2014-09-27 08:35:39" + "time": "2015-03-12 10:28:44" }, { "name": "symfony/process", - "version": "v2.5.5", + "version": "v2.6.5", "target-dir": "Symfony/Component/Process", "source": { "type": "git", "url": "https://github.com/symfony/Process.git", - "reference": "8a1ec96c4e519cee0fb971ea48a1eb7369dda54b" + "reference": "4d717f34f3d1d6ab30fbe79f7132960a27f4a0dc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Process/zipball/8a1ec96c4e519cee0fb971ea48a1eb7369dda54b", - "reference": "8a1ec96c4e519cee0fb971ea48a1eb7369dda54b", + "url": "https://api.github.com/repos/symfony/Process/zipball/4d717f34f3d1d6ab30fbe79f7132960a27f4a0dc", + "reference": "4d717f34f3d1d6ab30fbe79f7132960a27f4a0dc", "shasum": "" }, "require": { "php": ">=5.3.3" }, + "require-dev": { + "symfony/phpunit-bridge": "~2.7" + }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.5-dev" + "dev-master": "2.6-dev" } }, "autoload": { @@ -839,30 +859,33 @@ ], "description": "Symfony Process Component", "homepage": "http://symfony.com", - "time": "2014-09-23 05:25:11" + "time": "2015-03-12 10:28:44" }, { "name": "symfony/stopwatch", - "version": "v2.5.5", + "version": "v2.6.5", "target-dir": "Symfony/Component/Stopwatch", "source": { "type": "git", "url": "https://github.com/symfony/Stopwatch.git", - "reference": "9f8a33a24f2378c0ec5f372a8d50b2d43069c050" + "reference": "ba4e774f71e2ce3e3f65cabac4031b9029972af5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Stopwatch/zipball/9f8a33a24f2378c0ec5f372a8d50b2d43069c050", - "reference": "9f8a33a24f2378c0ec5f372a8d50b2d43069c050", + "url": "https://api.github.com/repos/symfony/Stopwatch/zipball/ba4e774f71e2ce3e3f65cabac4031b9029972af5", + "reference": "ba4e774f71e2ce3e3f65cabac4031b9029972af5", "shasum": "" }, "require": { "php": ">=5.3.3" }, + "require-dev": { + "symfony/phpunit-bridge": "~2.7" + }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.5-dev" + "dev-master": "2.6-dev" } }, "autoload": { @@ -886,30 +909,33 @@ ], "description": "Symfony Stopwatch Component", "homepage": "http://symfony.com", - "time": "2014-09-22 09:14:18" + "time": "2015-02-24 11:52:21" }, { "name": "symfony/yaml", - "version": "v2.5.5", + "version": "v2.6.5", "target-dir": "Symfony/Component/Yaml", "source": { "type": "git", "url": "https://github.com/symfony/Yaml.git", - "reference": "b1dbc53593b98c2d694ebf383660ac9134d30b96" + "reference": "0cd8e72071e46e15fc072270ae39ea1b66b10a9d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Yaml/zipball/b1dbc53593b98c2d694ebf383660ac9134d30b96", - "reference": "b1dbc53593b98c2d694ebf383660ac9134d30b96", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/0cd8e72071e46e15fc072270ae39ea1b66b10a9d", + "reference": "0cd8e72071e46e15fc072270ae39ea1b66b10a9d", "shasum": "" }, "require": { "php": ">=5.3.3" }, + "require-dev": { + "symfony/phpunit-bridge": "~2.7" + }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.5-dev" + "dev-master": "2.6-dev" } }, "autoload": { @@ -933,20 +959,20 @@ ], "description": "Symfony Yaml Component", "homepage": "http://symfony.com", - "time": "2014-09-22 09:14:18" + "time": "2015-03-12 10:28:44" }, { "name": "twig/twig", - "version": "v1.16.0", + "version": "v1.18.0", "source": { "type": "git", - "url": "https://github.com/fabpot/Twig.git", - "reference": "8ce37115802e257a984a82d38254884085060024" + "url": "https://github.com/twigphp/Twig.git", + "reference": "4cf7464348e7f9893a93f7096a90b73722be99cf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fabpot/Twig/zipball/8ce37115802e257a984a82d38254884085060024", - "reference": "8ce37115802e257a984a82d38254884085060024", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/4cf7464348e7f9893a93f7096a90b73722be99cf", + "reference": "4cf7464348e7f9893a93f7096a90b73722be99cf", "shasum": "" }, "require": { @@ -955,7 +981,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.16-dev" + "dev-master": "1.18-dev" } }, "autoload": { @@ -981,7 +1007,7 @@ }, { "name": "Twig Team", - "homepage": "https://github.com/fabpot/Twig/graphs/contributors", + "homepage": "http://twig.sensiolabs.org/contributors", "role": "Contributors" } ], @@ -990,13 +1016,14 @@ "keywords": [ "templating" ], - "time": "2014-07-05 12:19:05" + "time": "2015-01-25 17:32:08" } ], "aliases": [], "minimum-stability": "stable", "stability-flags": [], "prefer-stable": false, + "prefer-lowest": false, "platform": { "php": ">=5.3" }, diff --git a/src/Detail/Autoloader.php b/src/Detail/Autoloader.php index 66a5c2a..36a6537 100644 --- a/src/Detail/Autoloader.php +++ b/src/Detail/Autoloader.php @@ -1,6 +1,7 @@ path = $path; + $this->path = $path; $this->codeGenerator = $codeGenerator; } @@ -86,19 +87,28 @@ public function generateIsolatorClass( array $functions ) { $dirName = dirname($fileName); + $umask = umask(0); - if (!file_exists($dirName)) { - mkdir($dirName, 0777, true); - } + try { + if (!file_exists($dirName)) { + mkdir($dirName, 0777, true); + } - $code = $this - ->codeGenerator - ->generate( - $className, - $functions - ); + $code = $this + ->codeGenerator + ->generate( + $className, + $functions + ); - file_put_contents($fileName, $code); + file_put_contents($fileName, $code); + + umask($umask); + } catch (Exception $e) { + umask($umask); + + throw $e; + } } private $path; diff --git a/src/Detail/CodeGenerator.php b/src/Detail/CodeGenerator.php index 9dff75a..721b2cb 100644 --- a/src/Detail/CodeGenerator.php +++ b/src/Detail/CodeGenerator.php @@ -171,8 +171,8 @@ public function generateFallbackReturn($name, $refIndices) private function inspectParameters(ReflectionFunction $reflector) { - $minArity = 0; - $maxArity = 0; + $minArity = 0; + $maxArity = 0; $refIndices = array(); foreach ($reflector->getParameters() as $parameter) { diff --git a/src/PackageInfo.php b/src/PackageInfo.php index c1a8016..e3041b9 100644 --- a/src/PackageInfo.php +++ b/src/PackageInfo.php @@ -3,6 +3,6 @@ class PackageInfo { - const NAME = 'Isolator'; - const VERSION = '3.0.1'; + const NAME = 'Isolator'; + const VERSION = '3.0.2'; } diff --git a/src/register-autoloader.php b/src/register-autoloader.php index d17ec03..aa808ee 100644 --- a/src/register-autoloader.php +++ b/src/register-autoloader.php @@ -1,9 +1,7 @@ path = tempnam(sys_get_temp_dir(), 'isolator-'); + $this->path = tempnam(sys_get_temp_dir(), 'isolator-'); $this->codeGenerator = Phake::mock(__NAMESPACE__ . '\CodeGenerator'); $this->autoloader = new Autoloader( @@ -42,4 +43,58 @@ public function testLoad() Phake::verify($this->codeGenerator, Phake::times(1))->generate(Phake::anyParameters()); } + public function testDirectoryIsCreatedWorldWritable() + { + $this->expectOutputString('Included!'); + + $this->autoloader->load('Foo'); + + $stat = stat($this->path); + + $this->assertEquals( + 0777, + $stat['mode'] & 0777, + 'Isolator temporary directory must be world writable.' + ); + } + + public function testUmaskIsReset() + { + $umask = umask(); + + $this->expectOutputString('Included!'); + + $this->autoloader->load('Foo'); + + $this->assertEquals( + $umask, + umask() + ); + } + + public function testUmaskIsResetAfterException() + { + $umask = umask(); + $exception = new Exception('The exception!'); + + Phake::when($this->codeGenerator) + ->generate(Phake::anyParameters()) + ->thenThrow($exception); + + $this->setExpectedException( + 'Exception', + 'The exception!' + ); + + try { + $this->autoloader->load('Foo'); + } catch (Exception $e) { + $this->assertEquals( + $umask, + umask() + ); + + throw $e; + } + } } diff --git a/test/suite/Detail/CodeGeneratorTest.php b/test/suite/Detail/CodeGeneratorTest.php index c4dd668..7183b98 100644 --- a/test/suite/Detail/CodeGeneratorTest.php +++ b/test/suite/Detail/CodeGeneratorTest.php @@ -147,4 +147,47 @@ public function testGenerateMethodWithVarArgs() $code ); } + + public function testGenerateMultipleMethods() + { + $code = $this->generator->generate( + 'Foo', + array('strlen', 'phpversion') + ); + + $expectedCode = 'assertSame( + $expectedCode, + $code + ); + } } diff --git a/test/suite/IsolatorTraitTest.php b/test/suite/IsolatorTraitTest.php index 183dc91..b1ec4e3 100644 --- a/test/suite/IsolatorTraitTest.php +++ b/test/suite/IsolatorTraitTest.php @@ -1,8 +1,8 @@