diff --git a/.travis.env b/.travis.env index f5b559e..9526226 100644 --- a/.travis.env +++ b/.travis.env @@ -1 +1 @@ -Ob4Tk/LbPO+MA2+t5gzLmh+/9Q7hPOsMdoAkrIrIS9NJuN7j+Njf2rg3yPq9TZjXpbGnQaR0avSaiCfpjkVfWMOYYtyU6Duotgp71lpshQhM3owIifkEfqRhh3mP/sOnTjcW9bpD2A/97u3mK9Gc2nyw1nNIn5egD85VJ10KYis= \ No newline at end of file +pTSn8XE11MNuOBzY6d53r/8q20eT+HAtllIOn4q3Jp9nsxlzTx9ORQvwT8LBiDW8TTY87h+TuwawA9AYA/tA0QWPAkI3lD9HqW5/DS0p1aS9ssRywq5KJXs/N8MaqTUfom+RdPkpCwSvAYxWcjy9CXkp+zYVwPPZpg7x2k1rxuY= \ No newline at end of file diff --git a/.travis.install b/.travis.install index 60d38bd..47961e7 100755 --- a/.travis.install +++ b/.travis.install @@ -1,26 +1,42 @@ #!/usr/bin/env php array( - 'github-oauth' => array('github.com' => $token) - ) - ); - $file = '~/.composer/config.json'; - $dir = dirname($file); - if (!is_dir($dir)) { - mkdir($dir, 0755, true); - } - file_put_contents($file, json_encode($config)); +// Update git to the latest version ... +passthru('sudo apt-get update'); +passthru('sudo apt-get install git'); + +// Update composer to the latest version ... +passthru('composer self-update --no-interaction'); +// Build a composer config that uses the GitHub OAuth token if it is available ... +$config = array( + 'config' => array( + 'notify-on-install' => false + ) +); + +if ($token = getenv('ARCHER_TOKEN')) { + $config['config']['github-oauth'] = array( + 'github.com' => $token + ); $composerFlags = '--prefer-dist'; } else { $composerFlags = '--prefer-source'; } -passthru('composer install --dev --no-progress --no-interaction --ansi ' . $composerFlags); +$file = '~/.composer/config.json'; +$dir = dirname($file); +if (!is_dir($dir)) { + mkdir($dir, 0755, true); +} +file_put_contents($file, json_encode($config)); + +// Display some information about GitHub rate limiting ... +if ($token) { + passthru('curl -s -i -H "Authorization: token $ARCHER_TOKEN" https://api.github.com | grep "^X-RateLimit"'); +} + +// Install composer dependencies ... +$exitCode = 0; +passthru('composer install --dev --no-progress --no-interaction --ansi ' . $composerFlags, $exitCode); +exit($exitCode); diff --git a/.travis.yml b/.travis.yml index b52ffee..12a16ea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,29 +1,18 @@ -# -# This is the default Travis CI configuration. -# -# It uses a GitHub OAuth token when fetching composer dependencies -# to avoid IP-based API throttling. -# -# It also allows publication of artifacts via an additional build. -# language: php -php: - - 5.3 - - 5.4 - - 5.5 +php: ["5.3", "5.4", "5.5", "hhvm"] + +matrix: + allow_failures: + - php: hhvm env: global: - - ARCHER_PUBLISH_VERSION=5.4 - - secure: "Ob4Tk/LbPO+MA2+t5gzLmh+/9Q7hPOsMdoAkrIrIS9NJuN7j+Njf2rg3yPq9TZjXpbGnQaR0avSaiCfpjkVfWMOYYtyU6Duotgp71lpshQhM3owIifkEfqRhh3mP/sOnTjcW9bpD2A/97u3mK9Gc2nyw1nNIn5egD85VJ10KYis=" + - ARCHER_PUBLISH_VERSION=5.5 + - secure: "pTSn8XE11MNuOBzY6d53r/8q20eT+HAtllIOn4q3Jp9nsxlzTx9ORQvwT8LBiDW8TTY87h+TuwawA9AYA/tA0QWPAkI3lD9HqW5/DS0p1aS9ssRywq5KJXs/N8MaqTUfom+RdPkpCwSvAYxWcjy9CXkp+zYVwPPZpg7x2k1rxuY=" install: - ./.travis.install + script: - ./vendor/bin/archer travis:build - -matrix: - # PHP 5.5 is still in alpha, so ignore build failures. - allow_failures: - - php: 5.5 diff --git a/CHANGELOG.md b/CHANGELOG.md index 598d6d0..09c6d9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,14 +1,25 @@ # Liberator changelog -### 1.1.1 +## 2.0.0 (2014-02-09) -* Added [icecave/archer](https://github.com/IcecaveStudios/archer) integration -* Repository maintenance +- **[BC BREAK]** Some class members that were previously protected are now + private. It is very unlikely that this affects anyone at all, but technically + it's backwards incompatible. +- **[NEW]** Added an interface for identifying liberator proxied values. +- **[NEW]** API documentation +- **[MAINTENANCE]** Repository maintenance -### 1.1.0 +## 1.1.1 (2013-03-04) -* Improved API +- **[NEW]** Added [Archer] integration +- **[MAINTENANCE]** Repository maintenance -### 1.0.0 +[Archer]: https://github.com/IcecaveStudios/archer -* Initial stable release +## 1.1.0 (2012-08-02) + +- **[IMPROVED]** Improved API + +## 1.0.0 (2012-08-02) + +- **[NEW]** Initial stable release diff --git a/LICENSE b/LICENSE index f23d006..54584b1 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright © 2013 Erin Millard +Copyright © 2014 Erin Millard Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index cae55ed..e129598 100644 --- a/README.md +++ b/README.md @@ -2,32 +2,27 @@ *A proxy for circumventing PHP access modifier restrictions.* -[![Build status](https://raw.github.com/eloquent/liberator/gh-pages/artifacts/images/icecave/regular/build-status.png)](http://travis-ci.org/eloquent/liberator) -[![Test coverage](https://raw.github.com/eloquent/liberator/gh-pages/artifacts/images/icecave/regular/coverage.png)](http://eloquent.github.com/liberator/artifacts/tests/coverage) +[![The most recent stable version is 2.0.0][version-image]][Semantic versioning] +[![Current build status image][build-image]][Current build status] +[![Current coverage status image][coverage-image]][Current coverage status] -## Installation +## Installation and documentation -Available as [Composer](http://getcomposer.org/) package -[eloquent/liberator](https://packagist.org/packages/eloquent/liberator). +- Available as [Composer] package [eloquent/liberator]. +- [API documentation] available. ## What is Liberator? -Liberator is an object proxy that allows you to access methods and properties -of an object or class that would normally be restricted by PHP. Essentially, -this means you ignore any 'private' or 'protected' keywords. +*Liberator* allows access to **protected** and **private** methods and +properties of objects as if they were marked **public**. It can do so for both +objects and classes (i.e. static methods and properties). -Liberator's primary use is as a testing tool. Unit tests can often be simplified -using a mix of partially mocked objects and Liberator. - -Liberator is based upon the [Pops](https://github.com/eloquent/pops) object -proxy system. +*Liberator*'s primary use is as a testing tool, allowing direct access to +methods that would otherwise require complicated test harnesses or mocking to +test. ## Usage -Liberator allows access to **protected** and **private** methods and properties -of objects as if they were marked **public**. It can do so for both objects and -classes (i.e. static methods and properties). - ### For objects Take the following class: @@ -37,7 +32,7 @@ class SeriousBusiness { private function foo($adjective) { - return 'foo is '.$adjective; + return 'foo is ' . $adjective; } private $bar = 'mind'; @@ -45,7 +40,7 @@ class SeriousBusiness ``` Normally there is no way to call `foo()` or access `$bar` from outside the -`SeriousBusiness` class, but **Liberator** allows this to be achieved: +`SeriousBusiness` class, but *Liberator* allows this to be achieved: ```php use Eloquent\Liberator\Liberator; @@ -53,8 +48,8 @@ use Eloquent\Liberator\Liberator; $object = new SeriousBusiness; $liberator = Liberator::liberate($object); -echo $liberator->foo('not so private...'); // outputs 'foo is not so private...' -echo $liberator->bar.' = blown'; // outputs 'mind = blown' +echo $liberator->foo('not so private...'); // outputs 'foo is not so private...' +echo $liberator->bar . ' = blown'; // outputs 'mind = blown' ``` ### For classes @@ -66,26 +61,26 @@ class SeriousBusiness { static private function baz($adjective) { - return 'baz is '.$adjective; + return 'baz is ' . $adjective; } static private $qux = 'mind'; } ``` -To access these, a **class liberator** must be used instead of an -**object liberator**, but they operate in a similar manner: +To access these, a *class liberator* must be used instead of an *object +liberator*, but they operate in a similar manner: ```php use Eloquent\Liberator\Liberator; $liberator = Liberator::liberateClass('SeriousBusiness'); -echo $liberator->baz('not so private...'); // outputs 'baz is not so private...' -echo $liberator->qux.' = blown'; // outputs 'mind = blown' +echo $liberator->baz('not so private...'); // outputs 'baz is not so private...' +echo $liberator->qux . ' = blown'; // outputs 'mind = blown' ``` -Alternatively, Liberator can generate a class that can be used statically: +Alternatively, *Liberator* can generate a class that can be used statically: ```php use Eloquent\Liberator\Liberator; @@ -93,7 +88,7 @@ use Eloquent\Liberator\Liberator; $liberatorClass = Liberator::liberateClassStatic('SeriousBusiness'); echo $liberatorClass::baz('not so private...'); // outputs 'baz is not so private...' -echo $liberatorClass::liberator()->qux.' = blown'; // outputs 'mind = blown' +echo $liberatorClass::liberator()->qux . ' = blown'; // outputs 'mind = blown' ``` Unfortunately, there is (currently) no __getStatic() or __setStatic() in PHP, @@ -101,6 +96,19 @@ so accessing static properties in this way is a not as elegant as it could be. ## Applications for Liberator -* Writing [white-box](http://en.wikipedia.org/wiki/White-box_testing) style unit - tests (testing protected/private methods). -* Modifying behaviour of poorly designed third-party libraries. +- Writing [white-box] style unit tests (testing protected/private methods). +- Modifying behavior of poorly designed third-party libraries. + + + +[white-box]: http://en.wikipedia.org/wiki/White-box_testing + +[API documentation]: http://lqnt.co/liberator/artifacts/documentation/api/ +[Composer]: http://getcomposer.org/ +[build-image]: http://img.shields.io/travis/eloquent/liberator/develop.svg "Current build status for the develop branch" +[Current build status]: https://travis-ci.org/eloquent/liberator +[coverage-image]: http://img.shields.io/coveralls/eloquent/liberator/develop.svg "Current test coverage for the develop branch" +[Current coverage status]: https://coveralls.io/r/eloquent/liberator +[eloquent/liberator]: https://packagist.org/packages/eloquent/liberator +[Semantic versioning]: http://semver.org/ +[version-image]: http://img.shields.io/:semver-2.0.0-brightgreen.svg "This project uses semantic versioning" diff --git a/composer.json b/composer.json index 3e53895..2fd5b41 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "eloquent/liberator", "description": "A proxy for circumventing PHP access modifier restrictions.", - "keywords": ["access","modifier","object","proxy","private","protected","reflection"], + "keywords": ["access", "modifier", "object", "proxy", "private", "protected", "reflection"], "homepage": "https://github.com/eloquent/liberator", "license": "MIT", "authors": [ @@ -12,15 +12,15 @@ } ], "require": { - "php": ">=5.3.0", - "eloquent/pops": "~3" + "php": ">=5.3", + "eloquent/pops": "~4.1.0" }, "require-dev": { - "icecave/archer": "~0.2" + "icecave/archer": "~1" }, "autoload": { - "psr-0": { - "Eloquent\\Liberator": "src" + "psr-4": { + "Eloquent\\Liberator\\": "src" } } } diff --git a/composer.lock b/composer.lock index d4d1d43..007539c 100644 --- a/composer.lock +++ b/composer.lock @@ -1,27 +1,34 @@ { - "hash": "01616caf6008c198d376a6a45b115ad7", + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" + ], + "hash": "79799b8249b429d0b5eaf3d45440abc4", "packages": [ { "name": "eloquent/pops", - "version": "3.1.0", + "version": "4.1.0", "source": { "type": "git", - "url": "git://github.com/eloquent/pops.git", - "reference": "3.1.0" + "url": "https://github.com/eloquent/pops.git", + "reference": "80dbee5422347dc581d38ade92001509dce34926" }, "dist": { "type": "zip", - "url": "https://github.com/eloquent/pops/zipball/3.1.0", - "reference": "3.1.0", + "url": "https://api.github.com/repos/eloquent/pops/zipball/80dbee5422347dc581d38ade92001509dce34926", + "reference": "80dbee5422347dc581d38ade92001509dce34926", "shasum": "" }, "require": { - "php": ">=5.3.0" + "php": ">=5.3" + }, + "require-dev": { + "icecave/archer": "~1" }, "type": "library", "autoload": { - "psr-0": { - "Eloquent\\Pops": "src" + "psr-4": { + "Eloquent\\Pops\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -38,33 +45,191 @@ "description": "PHP object proxy system.", "homepage": "https://github.com/eloquent/pops", "keywords": [ - "escaping", + "method", "object", + "property", "proxy" ], - "time": "2012-08-02 06:17:58" + "time": "2014-02-09 10:09:42" } ], "packages-dev": [ + { + "name": "dflydev/markdown", + "version": "v1.0.3", + "source": { + "type": "git", + "url": "https://github.com/dflydev/dflydev-markdown.git", + "reference": "6baed9b50f29c980795b6656d43722aadb126f7e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/dflydev/dflydev-markdown/zipball/6baed9b50f29c980795b6656d43722aadb126f7e", + "reference": "6baed9b50f29c980795b6656d43722aadb126f7e", + "shasum": "" + }, + "require": { + "php": ">=5.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-0": { + "dflydev\\markdown": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Dragonfly Development Inc.", + "email": "info@dflydev.com", + "homepage": "http://dflydev.com" + }, + { + "name": "Beau Simensen", + "email": "beau@dflydev.com", + "homepage": "http://beausimensen.com" + }, + { + "name": "Michel Fortin", + "homepage": "http://michelf.com" + }, + { + "name": "John Gruber", + "homepage": "http://daringfireball.net" + } + ], + "description": "PHP Markdown & Extra", + "homepage": "http://github.com/dflydev/dflydev-markdown", + "keywords": [ + "markdown" + ], + "time": "2013-09-23 12:00:18" + }, + { + "name": "guzzle/guzzle", + "version": "v3.8.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "4de0618a01b34aa1c8c33a3f13f396dcd3882eba" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/4de0618a01b34aa1c8c33a3f13f396dcd3882eba", + "reference": "4de0618a01b34aa1c8c33a3f13f396dcd3882eba", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "php": ">=5.3.3", + "symfony/event-dispatcher": ">=2.1" + }, + "replace": { + "guzzle/batch": "self.version", + "guzzle/cache": "self.version", + "guzzle/common": "self.version", + "guzzle/http": "self.version", + "guzzle/inflection": "self.version", + "guzzle/iterator": "self.version", + "guzzle/log": "self.version", + "guzzle/parser": "self.version", + "guzzle/plugin": "self.version", + "guzzle/plugin-async": "self.version", + "guzzle/plugin-backoff": "self.version", + "guzzle/plugin-cache": "self.version", + "guzzle/plugin-cookie": "self.version", + "guzzle/plugin-curlauth": "self.version", + "guzzle/plugin-error-response": "self.version", + "guzzle/plugin-history": "self.version", + "guzzle/plugin-log": "self.version", + "guzzle/plugin-md5": "self.version", + "guzzle/plugin-mock": "self.version", + "guzzle/plugin-oauth": "self.version", + "guzzle/service": "self.version", + "guzzle/stream": "self.version" + }, + "require-dev": { + "doctrine/cache": "*", + "monolog/monolog": "1.*", + "phpunit/phpunit": "3.7.*", + "psr/log": "1.0.*", + "symfony/class-loader": "*", + "zendframework/zend-cache": "<2.3", + "zendframework/zend-log": "<2.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.8-dev" + } + }, + "autoload": { + "psr-0": { + "Guzzle": "src/", + "Guzzle\\Tests": "tests/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Guzzle Community", + "homepage": "https://github.com/guzzle/guzzle/contributors" + } + ], + "description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "rest", + "web service" + ], + "time": "2014-01-28 22:29:15" + }, { "name": "icecave/archer", - "version": "0.2.1", + "version": "1.1.2", "source": { "type": "git", "url": "https://github.com/IcecaveStudios/archer.git", - "reference": "0.2.1" + "reference": "c8f777640f216f75d10905619135d4f92bb0223f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/IcecaveStudios/archer/zipball/0.2.1", - "reference": "0.2.1", + "url": "https://api.github.com/repos/IcecaveStudios/archer/zipball/c8f777640f216f75d10905619135d4f92bb0223f", + "reference": "c8f777640f216f75d10905619135d4f92bb0223f", "shasum": "" }, "require": { - "phake/phake": ">=1.0,<2.0", + "phake/phake": "~1", "php": ">=5.3", - "symfony/console": ">=2.0,<3.0", - "symfony/process": ">=2.0,<3.0" + "sami/sami": "~1.1.0", + "satooshi/php-coveralls": "~0.6", + "symfony/console": "~2", + "symfony/process": "~2" + }, + "require-dev": { + "eloquent/liberator": "~1", + "symfony/event-dispatcher": "~2.1" }, "suggest": { "ext-openssl": "OpenSSL is required to encrypt GitHub OAuth tokens for artifact publication." @@ -76,7 +241,7 @@ "type": "library", "autoload": { "psr-0": { - "Icecave\\Archer": "lib" + "Icecave\\Archer": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -91,34 +256,83 @@ }, { "name": "James Harris", - "email": "james.harris@icecave.com.au" + "email": "james.harris@icecave.com.au", + "homepage": "https://github.com/jmalloc" } ], - "description": "PHP testing and continuous integration by convention.", + "description": "Testing, CI and documentation of PHP projects by convention.", "homepage": "https://github.com/IcecaveStudios/archer", "keywords": [ + "api", "artifacts", + "convention", "coverage", + "documentation", "phake", "phpunit", + "project", "test", "testing", "unit" ], - "time": "2013-02-27 04:42:20" + "time": "2014-01-21 01:56:19" + }, + { + "name": "nikic/php-parser", + "version": "v0.9.4", + "source": { + "type": "git", + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "1e5e280ae88a27effa2ae4aa2bd088494ed8594f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/1e5e280ae88a27effa2ae4aa2bd088494ed8594f", + "reference": "1e5e280ae88a27effa2ae4aa2bd088494ed8594f", + "shasum": "" + }, + "require": { + "php": ">=5.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.9-dev" + } + }, + "autoload": { + "psr-0": { + "PHPParser": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov" + } + ], + "description": "A PHP parser written in PHP", + "keywords": [ + "parser", + "php" + ], + "time": "2013-08-25 17:11:40" }, { "name": "phake/phake", "version": "v1.0.3", "source": { "type": "git", - "url": "git://github.com/mlively/Phake.git", - "reference": "v1.0.3" + "url": "https://github.com/mlively/Phake.git", + "reference": "4d822246b401f4dc609500d47e42dac8df645f4f" }, "dist": { "type": "zip", - "url": "https://github.com/mlively/Phake/zipball/v1.0.3", - "reference": "v1.0.3", + "url": "https://api.github.com/repos/mlively/Phake/zipball/4d822246b401f4dc609500d47e42dac8df645f4f", + "reference": "4d822246b401f4dc609500d47e42dac8df645f4f", "shasum": "" }, "require": { @@ -149,30 +363,293 @@ "mock", "testing" ], - "time": "2012-05-14 08:06:51" + "time": "2012-05-14 15:06:51" + }, + { + "name": "pimple/pimple", + "version": "v1.0.2", + "source": { + "type": "git", + "url": "https://github.com/fabpot/Pimple.git", + "reference": "ae11e57e8c2bb414b2ff93396dbbfc0eb92feb94" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/fabpot/Pimple/zipball/ae11e57e8c2bb414b2ff93396dbbfc0eb92feb94", + "reference": "ae11e57e8c2bb414b2ff93396dbbfc0eb92feb94", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Pimple": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Pimple is a simple Dependency Injection Container for PHP 5.3", + "homepage": "http://pimple.sensiolabs.org", + "keywords": [ + "container", + "dependency injection" + ], + "time": "2013-03-08 08:21:40" + }, + { + "name": "psr/log", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/fe0936ee26643249e916849d48e3a51d5f5e278b", + "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b", + "shasum": "" + }, + "type": "library", + "autoload": { + "psr-0": { + "Psr\\Log\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2012-12-21 11:40:51" + }, + { + "name": "sami/sami", + "version": "v1.1", + "source": { + "type": "git", + "url": "https://github.com/fabpot/Sami.git", + "reference": "46c58957ce4823c613e8535626b81e2fd80a9865" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/fabpot/Sami/zipball/46c58957ce4823c613e8535626b81e2fd80a9865", + "reference": "46c58957ce4823c613e8535626b81e2fd80a9865", + "shasum": "" + }, + "require": { + "dflydev/markdown": "1.0.*", + "nikic/php-parser": "0.9.*", + "php": ">=5.3.0", + "pimple/pimple": "1.0.*", + "symfony/console": "~2.1", + "symfony/filesystem": "~2.1", + "symfony/finder": "~2.1", + "symfony/process": "~2.1", + "symfony/yaml": "~2.1", + "twig/twig": "1.*" + }, + "bin": [ + "sami.php" + ], + "type": "application", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-0": { + "Sami": "." + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Sami, an API documentation generator", + "homepage": "http://sami.sensiolabs.org", + "keywords": [ + "phpdoc" + ], + "time": "2013-08-04 13:56:41" + }, + { + "name": "satooshi/php-coveralls", + "version": "v0.6.1", + "source": { + "type": "git", + "url": "https://github.com/satooshi/php-coveralls.git", + "reference": "dd0df95bd37a7cf5c5c50304dfe260ffe4b50760" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/satooshi/php-coveralls/zipball/dd0df95bd37a7cf5c5c50304dfe260ffe4b50760", + "reference": "dd0df95bd37a7cf5c5c50304dfe260ffe4b50760", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "ext-json": "*", + "ext-simplexml": "*", + "guzzle/guzzle": ">=3.0", + "php": ">=5.3", + "psr/log": "1.0.0", + "symfony/config": ">=2.0", + "symfony/console": ">=2.0", + "symfony/stopwatch": ">=2.2", + "symfony/yaml": ">=2.0" + }, + "require-dev": { + "apigen/apigen": "2.8.*@stable", + "pdepend/pdepend": "dev-master", + "phpmd/phpmd": "dev-master", + "phpunit/php-invoker": ">=1.1.0,<1.2.0", + "phpunit/phpunit": "3.7.*@stable", + "sebastian/finder-facade": "dev-master", + "sebastian/phpcpd": "1.4.*@stable", + "squizlabs/php_codesniffer": "1.4.*@stable", + "theseer/fdomdocument": "dev-master" + }, + "bin": [ + "composer/bin/coveralls" + ], + "type": "library", + "autoload": { + "psr-0": { + "Contrib\\Component": "src/", + "Contrib\\Bundle": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kitamura Satoshi", + "email": "with.no.parachute@gmail.com", + "homepage": "https://www.facebook.com/satooshi.jp" + } + ], + "description": "PHP client library for Coveralls API", + "homepage": "https://github.com/satooshi/php-coveralls", + "keywords": [ + "ci", + "coverage", + "github", + "test" + ], + "time": "2013-05-04 08:07:33" + }, + { + "name": "symfony/config", + "version": "v2.4.1", + "target-dir": "Symfony/Component/Config", + "source": { + "type": "git", + "url": "https://github.com/symfony/Config.git", + "reference": "27d0b35879ebefcfee6d218512c32ab2d6cd6a6a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/Config/zipball/27d0b35879ebefcfee6d218512c32ab2d6cd6a6a", + "reference": "27d0b35879ebefcfee6d218512c32ab2d6cd6a6a", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "symfony/filesystem": "~2.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.4-dev" + } + }, + "autoload": { + "psr-0": { + "Symfony\\Component\\Config\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony Config Component", + "homepage": "http://symfony.com", + "time": "2014-01-01 08:14:50" }, { "name": "symfony/console", - "version": "v2.2.0", + "version": "v2.4.1", "target-dir": "Symfony/Component/Console", "source": { "type": "git", "url": "https://github.com/symfony/Console.git", - "reference": "v2.2.0" + "reference": "4c1ed2ff514bd85ee186eebb010ccbdeeab05af7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Console/zipball/v2.2.0", - "reference": "v2.2.0", + "url": "https://api.github.com/repos/symfony/Console/zipball/4c1ed2ff514bd85ee186eebb010ccbdeeab05af7", + "reference": "4c1ed2ff514bd85ee186eebb010ccbdeeab05af7", "shasum": "" }, "require": { "php": ">=5.3.3" }, + "require-dev": { + "symfony/event-dispatcher": "~2.1" + }, + "suggest": { + "symfony/event-dispatcher": "" + }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.2-dev" + "dev-master": "2.4-dev" } }, "autoload": { @@ -196,21 +673,169 @@ ], "description": "Symfony Console Component", "homepage": "http://symfony.com", - "time": "2013-03-01 06:43:14" + "time": "2014-01-01 08:14:50" + }, + { + "name": "symfony/event-dispatcher", + "version": "v2.4.1", + "target-dir": "Symfony/Component/EventDispatcher", + "source": { + "type": "git", + "url": "https://github.com/symfony/EventDispatcher.git", + "reference": "e3ba42f6a70554ed05749e61b829550f6ac33601" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/e3ba42f6a70554ed05749e61b829550f6ac33601", + "reference": "e3ba42f6a70554ed05749e61b829550f6ac33601", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "symfony/dependency-injection": "~2.0" + }, + "suggest": { + "symfony/dependency-injection": "", + "symfony/http-kernel": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.4-dev" + } + }, + "autoload": { + "psr-0": { + "Symfony\\Component\\EventDispatcher\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony EventDispatcher Component", + "homepage": "http://symfony.com", + "time": "2013-12-28 08:12:03" + }, + { + "name": "symfony/filesystem", + "version": "v2.4.1", + "target-dir": "Symfony/Component/Filesystem", + "source": { + "type": "git", + "url": "https://github.com/symfony/Filesystem.git", + "reference": "b3c3b5a8108b3e5d604dc23241b4ea84a067fc78" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/Filesystem/zipball/b3c3b5a8108b3e5d604dc23241b4ea84a067fc78", + "reference": "b3c3b5a8108b3e5d604dc23241b4ea84a067fc78", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.4-dev" + } + }, + "autoload": { + "psr-0": { + "Symfony\\Component\\Filesystem\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony Filesystem Component", + "homepage": "http://symfony.com", + "time": "2013-12-31 13:43:26" + }, + { + "name": "symfony/finder", + "version": "v2.4.1", + "target-dir": "Symfony/Component/Finder", + "source": { + "type": "git", + "url": "https://github.com/symfony/Finder.git", + "reference": "6904345cf2b3bbab1f6d6e4ce1724cb99df9f00a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/Finder/zipball/6904345cf2b3bbab1f6d6e4ce1724cb99df9f00a", + "reference": "6904345cf2b3bbab1f6d6e4ce1724cb99df9f00a", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.4-dev" + } + }, + "autoload": { + "psr-0": { + "Symfony\\Component\\Finder\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "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", + "time": "2014-01-01 08:14:50" }, { "name": "symfony/process", - "version": "v2.2.0", + "version": "v2.4.1", "target-dir": "Symfony/Component/Process", "source": { "type": "git", "url": "https://github.com/symfony/Process.git", - "reference": "v2.2.0-RC3" + "reference": "58fdccb311e44f28866f976c2d7b3227e9f713db" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Process/zipball/v2.2.0-RC3", - "reference": "v2.2.0-RC3", + "url": "https://api.github.com/repos/symfony/Process/zipball/58fdccb311e44f28866f976c2d7b3227e9f713db", + "reference": "58fdccb311e44f28866f976c2d7b3227e9f713db", "shasum": "" }, "require": { @@ -219,7 +844,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.2-dev" + "dev-master": "2.4-dev" } }, "autoload": { @@ -243,7 +868,150 @@ ], "description": "Symfony Process Component", "homepage": "http://symfony.com", - "time": "2013-02-18 21:28:10" + "time": "2014-01-05 02:10:50" + }, + { + "name": "symfony/stopwatch", + "version": "v2.4.1", + "target-dir": "Symfony/Component/Stopwatch", + "source": { + "type": "git", + "url": "https://github.com/symfony/Stopwatch.git", + "reference": "c8e21e1380c7eef6197a8165620da8457b7c69a5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/Stopwatch/zipball/c8e21e1380c7eef6197a8165620da8457b7c69a5", + "reference": "c8e21e1380c7eef6197a8165620da8457b7c69a5", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.4-dev" + } + }, + "autoload": { + "psr-0": { + "Symfony\\Component\\Stopwatch\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony Stopwatch Component", + "homepage": "http://symfony.com", + "time": "2013-12-12 16:06:47" + }, + { + "name": "symfony/yaml", + "version": "v2.4.1", + "target-dir": "Symfony/Component/Yaml", + "source": { + "type": "git", + "url": "https://github.com/symfony/Yaml.git", + "reference": "4e1a237fc48145fae114b96458d799746ad89aa0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/4e1a237fc48145fae114b96458d799746ad89aa0", + "reference": "4e1a237fc48145fae114b96458d799746ad89aa0", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.4-dev" + } + }, + "autoload": { + "psr-0": { + "Symfony\\Component\\Yaml\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony Yaml Component", + "homepage": "http://symfony.com", + "time": "2013-12-28 08:12:03" + }, + { + "name": "twig/twig", + "version": "v1.15.0", + "source": { + "type": "git", + "url": "https://github.com/fabpot/Twig.git", + "reference": "85e4ff98000157ff753d934b9f13659a953f5666" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/fabpot/Twig/zipball/85e4ff98000157ff753d934b9f13659a953f5666", + "reference": "85e4ff98000157ff753d934b9f13659a953f5666", + "shasum": "" + }, + "require": { + "php": ">=5.2.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.15-dev" + } + }, + "autoload": { + "psr-0": { + "Twig_": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Armin Ronacher", + "email": "armin.ronacher@active-4.com" + } + ], + "description": "Twig, the flexible, fast, and secure template language for PHP", + "homepage": "http://twig.sensiolabs.org", + "keywords": [ + "templating" + ], + "time": "2013-12-06 07:47:10" } ], "aliases": [ @@ -252,5 +1020,11 @@ "minimum-stability": "stable", "stability-flags": [ + ], + "platform": { + "php": ">=5.3" + }, + "platform-dev": [ + ] } diff --git a/src/Eloquent/Liberator/Liberator.php b/src/Eloquent/Liberator/Liberator.php deleted file mode 100644 index 426280b..0000000 --- a/src/Eloquent/Liberator/Liberator.php +++ /dev/null @@ -1,78 +0,0 @@ -liberatorReflector = new ReflectionClass($class); - } - - /** - * @param string $method - * @param array &$arguments - * - * @return mixed - */ - public function popsCall($method, array &$arguments) - { - if ($this->liberatorReflector->hasMethod($method)) { - $method = $this->liberatorReflector->getMethod($method); - $method->setAccessible(true); - - return static::popsProxySubValue( - $method->invokeArgs(null, $arguments), - $this->popsRecursive - ); - } - - return parent::popsCall($method, $arguments); - } - - /** - * @param string $method - * @param array &$arguments - * - * @return mixed - */ - public function liberatorCall($method, array &$arguments) - { - return $this->popsCall($method, $arguments); - } - - /** - * @param string $property - * @param mixed $value - */ - public function __set($property, $value) - { - if ($propertyReflector = $this->liberatorPropertyReflector($property)) { - $propertyReflector->setValue(null, $value); - - return; - } - - throw new LogicException( - 'Access to undeclared static property: '. - $this->popsClass. - '::$'. - $property - ); - } - - /** - * @param string $property - * - * @return mixed - */ - public function __get($property) - { - if ($propertyReflector = $this->liberatorPropertyReflector($property)) { - return static::popsProxySubValue( - $propertyReflector->getValue(null), - $this->popsRecursive - ); - } - - throw new LogicException( - 'Access to undeclared static property: '. - $this->popsClass. - '::$'. - $property - ); - } - - /** - * @param string $property - * - * @return boolean - */ - public function __isset($property) - { - if ($propertyReflector = $this->liberatorPropertyReflector($property)) { - return null !== $propertyReflector->getValue(null); - } - - return parent::__isset($property); - } - - /** - * @param string $property - */ - public function __unset($property) - { - if ($propertyReflector = $this->liberatorPropertyReflector($property)) { - $propertyReflector->setValue(null, null); - - return; - } - - throw new LogicException( - 'Access to undeclared static property: '. - $this->popsClass. - '::$'. - $property - ); - } - - /** - * @return string - */ - protected static function popsProxyClass() - { - return __NAMESPACE__.'\Liberator'; - } - - /** - * @param string $property - * - * @return ReflectionProperty|null - */ - protected function liberatorPropertyReflector($property) - { - $classReflector = $this->liberatorReflector; - - while ($classReflector) { - if ($classReflector->hasProperty($property)) { - $propertyReflector = $classReflector->getProperty($property); - $propertyReflector->setAccessible(true); - - return $propertyReflector; - } - - $classReflector = $classReflector->getParentClass(); - } - - return null; - } - - /** - * @var ReflectionClass - */ - protected $liberatorReflector; -} diff --git a/src/Eloquent/Liberator/LiberatorObject.php b/src/Eloquent/Liberator/LiberatorObject.php deleted file mode 100644 index 72b4fbb..0000000 --- a/src/Eloquent/Liberator/LiberatorObject.php +++ /dev/null @@ -1,155 +0,0 @@ -liberatorReflector = new ReflectionObject($object); - } - - /** - * @param string $method - * @param array &$arguments - * - * @return mixed - */ - public function popsCall($method, array &$arguments) - { - if ($this->liberatorReflector->hasMethod($method)) { - $method = $this->liberatorReflector->getMethod($method); - $method->setAccessible(true); - - return $this->popsProxySubValue( - $method->invokeArgs($this->popsObject, $arguments) - ); - } - - return parent::popsCall($method, $arguments); - } - - /** - * @param string $method - * @param array &$arguments - * - * @return mixed - */ - public function liberatorCall($method, array &$arguments) - { - return $this->popsCall($method, $arguments); - } - - /** - * @param string $property - * @param mixed $value - */ - public function __set($property, $value) - { - if ($propertyReflector = $this->liberatorPropertyReflector($property)) { - $propertyReflector->setValue($this->popsObject, $value); - - return; - } - - parent::__set($property, $value); - } - - /** - * @param string $property - * - * @return mixed - */ - public function __get($property) - { - if ($propertyReflector = $this->liberatorPropertyReflector($property)) { - return $this->popsProxySubValue( - $propertyReflector->getValue($this->popsObject) - ); - } - - return parent::__get($property); - } - - /** - * @param string $property - * - * @return boolean - */ - public function __isset($property) - { - if ($propertyReflector = $this->liberatorPropertyReflector($property)) { - return null !== $propertyReflector->getValue($this->popsObject); - } - - return parent::__isset($property); - } - - /** - * @param string $property - */ - public function __unset($property) - { - if ($propertyReflector = $this->liberatorPropertyReflector($property)) { - $propertyReflector->setValue($this->popsObject, null); - - return; - } - - parent::__unset($property); - } - - /** - * @return string - */ - protected static function popsProxyClass() - { - return __NAMESPACE__.'\Liberator'; - } - - /** - * @param string $property - * - * @return ReflectionProperty|null - */ - protected function liberatorPropertyReflector($property) - { - $classReflector = $this->liberatorReflector; - - while ($classReflector) { - if ($classReflector->hasProperty($property)) { - $propertyReflector = $classReflector->getProperty($property); - $propertyReflector->setAccessible(true); - - return $propertyReflector; - } - - $classReflector = $classReflector->getParentClass(); - } - - return null; - } - - /** - * @var ReflectionObject - */ - protected $liberatorReflector; -} diff --git a/src/Eloquent/Liberator/LiberatorProxy.php b/src/Eloquent/Liberator/LiberatorProxy.php deleted file mode 100644 index bdf73e6..0000000 --- a/src/Eloquent/Liberator/LiberatorProxy.php +++ /dev/null @@ -1,18 +0,0 @@ -popsCall($method, $arguments); + } + + /** + * Set the wrapped class. + * + * @param string $class The class to wrap. + * + * @throws InvalidTypeException If the supplied value is not the correct type. + */ + public function setPopsValue($class) + { + parent::setPopsValue($class); + + $this->liberatorReflector = new ReflectionClass($class); + } + + /** + * Call a static method on the proxied class with support for by-reference + * arguments. + * + * @param string $method The name of the method to call. + * @param array &$arguments The arguments. + * + * @return mixed The result of the method call. + */ + public function popsCall($method, array &$arguments) + { + if ($this->liberatorReflector()->hasMethod($method)) { + $method = $this->liberatorReflector()->getMethod($method); + $method->setAccessible(true); + + return static::popsProxySubValue( + $method->invokeArgs(null, $arguments), + $this->isPopsRecursive() + ); + } + + return parent::popsCall($method, $arguments); + } + + /** + * Set the value of a static property on the proxied class. + * + * @param string $property The name of the property to set. + * @param mixed $value The new value. + */ + public function __set($property, $value) + { + if ($propertyReflector = $this->liberatorPropertyReflector($property)) { + $propertyReflector->setValue(null, $value); + + return; + } + + throw new LogicException( + sprintf( + 'Access to undeclared static property: %s::$%s', + $this->popsValue(), + $property + ) + ); + } + + /** + * Get the value of a static property on the proxied class. + * + * @param string $property The name of the property to get. + * + * @return mixed The value of the property. + */ + public function __get($property) + { + if ($propertyReflector = $this->liberatorPropertyReflector($property)) { + return static::popsProxySubValue( + $propertyReflector->getValue(null), + $this->isPopsRecursive() + ); + } + + throw new LogicException( + sprintf( + 'Access to undeclared static property: %s::$%s', + $this->popsValue(), + $property + ) + ); + } + + /** + * Returns true if the supplied static property exists on the proxied class. + * + * @param string $property The name of the property to search for. + * + * @return boolean True if the property exists. + */ + public function __isset($property) + { + if ($propertyReflector = $this->liberatorPropertyReflector($property)) { + return null !== $propertyReflector->getValue(null); + } + + return parent::__isset($property); + } + + /** + * Set the value of a static property on the proxied class to null. + * + * @param string $property The name of the property to set. + */ + public function __unset($property) + { + if ($propertyReflector = $this->liberatorPropertyReflector($property)) { + $propertyReflector->setValue(null, null); + + return; + } + + throw new LogicException( + sprintf( + 'Access to undeclared static property: %s::$%s', + $this->popsValue(), + $property + ) + ); + } + + /** + * Get the proxy class. + * + * @return string The proxy class. + */ + protected static function popsProxyClass() + { + return 'Eloquent\Liberator\Liberator'; + } + + /** + * Get the class reflector. + * + * @return ReflectionClass The class reflector. + */ + protected function liberatorReflector() + { + return $this->liberatorReflector; + } + + /** + * Get a property reflector. + * + * @param string $property The property name. + * + * @return ReflectionProperty|null The property reflector, or null if no such property exists. + */ + protected function liberatorPropertyReflector($property) + { + $classReflector = $this->liberatorReflector(); + + while ($classReflector) { + if ($classReflector->hasProperty($property)) { + $propertyReflector = $classReflector->getProperty($property); + $propertyReflector->setAccessible(true); + + return $propertyReflector; + } + + $classReflector = $classReflector->getParentClass(); + } + + return null; + } + + private $liberatorReflector; +} diff --git a/src/LiberatorObject.php b/src/LiberatorObject.php new file mode 100644 index 0000000..1ae3a5a --- /dev/null +++ b/src/LiberatorObject.php @@ -0,0 +1,187 @@ +popsCall($method, $arguments); + } + + /** + * Set the wrapped object. + * + * @param string $object The object to wrap. + * + * @throws InvalidTypeException If the supplied value is not the correct type. + */ + public function setPopsValue($object) + { + parent::setPopsValue($object); + + $this->liberatorReflector = new ReflectionObject($object); + } + + /** + * Call a method on the wrapped object with support for by-reference + * arguments. + * + * @param string $method The name of the method to call. + * @param array &$arguments The arguments. + * + * @return mixed The result of the method call. + */ + public function popsCall($method, array &$arguments) + { + if ($this->liberatorReflector->hasMethod($method)) { + $method = $this->liberatorReflector->getMethod($method); + $method->setAccessible(true); + + return $this->popsProxySubValue( + $method->invokeArgs($this->popsValue(), $arguments) + ); + } + + return parent::popsCall($method, $arguments); + } + + /** + * Set the value of a property on the wrapped object. + * + * @param string $property The property name. + * @param mixed $value The new value. + */ + public function __set($property, $value) + { + if ($propertyReflector = $this->liberatorPropertyReflector($property)) { + $propertyReflector->setValue($this->popsValue(), $value); + + return; + } + + parent::__set($property, $value); + } + + /** + * Get the value of a property from the wrapped object. + * + * @param string $property The property name. + * + * @return mixed The property value. + */ + public function __get($property) + { + if ($propertyReflector = $this->liberatorPropertyReflector($property)) { + return $this->popsProxySubValue( + $propertyReflector->getValue($this->popsValue()) + ); + } + + return parent::__get($property); + } + + /** + * Returns true if the property exists on the wrapped object. + * + * @param string $property The name of the property to search for. + * + * @return boolean True if the property exists. + */ + public function __isset($property) + { + if ($propertyReflector = $this->liberatorPropertyReflector($property)) { + return null !== $propertyReflector->getValue($this->popsValue()); + } + + return parent::__isset($property); + } + + /** + * Unset a property from the wrapped object. + * + * @param string $property The property name. + */ + public function __unset($property) + { + if ($propertyReflector = $this->liberatorPropertyReflector($property)) { + $propertyReflector->setValue($this->popsValue(), null); + + return; + } + + parent::__unset($property); + } + + /** + * Get the proxy class. + * + * @return string The proxy class. + */ + protected static function popsProxyClass() + { + return 'Eloquent\Liberator\Liberator'; + } + + /** + * Get the class reflector. + * + * @return ReflectionObject The class reflector. + */ + protected function liberatorReflector() + { + return $this->liberatorReflector; + } + + /** + * Get a property reflector. + * + * @param string $property The property name. + * + * @return ReflectionProperty|null The property reflector, or null if no such property exists. + */ + protected function liberatorPropertyReflector($property) + { + $classReflector = $this->liberatorReflector(); + + while ($classReflector) { + if ($classReflector->hasProperty($property)) { + $propertyReflector = $classReflector->getProperty($property); + $propertyReflector->setAccessible(true); + + return $propertyReflector; + } + + $classReflector = $classReflector->getParentClass(); + } + + return null; + } + + private $liberatorReflector; +} diff --git a/src/LiberatorProxyInterface.php b/src/LiberatorProxyInterface.php new file mode 100644 index 0000000..4acf39b --- /dev/null +++ b/src/LiberatorProxyInterface.php @@ -0,0 +1,21 @@ +assertEquals( - 'foo is not so private...', - $liberator->foo('not so private...') - ); - $this->assertEquals( - 'mind = blown', - $liberator->bar.' = blown' - ); - } - - public function testDocumentationLiberatorClass() - { - $liberator = Liberator::liberateClass('SeriousBusiness'); - - $this->assertEquals( - 'baz is not so private...', - $liberator->baz('not so private...') - ); - $this->assertEquals( - 'mind = blown', - $liberator->qux.' = blown' - ); - } - - public function testDocumentationLiberatorClassStatic() - { - $liberatorClass = Liberator::liberateClassStatic('SeriousBusiness'); - - $this->assertEquals( - 'baz is not so private...', - $liberatorClass::baz('not so private...') - ); - $this->assertEquals( - 'mind = blown', - $liberatorClass::liberator()->qux.' = blown' - ); - } -} diff --git a/test/suite/Eloquent/Liberator/LiberatorArrayTest.php b/test/suite/Eloquent/Liberator/LiberatorArrayTest.php deleted file mode 100644 index 98d456d..0000000 --- a/test/suite/Eloquent/Liberator/LiberatorArrayTest.php +++ /dev/null @@ -1,73 +0,0 @@ - new Object, - 'array' => array( - 'object' => new Object, - 'array' => array(), - 'string' => 'string', - ), - 'string' => 'string', - ); - $recursiveProxy = new LiberatorArray($array, true); - - $this->assertInstanceOf( - __NAMESPACE__.'\LiberatorObject', - $recursiveProxy['object'] - ); - $this->assertInstanceOf( - __NAMESPACE__.'\LiberatorObject', - $recursiveProxy['object']->object() - ); - $this->assertInstanceOf( - __NAMESPACE__.'\LiberatorArray', - $recursiveProxy['object']->arrayValue() - ); - $this->assertInstanceOf( - 'Eloquent\Pops\ProxyPrimitive', - $recursiveProxy['object']->string() - ); - $this->assertInstanceOf( - __NAMESPACE__.'\LiberatorArray', - $recursiveProxy['array'] - ); - $this->assertInstanceOf( - __NAMESPACE__.'\LiberatorObject', - $recursiveProxy['array']['object'] - ); - $this->assertInstanceOf( - __NAMESPACE__.'\LiberatorObject', - $recursiveProxy['array']['object']->object() - ); - $this->assertInstanceOf( - __NAMESPACE__.'\LiberatorArray', - $recursiveProxy['array']['array'] - ); - $this->assertInstanceOf( - 'Eloquent\Pops\ProxyPrimitive', - $recursiveProxy['array']['string'] - ); - $this->assertInstanceOf( - 'Eloquent\Pops\ProxyPrimitive', - $recursiveProxy['string'] - ); - } -} diff --git a/test/suite/Eloquent/Liberator/LiberatorClassTest.php b/test/suite/Eloquent/Liberator/LiberatorClassTest.php deleted file mode 100644 index 7a08842..0000000 --- a/test/suite/Eloquent/Liberator/LiberatorClassTest.php +++ /dev/null @@ -1,259 +0,0 @@ -_class = __NAMESPACE__.'\Test\Fixture\Object'; - $this->_proxy = new LiberatorClass($this->_class); - } - - public function fixtureData() - { - $data = array(); - - // #0: class with no inheritance - $class = __NAMESPACE__.'\Test\Fixture\Object'; - $proxy = new LiberatorClass($class); - $data[] = array($class, $proxy); - - // #1: child class - $class = __NAMESPACE__.'\Test\Fixture\ChildObject'; - $proxy = new LiberatorClass($class); - $data[] = array($class, $proxy); - - return $data; - } - - /** - * @dataProvider fixtureData - */ - public function testRecursive($class) - { - $recursiveProxy = new LiberatorClass($class, true); - - $this->assertInstanceOf( - __NAMESPACE__.'\LiberatorObject', - $recursiveProxy->staticObject() - ); - $this->assertInstanceOf( - __NAMESPACE__.'\LiberatorObject', - $recursiveProxy->staticObject()->object() - ); - $this->assertInstanceOf( - __NAMESPACE__.'\LiberatorArray', - $recursiveProxy->staticObject()->arrayValue() - ); - $this->assertInstanceOf( - 'Eloquent\Pops\ProxyPrimitive', - $recursiveProxy->staticObject()->string() - ); - $this->assertInstanceOf( - __NAMESPACE__.'\LiberatorArray', - $recursiveProxy->staticArray() - ); - $this->assertInstanceOf( - 'Eloquent\Pops\ProxyPrimitive', - $recursiveProxy->staticString() - ); - } - - /** - * @dataProvider fixtureData - */ - public function testCall($class, LiberatorClass $proxy) - { - $this->assertLiberatorCall( - $proxy, - 'staticPublicMethod', - array('foo', 'bar') - ); - $this->assertLiberatorCall( - $proxy, - 'staticProtectedMethod', - array('foo', 'bar') - ); - $this->assertLiberatorCall( - $proxy, - 'staticPrivateMethod', - array('foo', 'bar') - ); - $this->assertLiberatorCall( - $proxy, - 'foo', - array('bar', 'baz'), - true - ); - } - - public function testCallByReference() - { - $variable = null; - $arguments = array(&$variable, 'foo'); - $this->_proxy->liberatorCall('staticByReference', $arguments); - - $this->assertSame('foo', $variable); - } - - public function testCallByReferenceStatic() - { - $class = LiberatorClass::popsGenerateStaticClassProxy( - __NAMESPACE__.'\Test\Fixture\Object' - ); - $variable = null; - $arguments = array(&$variable, 'foo'); - $class::liberator()->liberatorCall('staticByReference', $arguments); - - $this->assertSame('foo', $variable); - } - - /** - * @dataProvider fixtureData - */ - public function testSetGet($class, LiberatorClass $proxy) - { - $this->assertTrue(isset($proxy->staticPublicProperty)); - $this->assertTrue(isset($proxy->staticProtectedProperty)); - $this->assertTrue(isset($proxy->staticPrivateProperty)); - $this->assertEquals( - 'staticPublicProperty', - $proxy->staticPublicProperty - ); - $this->assertEquals( - 'staticProtectedProperty', - $proxy->staticProtectedProperty - ); - $this->assertEquals( - 'staticPrivateProperty', - $proxy->staticPrivateProperty - ); - - $proxy->staticPublicProperty = 'foo'; - $proxy->staticProtectedProperty = 'bar'; - $proxy->staticPrivateProperty = 'baz'; - - $this->assertTrue(isset($proxy->staticPublicProperty)); - $this->assertTrue(isset($proxy->staticProtectedProperty)); - $this->assertTrue(isset($proxy->staticPrivateProperty)); - $this->assertEquals('foo', $proxy->staticPublicProperty); - $this->assertEquals('bar', $proxy->staticProtectedProperty); - $this->assertEquals('baz', $proxy->staticPrivateProperty); - - unset($proxy->staticPublicProperty); - unset($proxy->staticProtectedProperty); - unset($proxy->staticPrivateProperty); - - $this->assertFalse(isset($proxy->staticPublicProperty)); - $this->assertFalse(isset($proxy->staticProtectedProperty)); - $this->assertFalse(isset($proxy->staticPrivateProperty)); - - $proxy->staticPublicProperty = 'staticPublicProperty'; - $proxy->staticProtectedProperty = 'staticProtectedProperty'; - $proxy->staticPrivateProperty = 'staticPrivateProperty'; - - $this->assertTrue(isset($proxy->staticPublicProperty)); - $this->assertTrue(isset($proxy->staticProtectedProperty)); - $this->assertTrue(isset($proxy->staticPrivateProperty)); - $this->assertEquals( - 'staticPublicProperty', - $proxy->staticPublicProperty - ); - $this->assertEquals( - 'staticProtectedProperty', - $proxy->staticProtectedProperty - ); - $this->assertEquals( - 'staticPrivateProperty', - $proxy->staticPrivateProperty - ); - - $this->assertFalse(isset($proxy->foo)); - } - - public function setGetFailureData() - { - return array( - array('__set', array('foo', 'bar')), - array('__get', array('foo')), - array('__unset', array('foo')), - ); - } - - /** - * @dataProvider setGetFailureData - */ - public function testSetGetFailure($method, array $arguments) - { - $this->setExpectedException( - 'LogicException', - 'Access to undeclared static property: '. - __NAMESPACE__.'\Test\Fixture\Object::$'. - $arguments[0] - ); - call_user_func_array(array($this->_proxy, $method), $arguments); - } - - public function testPopsGenerateStaticClassProxy() - { - $class = LiberatorClass::popsGenerateStaticClassProxy( - __NAMESPACE__.'\Test\Fixture\Object' - ); - - $this->assertTrue(class_exists($class, false)); - $this->assertTrue( - is_subclass_of($class, __NAMESPACE__.'\LiberatorClass') - ); - - $expected = new $class(__NAMESPACE__.'\Test\Fixture\Object'); - $proxy = $class::liberator(); - - $this->assertEquals($expected, $proxy); - - // recursive tests - $class = LiberatorClass::popsGenerateStaticClassProxy( - __NAMESPACE__.'\Test\Fixture\Object', - true - ); - - $this->assertInstanceOf( - __NAMESPACE__.'\LiberatorObject', - $class::staticObject() - ); - $this->assertInstanceOf( - __NAMESPACE__.'\LiberatorObject', - $class::staticObject()->object() - ); - $this->assertInstanceOf( - __NAMESPACE__.'\LiberatorArray', - $class::staticObject()->arrayValue() - ); - $this->assertInstanceOf( - 'Eloquent\Pops\ProxyPrimitive', - $class::staticObject()->string() - ); - $this->assertInstanceOf( - __NAMESPACE__.'\LiberatorArray', - $class::staticArray() - ); - $this->assertInstanceOf( - 'Eloquent\Pops\ProxyPrimitive', - $class::staticString() - ); - } -} diff --git a/test/suite/FunctionalTest.php b/test/suite/FunctionalTest.php new file mode 100644 index 0000000..5f0111b --- /dev/null +++ b/test/suite/FunctionalTest.php @@ -0,0 +1,40 @@ +assertEquals('foo is not so private...', $liberator->foo('not so private...')); + $this->assertEquals('mind = blown', $liberator->bar . ' = blown'); + } + + public function testDocumentationLiberatorClass() + { + $liberator = Liberator::liberateClass('SeriousBusiness'); + + $this->assertEquals('baz is not so private...', $liberator->baz('not so private...')); + $this->assertEquals('mind = blown', $liberator->qux . ' = blown'); + } + + public function testDocumentationLiberatorClassStatic() + { + $liberatorClass = Liberator::liberateClassStatic('SeriousBusiness'); + + $this->assertEquals('baz is not so private...', $liberatorClass::baz('not so private...')); + $this->assertEquals('mind = blown', $liberatorClass::liberator()->qux . ' = blown'); + } +} diff --git a/test/suite/LiberatorArrayTest.php b/test/suite/LiberatorArrayTest.php new file mode 100644 index 0000000..f967c5d --- /dev/null +++ b/test/suite/LiberatorArrayTest.php @@ -0,0 +1,43 @@ + new Object, + 'array' => array( + 'object' => new Object, + 'array' => array(), + 'string' => 'string', + ), + 'string' => 'string', + ); + $recursiveProxy = new LiberatorArray($array, true); + + $this->assertInstanceOf('Eloquent\Liberator\LiberatorObject', $recursiveProxy['object']); + $this->assertInstanceOf('Eloquent\Liberator\LiberatorObject', $recursiveProxy['object']->object()); + $this->assertInstanceOf('Eloquent\Liberator\LiberatorArray', $recursiveProxy['object']->arrayValue()); + $this->assertInstanceOf('Eloquent\Pops\ProxyPrimitive', $recursiveProxy['object']->string()); + $this->assertInstanceOf('Eloquent\Liberator\LiberatorArray', $recursiveProxy['array']); + $this->assertInstanceOf('Eloquent\Liberator\LiberatorObject', $recursiveProxy['array']['object']); + $this->assertInstanceOf('Eloquent\Liberator\LiberatorObject', $recursiveProxy['array']['object']->object()); + $this->assertInstanceOf('Eloquent\Liberator\LiberatorArray', $recursiveProxy['array']['array']); + $this->assertInstanceOf('Eloquent\Pops\ProxyPrimitive', $recursiveProxy['array']['string']); + $this->assertInstanceOf('Eloquent\Pops\ProxyPrimitive', $recursiveProxy['string']); + } +} diff --git a/test/suite/LiberatorClassTest.php b/test/suite/LiberatorClassTest.php new file mode 100644 index 0000000..2e4e6c9 --- /dev/null +++ b/test/suite/LiberatorClassTest.php @@ -0,0 +1,175 @@ +class = 'Eloquent\Liberator\Test\Fixture\Object'; + $this->proxy = new LiberatorClass($this->class); + } + + public function fixtureData() + { + $data = array(); + + $class = 'Eloquent\Liberator\Test\Fixture\Object'; + $proxy = new LiberatorClass($class); + $data['Class with no inheritance'] = array($class, $proxy); + + $class = 'Eloquent\Liberator\Test\Fixture\ChildObject'; + $proxy = new LiberatorClass($class); + $data['Child class'] = array($class, $proxy); + + return $data; + } + + /** + * @dataProvider fixtureData + */ + public function testRecursive($class) + { + $recursiveProxy = new LiberatorClass($class, true); + + $this->assertInstanceOf('Eloquent\Liberator\LiberatorObject', $recursiveProxy->staticObject()); + $this->assertInstanceOf('Eloquent\Liberator\LiberatorObject', $recursiveProxy->staticObject()->object()); + $this->assertInstanceOf('Eloquent\Liberator\LiberatorArray', $recursiveProxy->staticObject()->arrayValue()); + $this->assertInstanceOf('Eloquent\Pops\ProxyPrimitive', $recursiveProxy->staticObject()->string()); + $this->assertInstanceOf('Eloquent\Liberator\LiberatorArray', $recursiveProxy->staticArray()); + $this->assertInstanceOf('Eloquent\Pops\ProxyPrimitive', $recursiveProxy->staticString()); + } + + /** + * @dataProvider fixtureData + */ + public function testCall($class, LiberatorClass $proxy) + { + $this->assertLiberatorCall($proxy, 'staticPublicMethod', array('foo', 'bar')); + $this->assertLiberatorCall($proxy, 'staticProtectedMethod', array('foo', 'bar')); + $this->assertLiberatorCall($proxy, 'staticPrivateMethod', array('foo', 'bar')); + $this->assertLiberatorCall($proxy, 'foo', array('bar', 'baz'), true); + } + + public function testCallByReference() + { + $variable = null; + $arguments = array(&$variable, 'foo'); + $this->proxy->liberatorCall('staticByReference', $arguments); + + $this->assertSame('foo', $variable); + } + + public function testCallByReferenceStatic() + { + $class = LiberatorClass::popsGenerateStaticClassProxy('Eloquent\Liberator\Test\Fixture\Object'); + $variable = null; + $arguments = array(&$variable, 'foo'); + $class::liberator()->liberatorCall('staticByReference', $arguments); + + $this->assertSame('foo', $variable); + } + + /** + * @dataProvider fixtureData + */ + public function testSetGet($class, LiberatorClass $proxy) + { + $this->assertTrue(isset($proxy->staticPublicProperty)); + $this->assertTrue(isset($proxy->staticProtectedProperty)); + $this->assertTrue(isset($proxy->staticPrivateProperty)); + $this->assertEquals('staticPublicProperty', $proxy->staticPublicProperty); + $this->assertEquals('staticProtectedProperty', $proxy->staticProtectedProperty); + $this->assertEquals('staticPrivateProperty', $proxy->staticPrivateProperty); + + $proxy->staticPublicProperty = 'foo'; + $proxy->staticProtectedProperty = 'bar'; + $proxy->staticPrivateProperty = 'baz'; + + $this->assertTrue(isset($proxy->staticPublicProperty)); + $this->assertTrue(isset($proxy->staticProtectedProperty)); + $this->assertTrue(isset($proxy->staticPrivateProperty)); + $this->assertEquals('foo', $proxy->staticPublicProperty); + $this->assertEquals('bar', $proxy->staticProtectedProperty); + $this->assertEquals('baz', $proxy->staticPrivateProperty); + + unset($proxy->staticPublicProperty); + unset($proxy->staticProtectedProperty); + unset($proxy->staticPrivateProperty); + + $this->assertFalse(isset($proxy->staticPublicProperty)); + $this->assertFalse(isset($proxy->staticProtectedProperty)); + $this->assertFalse(isset($proxy->staticPrivateProperty)); + + $proxy->staticPublicProperty = 'staticPublicProperty'; + $proxy->staticProtectedProperty = 'staticProtectedProperty'; + $proxy->staticPrivateProperty = 'staticPrivateProperty'; + + $this->assertTrue(isset($proxy->staticPublicProperty)); + $this->assertTrue(isset($proxy->staticProtectedProperty)); + $this->assertTrue(isset($proxy->staticPrivateProperty)); + $this->assertEquals('staticPublicProperty', $proxy->staticPublicProperty); + $this->assertEquals('staticProtectedProperty', $proxy->staticProtectedProperty); + $this->assertEquals('staticPrivateProperty', $proxy->staticPrivateProperty); + + $this->assertFalse(isset($proxy->foo)); + } + + public function setGetFailureData() + { + return array( + array('__set', array('foo', 'bar')), + array('__get', array('foo')), + array('__unset', array('foo')), + ); + } + + /** + * @dataProvider setGetFailureData + */ + public function testSetGetFailure($method, array $arguments) + { + $this->setExpectedException( + 'LogicException', + 'Access to undeclared static property: Eloquent\Liberator\Test\Fixture\Object::$' . $arguments[0] + ); + call_user_func_array(array($this->proxy, $method), $arguments); + } + + public function testPopsGenerateStaticClassProxy() + { + $class = LiberatorClass::popsGenerateStaticClassProxy('Eloquent\Liberator\Test\Fixture\Object'); + + $this->assertTrue(class_exists($class, false)); + $this->assertTrue(is_subclass_of($class, 'Eloquent\Liberator\LiberatorClass')); + + $expected = new $class('Eloquent\Liberator\Test\Fixture\Object'); + $proxy = $class::liberator(); + + $this->assertEquals($expected, $proxy); + + // recursive tests + $class = LiberatorClass::popsGenerateStaticClassProxy('Eloquent\Liberator\Test\Fixture\Object', true); + + $this->assertInstanceOf('Eloquent\Liberator\LiberatorObject', $class::staticObject()); + $this->assertInstanceOf('Eloquent\Liberator\LiberatorObject', $class::staticObject()->object()); + $this->assertInstanceOf('Eloquent\Liberator\LiberatorArray', $class::staticObject()->arrayValue()); + $this->assertInstanceOf('Eloquent\Pops\ProxyPrimitive', $class::staticObject()->string()); + $this->assertInstanceOf('Eloquent\Liberator\LiberatorArray', $class::staticArray()); + $this->assertInstanceOf('Eloquent\Pops\ProxyPrimitive', $class::staticString()); + } +} diff --git a/test/suite/Eloquent/Liberator/LiberatorObjectTest.php b/test/suite/LiberatorObjectTest.php similarity index 60% rename from test/suite/Eloquent/Liberator/LiberatorObjectTest.php rename to test/suite/LiberatorObjectTest.php index 3247964..3627d91 100644 --- a/test/suite/Eloquent/Liberator/LiberatorObjectTest.php +++ b/test/suite/LiberatorObjectTest.php @@ -3,10 +3,10 @@ /* * This file is part of the Liberator package. * - * Copyright © 2013 Erin Millard + * Copyright © 2014 Erin Millard * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. + * For the full copyright and license information, please view the LICENSE file + * that was distributed with this source code. */ namespace Eloquent\Liberator; @@ -22,15 +22,13 @@ public function fixtureData() { $data = array(); - // #0: object with no inheritance $object = new Object; $proxy = new LiberatorObject($object); - $data[] = array($object, $proxy); + $data['Object with no inheritance'] = array($object, $proxy); - // #1: child object $object = new ChildObject; $proxy = new LiberatorObject($object); - $data[] = array($object, $proxy); + $data['Child object'] = array($object, $proxy); return $data; } @@ -42,30 +40,12 @@ public function testRecursive(Object $object) { $recursiveProxy = new LiberatorObject($object, true); - $this->assertInstanceOf( - __NAMESPACE__.'\LiberatorObject', - $recursiveProxy->object() - ); - $this->assertInstanceOf( - __NAMESPACE__.'\LiberatorObject', - $recursiveProxy->object()->object() - ); - $this->assertInstanceOf( - __NAMESPACE__.'\LiberatorArray', - $recursiveProxy->object()->arrayValue() - ); - $this->assertInstanceOf( - 'Eloquent\Pops\ProxyPrimitive', - $recursiveProxy->object()->string() - ); - $this->assertInstanceOf( - __NAMESPACE__.'\LiberatorArray', - $recursiveProxy->arrayValue() - ); - $this->assertInstanceOf( - 'Eloquent\Pops\ProxyPrimitive', - $recursiveProxy->string() - ); + $this->assertInstanceOf('Eloquent\Liberator\LiberatorObject', $recursiveProxy->object()); + $this->assertInstanceOf('Eloquent\Liberator\LiberatorObject', $recursiveProxy->object()->object()); + $this->assertInstanceOf('Eloquent\Liberator\LiberatorArray', $recursiveProxy->object()->arrayValue()); + $this->assertInstanceOf('Eloquent\Pops\ProxyPrimitive', $recursiveProxy->object()->string()); + $this->assertInstanceOf('Eloquent\Liberator\LiberatorArray', $recursiveProxy->arrayValue()); + $this->assertInstanceOf('Eloquent\Pops\ProxyPrimitive', $recursiveProxy->string()); } /** @@ -73,27 +53,10 @@ public function testRecursive(Object $object) */ public function testCall(Object $object, LiberatorObject $proxy) { - $this->assertLiberatorCall( - $proxy, - 'publicMethod', - array('foo', 'bar') - ); - $this->assertLiberatorCall( - $proxy, - 'protectedMethod', - array('foo', 'bar') - ); - $this->assertLiberatorCall( - $proxy, - 'privateMethod', - array('foo', 'bar') - ); - $this->assertLiberatorCall( - $proxy, - 'foo', - array('bar', 'baz'), - true - ); + $this->assertLiberatorCall($proxy, 'publicMethod', array('foo', 'bar')); + $this->assertLiberatorCall($proxy, 'protectedMethod', array('foo', 'bar')); + $this->assertLiberatorCall($proxy, 'privateMethod', array('foo', 'bar')); + $this->assertLiberatorCall($proxy, 'foo', array('bar', 'baz'), true); } /** @@ -116,18 +79,9 @@ public function testSetGet(Object $object, LiberatorObject $proxy) $this->assertTrue(isset($proxy->publicProperty)); $this->assertTrue(isset($proxy->protectedProperty)); $this->assertTrue(isset($proxy->privateProperty)); - $this->assertEquals( - 'publicProperty', - $proxy->publicProperty - ); - $this->assertEquals( - 'protectedProperty', - $proxy->protectedProperty - ); - $this->assertEquals( - 'privateProperty', - $proxy->privateProperty - ); + $this->assertEquals('publicProperty', $proxy->publicProperty); + $this->assertEquals('protectedProperty', $proxy->protectedProperty); + $this->assertEquals('privateProperty', $proxy->privateProperty); $proxy->publicProperty = 'foo'; $proxy->protectedProperty = 'bar'; @@ -156,9 +110,7 @@ public function testSetGet(Object $object, LiberatorObject $proxy) $this->assertEquals('bar', $object->foo); $object = new Overload; - $object->values = array( - 'foo' => 'bar', - ); + $object->values = array('foo' => 'bar'); $proxy = new LiberatorObject($object); $this->assertTrue(isset($proxy->foo)); diff --git a/test/suite/Eloquent/Liberator/LiberatorTest.php b/test/suite/LiberatorTest.php similarity index 55% rename from test/suite/Eloquent/Liberator/LiberatorTest.php rename to test/suite/LiberatorTest.php index 0782c54..c09ce03 100644 --- a/test/suite/Eloquent/Liberator/LiberatorTest.php +++ b/test/suite/LiberatorTest.php @@ -3,49 +3,39 @@ /* * This file is part of the Liberator package. * - * Copyright © 2013 Erin Millard + * Copyright © 2014 Erin Millard * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. + * For the full copyright and license information, please view the LICENSE file + * that was distributed with this source code. */ namespace Eloquent\Liberator; use Eloquent\Liberator\Test\Fixture\Object; -use Eloquent\Liberator\Test\TestCase; use Eloquent\Pops\ProxyPrimitive; +use PHPUnit_Framework_TestCase; -class LiberatorTest extends TestCase +class LiberatorTest extends PHPUnit_Framework_TestCase { public function testLiberator() { - $expected = new LiberatorClass(__NAMESPACE__.'\Test\Fixture\Object'); + $expected = new LiberatorClass('Eloquent\Liberator\Test\Fixture\Object'); - $this->assertEquals($expected, Liberator::liberateClass( - __NAMESPACE__.'\Test\Fixture\Object' - )); + $this->assertEquals($expected, Liberator::liberateClass('Eloquent\Liberator\Test\Fixture\Object')); + $class = Liberator::liberateClassStatic('Eloquent\Liberator\Test\Fixture\Object'); - $class = Liberator::liberateClassStatic( - __NAMESPACE__.'\Test\Fixture\Object' - ); - - $this->assertTrue(class_exists($class)); - $this->assertTrue( - is_subclass_of($class, __NAMESPACE__.'\LiberatorClass') - ); - + $this->assertTrue(class_exists($class, false)); + $this->assertTrue(is_subclass_of($class, 'Eloquent\Liberator\LiberatorClass')); $expected = new LiberatorArray(array()); $this->assertEquals($expected, Liberator::liberate(array())); - $expected = new LiberatorObject(new Object); $this->assertEquals($expected, Liberator::liberate(new Object)); - $expected = new ProxyPrimitive('string'); $this->assertEquals($expected, Liberator::liberate('string'));