diff --git a/CHANGELOG.md b/CHANGELOG.md index 91d7bce36..12e39f6bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,27 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. +## 3.0.0 - TBD + +### Added + +- Nothing. + +### Deprecated + +- Nothing. + +### Removed + +- [#33](https://github.com/zendframework/zend-stdlib/pull/20) - removed + deprecated classes + - *All Hydrator classes* see #22. + - `Zend\Stdlib\CallbackHandler` see #35 + +### Fixed + +- Nothing. + ## 2.8.0 - TBD ### Added diff --git a/composer.json b/composer.json index 4a5ecd55d..4b61b0051 100644 --- a/composer.json +++ b/composer.json @@ -13,32 +13,24 @@ } }, "require": { - "php": ">=5.5", - "zendframework/zend-hydrator": "~1.0" + "php": ">=5.5" }, "require-dev": { - "zendframework/zend-config": "~2.5", - "zendframework/zend-eventmanager": "~2.5", - "zendframework/zend-inputfilter": "~2.5", + "zendframework/zend-config": "dev-develop as 2.6.0", "zendframework/zend-serializer": "~2.5", - "zendframework/zend-servicemanager": "~2.5", - "zendframework/zend-filter": "~2.5", "fabpot/php-cs-fixer": "1.7.*", "phpunit/PHPUnit": "~4.0", "athletic/athletic": "~0.1" }, "suggest": { - "zendframework/zend-eventmanager": "To support aggregate hydrator usage", - "zendframework/zend-serializer": "Zend\\Serializer component", - "zendframework/zend-servicemanager": "To support hydrator plugin manager usage", - "zendframework/zend-filter": "To support naming strategy hydrator usage" + "zendframework/zend-serializer": "Zend\\Serializer component" }, "minimum-stability": "dev", "prefer-stable": true, "extra": { "branch-alias": { "dev-master": "2.7-dev", - "dev-develop": "2.8-dev" + "dev-develop": "3.0-dev" } }, "autoload-dev": { diff --git a/src/CallbackHandler.php b/src/CallbackHandler.php deleted file mode 100644 index dc9bfd57b..000000000 --- a/src/CallbackHandler.php +++ /dev/null @@ -1,197 +0,0 @@ -metadata = $metadata; - $this->registerCallback($callback); - } - - /** - * Registers the callback provided in the constructor - * - * @param callable $callback - * @throws Exception\InvalidCallbackException - * @return void - */ - protected function registerCallback($callback) - { - if (!is_callable($callback)) { - throw new Exception\InvalidCallbackException('Invalid callback provided; not callable'); - } - - $this->callback = $callback; - } - - /** - * Retrieve registered callback - * - * @return callable - */ - public function getCallback() - { - return $this->callback; - } - - /** - * Invoke handler - * - * @param array $args Arguments to pass to callback - * @return mixed - */ - public function call(array $args = []) - { - $callback = $this->getCallback(); - $argCount = count($args); - - if (is_string($callback)) { - $result = $this->validateStringCallbackFor54($callback); - - if ($result !== true && $argCount <= 3) { - $callback = $result; - // Minor performance tweak, if the callback gets called more - // than once - $this->callback = $result; - } - } - - // Minor performance tweak; use call_user_func() until > 3 arguments - // reached - switch ($argCount) { - case 0: - return $callback(); - case 1: - return $callback(array_shift($args)); - case 2: - $arg1 = array_shift($args); - $arg2 = array_shift($args); - return $callback($arg1, $arg2); - case 3: - $arg1 = array_shift($args); - $arg2 = array_shift($args); - $arg3 = array_shift($args); - return $callback($arg1, $arg2, $arg3); - default: - return call_user_func_array($callback, $args); - } - } - - /** - * Invoke as functor - * - * @return mixed - */ - public function __invoke() - { - return $this->call(func_get_args()); - } - - /** - * Get all callback metadata - * - * @return array - */ - public function getMetadata() - { - return $this->metadata; - } - - /** - * Retrieve a single metadatum - * - * @param string $name - * @return mixed - */ - public function getMetadatum($name) - { - if (array_key_exists($name, $this->metadata)) { - return $this->metadata[$name]; - } - return; - } - - /** - * Validate a static method call - * - * - * @param string $callback - * @return true|array - * @throws Exception\InvalidCallbackException if invalid - */ - protected function validateStringCallbackFor54($callback) - { - if (!strstr($callback, '::')) { - return true; - } - - list($class, $method) = explode('::', $callback, 2); - - if (!class_exists($class)) { - throw new Exception\InvalidCallbackException(sprintf( - 'Static method call "%s" refers to a class that does not exist', - $callback - )); - } - - $r = new ReflectionClass($class); - if (!$r->hasMethod($method)) { - throw new Exception\InvalidCallbackException(sprintf( - 'Static method call "%s" refers to a method that does not exist', - $callback - )); - } - $m = $r->getMethod($method); - if (!$m->isStatic()) { - throw new Exception\InvalidCallbackException(sprintf( - 'Static method call "%s" refers to a method that is not static', - $callback - )); - } - - // returning a non boolean value may not be nice for a validate method, - // but that allows the usage of a static string callback without using - // the call_user_func function. - return [$class, $method]; - } -} diff --git a/src/Extractor/ExtractionInterface.php b/src/Extractor/ExtractionInterface.php deleted file mode 100644 index 6c84720c8..000000000 --- a/src/Extractor/ExtractionInterface.php +++ /dev/null @@ -1,19 +0,0 @@ -args)) { - unset($this->args); - } - } - - public function testCallbackShouldStoreMetadata() - { - $handler = new CallbackHandler('rand', ['event' => 'foo']); - $this->assertEquals('foo', $handler->getMetadatum('event')); - $this->assertEquals(['event' => 'foo'], $handler->getMetadata()); - } - - public function testCallbackShouldBeStringIfNoHandlerPassedToConstructor() - { - $handler = new CallbackHandler('rand'); - $this->assertSame('rand', $handler->getCallback()); - } - - public function testCallbackShouldBeArrayIfHandlerPassedToConstructor() - { - $handler = new CallbackHandler(['ZendTest\\Stdlib\\SignalHandlers\\ObjectCallback', 'test']); - $this->assertSame(['ZendTest\\Stdlib\\SignalHandlers\\ObjectCallback', 'test'], $handler->getCallback()); - } - - public function testCallShouldInvokeCallbackWithSuppliedArguments() - { - $handler = new CallbackHandler([ $this, 'handleCall' ]); - $args = ['foo', 'bar', 'baz']; - $handler->call($args); - $this->assertSame($args, $this->args); - } - - public function testPassingInvalidCallbackShouldRaiseInvalidCallbackExceptionDuringInstantiation() - { - $this->setExpectedException('Zend\Stdlib\Exception\InvalidCallbackException'); - $handler = new CallbackHandler('boguscallback'); - } - - public function testCallShouldReturnTheReturnValueOfTheCallback() - { - $handler = new CallbackHandler(['ZendTest\\Stdlib\\SignalHandlers\\ObjectCallback', 'test']); - if (!is_callable(['ZendTest\\Stdlib\\SignalHandlers\\ObjectCallback', 'test'])) { - echo "\nClass exists? " . var_export(class_exists('ZendTest\\Stdlib\\SignalHandlers\\ObjectCallback'), 1) . "\n"; - echo "Include path: " . get_include_path() . "\n"; - } - $this->assertEquals('bar', $handler->call([])); - } - - public function testStringCallbackResolvingToClassDefiningInvokeNameShouldRaiseException() - { - $this->setExpectedException('Zend\Stdlib\Exception\InvalidCallbackException'); - $handler = new CallbackHandler('ZendTest\\Stdlib\\SignalHandlers\\Invokable'); - } - - public function testStringCallbackReferringToClassWithoutDefinedInvokeShouldRaiseException() - { - $this->setExpectedException('Zend\Stdlib\Exception\InvalidCallbackException'); - $class = new SignalHandlers\InstanceMethod(); - $handler = new CallbackHandler($class); - } - - public function testCallbackConsistingOfStringContextWithNonStaticMethodShouldNotRaiseExceptionButWillRaiseEStrict() - { - $handler = new CallbackHandler(['ZendTest\\Stdlib\\SignalHandlers\\InstanceMethod', 'handler']); - $error = false; - set_error_handler(function ($errno, $errstr) use (&$error) { - $error = true; - }, E_STRICT|E_DEPRECATED); - $handler->call(); - restore_error_handler(); - $this->assertTrue($error); - } - - public function testStringCallbackConsistingOfNonStaticMethodShouldRaiseException() - { - $handler = new CallbackHandler('ZendTest\\Stdlib\\SignalHandlers\\InstanceMethod::handler'); - - if (version_compare(PHP_VERSION, '5.4.0rc1', '>=')) { - $this->setExpectedException('Zend\Stdlib\Exception\InvalidCallbackException'); - $handler->call(); - } else { - $error = false; - set_error_handler(function ($errno, $errstr) use (&$error) { - $error = true; - }, E_STRICT); - $handler->call(); - restore_error_handler(); - $this->assertTrue($error); - } - } - - public function testStringStaticCallbackForPhp54() - { - if (version_compare(PHP_VERSION, '5.4.0rc1', '<=')) { - $this->markTestSkipped('Requires PHP 5.4'); - } - - $handler = new CallbackHandler('ZendTest\\Stdlib\\SignalHandlers\\InstanceMethod::staticHandler'); - $error = false; - set_error_handler(function ($errno, $errstr) use (&$error) { - $error = true; - }, E_STRICT); - $result = $handler->call(); - restore_error_handler(); - $this->assertFalse($error); - $this->assertSame('staticHandler', $result); - } - - public function testStringStaticCallbackForPhp54WithMoreThan3Args() - { - if (version_compare(PHP_VERSION, '5.4.0rc1', '<=')) { - $this->markTestSkipped('Requires PHP 5.4'); - } - - $handler = new CallbackHandler('ZendTest\\Stdlib\\SignalHandlers\\InstanceMethod::staticHandler'); - $error = false; - set_error_handler(function ($errno, $errstr) use (&$error) { - $error = true; - }, E_STRICT); - $result = $handler->call([1, 2, 3, 4]); - restore_error_handler(); - $this->assertFalse($error); - $this->assertSame('staticHandler', $result); - } - - public function testCallbackToClassImplementingOverloadingButNotInvocableShouldRaiseException() - { - $this->setExpectedException('Zend\Stdlib\Exception\InvalidCallbackException'); - $handler = new CallbackHandler('foo', [ 'ZendTest\\Stdlib\\SignalHandlers\\Overloadable', 'foo' ]); - } - - public function testClosureCallbackShouldBeInvokedByCall() - { - $handler = new CallbackHandler(function () { - return 'foo'; - }); - $this->assertEquals('foo', $handler->call()); - } - - public function testHandlerShouldBeInvocable() - { - $handler = new CallbackHandler([$this, 'handleCall']); - $handler('foo', 'bar'); - $this->assertEquals(['foo', 'bar'], $this->args); - } - - public function handleCall() - { - $this->args = func_get_args(); - } -} diff --git a/test/FilterCompositeTest.php b/test/FilterCompositeTest.php deleted file mode 100644 index 0e83b91d4..000000000 --- a/test/FilterCompositeTest.php +++ /dev/null @@ -1,187 +0,0 @@ -filterComposite = new FilterComposite(); - } - - public function testValidationAdd() - { - $this->assertTrue($this->filterComposite->filter("foo")); - $this->filterComposite->addFilter( - 'has', - function ($property) { - return false; - } - ); - $this->assertFalse($this->filterComposite->filter("foo")); - } - - public function testValidationRemove() - { - $this->filterComposite->addFilter( - 'has', - function ($property) { - return false; - } - ); - $this->assertFalse($this->filterComposite->filter("foo")); - $this->filterComposite->removeFilter("has"); - $this->assertTrue($this->filterComposite->filter("foo")); - } - - public function testValidationHas() - { - $this->filterComposite->addFilter( - 'has', - function ($property) { - return false; - } - ); - $this->assertFalse($this->filterComposite->filter("foo")); - $this->assertTrue($this->filterComposite->hasFilter("has")); - } - - public function testComplexValidation() - { - $this->filterComposite->addFilter("has", new \Zend\Stdlib\Hydrator\Filter\HasFilter()); - $this->filterComposite->addFilter("get", new \Zend\Stdlib\Hydrator\Filter\GetFilter()); - $this->filterComposite->addFilter("is", new \Zend\Stdlib\Hydrator\Filter\IsFilter()); - - $this->filterComposite->addFilter( - 'exclude', - function ($property) { - $separatorPos = strpos($property, '::') ?: 0; - $method = substr($property, $separatorPos); - - if ($method === 'getServiceLocator') { - return false; - } - - return true; - }, - FilterComposite::CONDITION_AND - ); - - $this->assertTrue($this->filterComposite->filter('getFooBar')); - $this->assertFalse($this->filterComposite->filter('getServiceLocator')); - } - - public function testConstructorInjection() - { - $andCondition = [ - 'servicelocator' => function ($property) { - if ($property === 'getServiceLocator') { - return false; - } - return true; - }, - 'foobar' => function ($property) { - if ($property === 'getFooBar') { - return false; - } - return true; - } - ]; - $orCondition = [ - 'has' => new \Zend\Stdlib\Hydrator\Filter\HasFilter(), - 'get' => new \Zend\Stdlib\Hydrator\Filter\GetFilter() - ]; - $filterComposite = new FilterComposite($orCondition, $andCondition); - - $this->assertFalse($filterComposite->filter('getFooBar')); - $this->assertFalse($filterComposite->filter('geTFooBar')); - $this->assertFalse($filterComposite->filter('getServiceLocator')); - $this->assertTrue($filterComposite->filter('getFoo')); - $this->assertTrue($filterComposite->filter('hasFoo')); - } - - public function testWithOnlyAndFiltersAdded() - { - $filter = new FilterComposite(); - $filter->addFilter("foobarbaz", function ($property) { - return true; - }, FilterComposite::CONDITION_AND); - $filter->addFilter("foobar", function ($property) { - return true; - }, FilterComposite::CONDITION_AND); - $this->assertTrue($filter->filter("foo")); - } - - public function testWithOnlyOrFiltersAdded() - { - $filter = new FilterComposite(); - $filter->addFilter("foobarbaz", function ($property) { - return true; - }); - $filter->addFilter("foobar", function ($property) { - return false; - }); - $this->assertTrue($filter->filter("foo")); - } - - public function testWithComplexCompositeAdded() - { - $filter1 = new FilterComposite(); - $filter1->addFilter("foobarbaz", function ($property) { - return true; - }); - $filter1->addFilter("foobar", function ($property) { - return false; - }); - $filter2 = new FilterComposite(); - $filter2->addFilter("bar", function ($property) { - return true; - }, FilterComposite::CONDITION_AND); - $filter2->addFilter("barblubb", function ($property) { - return true; - }, FilterComposite::CONDITION_AND); - $this->assertTrue($filter1->filter("foo")); - $this->assertTrue($filter2->filter("foo")); - $filter1->addFilter("bar", $filter2); - $this->assertTrue($filter1->filter("blubb")); - - $filter1->addFilter("blubb", function ($property) { - return false; - }, FilterComposite::CONDITION_AND); - $this->assertFalse($filter1->filter("test")); - } - - /** - * @expectedException Zend\Hydrator\Exception\InvalidArgumentException - * @expectedExceptionMessage The value of test should be either a callable - * or an instance of Zend\Hydrator\Filter\FilterInterface - */ - public function testInvalidParameterConstructorInjection() - { - $andCondition = ['foo' => 'bar']; - $orCondition = ['test' => 'blubb']; - - new FilterComposite($orCondition, $andCondition); - } - - /** - * @expectedException Zend\Hydrator\Exception\InvalidArgumentException - * @expectedExceptionMessage The value of foo should be either a callable - * or an instance of Zend\Hydrator\Filter\FilterInterface - */ - public function testInvalidFilterInjection() - { - $this->filterComposite->addFilter('foo', 'bar'); - } -} diff --git a/test/FilterTest.php b/test/FilterTest.php deleted file mode 100644 index 9c9fdd5fc..000000000 --- a/test/FilterTest.php +++ /dev/null @@ -1,53 +0,0 @@ -assertTrue($hasValidation->filter('hasFoo')); - $this->assertTrue($hasValidation->filter('Foo::hasFoo')); - $this->assertFalse($hasValidation->filter('FoohasFoo')); - $this->assertFalse($hasValidation->filter('Bar::FoohasFoo')); - $this->assertFalse($hasValidation->filter('hAsFoo')); - $this->assertFalse($hasValidation->filter('Blubb::hAsFoo')); - $this->assertFalse($hasValidation->filter(get_class($this). '::hAsFoo')); - } - - public function testGetValidation() - { - $hasValidation = new GetFilter(); - $this->assertTrue($hasValidation->filter('getFoo')); - $this->assertTrue($hasValidation->filter('Bar::getFoo')); - $this->assertFalse($hasValidation->filter('GetFooBar')); - $this->assertFalse($hasValidation->filter('Foo::GetFooBar')); - $this->assertFalse($hasValidation->filter('GETFoo')); - $this->assertFalse($hasValidation->filter('Blubb::GETFoo')); - $this->assertFalse($hasValidation->filter(get_class($this).'::GETFoo')); - } - - public function testIsValidation() - { - $hasValidation = new IsFilter(); - $this->assertTrue($hasValidation->filter('isFoo')); - $this->assertTrue($hasValidation->filter('Blubb::isFoo')); - $this->assertFalse($hasValidation->filter('IsFooBar')); - $this->assertFalse($hasValidation->filter('Foo::IsFooBar')); - $this->assertFalse($hasValidation->filter('ISFoo')); - $this->assertFalse($hasValidation->filter('Bar::ISFoo')); - $this->assertFalse($hasValidation->filter(get_class($this).'::ISFoo')); - } -} diff --git a/test/Hydrator/Aggregate/AggregateHydratorFunctionalTest.php b/test/Hydrator/Aggregate/AggregateHydratorFunctionalTest.php deleted file mode 100644 index 2a9521a26..000000000 --- a/test/Hydrator/Aggregate/AggregateHydratorFunctionalTest.php +++ /dev/null @@ -1,177 +0,0 @@ -hydrator = new AggregateHydrator(); - } - - /** - * Verifies that no interaction happens when the aggregate hydrator is empty - */ - public function testEmptyAggregate() - { - $object = new ArrayObject(['zaphod' => 'beeblebrox']); - - $this->assertSame([], $this->hydrator->extract($object)); - $this->assertSame($object, $this->hydrator->hydrate(['arthur' => 'dent'], $object)); - - $this->assertSame(['zaphod' => 'beeblebrox'], $object->getArrayCopy()); - } - - /** - * @dataProvider getHydratorSet - * - * Verifies that using a single hydrator will have the aggregate hydrator behave like that single hydrator - */ - public function testSingleHydratorExtraction(HydratorInterface $comparisonHydrator, $object) - { - $blueprint = clone $object; - - $this->hydrator->add($comparisonHydrator); - - $this->assertSame($comparisonHydrator->extract($blueprint), $this->hydrator->extract($object)); - } - - /** - * @dataProvider getHydratorSet - * - * Verifies that using a single hydrator will have the aggregate hydrator behave like that single hydrator - */ - public function testSingleHydratorHydration(HydratorInterface $comparisonHydrator, $object, $data) - { - $blueprint = clone $object; - - $this->hydrator->add($comparisonHydrator); - - $hydratedBlueprint = $comparisonHydrator->hydrate($data, $blueprint); - $hydrated = $this->hydrator->hydrate($data, $object); - - $this->assertEquals($hydratedBlueprint, $hydrated); - - if ($hydratedBlueprint === $blueprint) { - $this->assertSame($hydrated, $object); - } - } - - /** - * Verifies that multiple hydrators in an aggregate merge the extracted data - */ - public function testExtractWithMultipleHydrators() - { - $this->hydrator->add(new ClassMethods()); - $this->hydrator->add(new ArraySerializable()); - - $object = new AggregateObject(); - - $extracted = $this->hydrator->extract($object); - - $this->assertArrayHasKey('maintainer', $extracted); - $this->assertArrayHasKey('president', $extracted); - $this->assertSame('Marvin', $extracted['maintainer']); - $this->assertSame('Zaphod', $extracted['president']); - } - - /** - * Verifies that multiple hydrators in an aggregate merge the extracted data - */ - public function testHydrateWithMultipleHydrators() - { - $this->hydrator->add(new ClassMethods()); - $this->hydrator->add(new ArraySerializable()); - - $object = new AggregateObject(); - - $this->assertSame( - $object, - $this->hydrator->hydrate(['maintainer' => 'Trillian', 'president' => '???'], $object) - ); - - $this->assertArrayHasKey('maintainer', $object->arrayData); - $this->assertArrayHasKey('president', $object->arrayData); - $this->assertSame('Trillian', $object->arrayData['maintainer']); - $this->assertSame('???', $object->arrayData['president']); - $this->assertSame('Trillian', $object->maintainer); - } - - /** - * Verifies that stopping propagation within a listener in the hydrator allows modifying how the - * hydrator behaves - */ - public function testStoppedPropagationInExtraction() - { - $object = new ArrayObject(['president' => 'Zaphod']); - $callback = function (ExtractEvent $event) { - $event->setExtractedData(['Ravenous Bugblatter Beast of Traal']); - $event->stopPropagation(); - }; - - $this->hydrator->add(new ArraySerializable()); - $this->hydrator->getEventManager()->attach(ExtractEvent::EVENT_EXTRACT, $callback, 1000); - - $this->assertSame(['Ravenous Bugblatter Beast of Traal'], $this->hydrator->extract($object)); - } - - /** - * Verifies that stopping propagation within a listener in the hydrator allows modifying how the - * hydrator behaves - */ - public function testStoppedPropagationInHydration() - { - $object = new ArrayObject(); - $swappedObject = new stdClass(); - $callback = function (HydrateEvent $event) use ($swappedObject) { - $event->setHydratedObject($swappedObject); - $event->stopPropagation(); - }; - - $this->hydrator->add(new ArraySerializable()); - $this->hydrator->getEventManager()->attach(HydrateEvent::EVENT_HYDRATE, $callback, 1000); - - $this->assertSame($swappedObject, $this->hydrator->hydrate(['president' => 'Zaphod'], $object)); - } - - /** - * Data provider method - * - * @return array - */ - public function getHydratorSet() - { - return [ - [new ArraySerializable(), new ArrayObject(['zaphod' => 'beeblebrox']), ['arthur' => 'dent']], - ]; - } -} diff --git a/test/Hydrator/Aggregate/AggregateHydratorTest.php b/test/Hydrator/Aggregate/AggregateHydratorTest.php deleted file mode 100644 index c06958831..000000000 --- a/test/Hydrator/Aggregate/AggregateHydratorTest.php +++ /dev/null @@ -1,115 +0,0 @@ -eventManager = $this->getMock('Zend\EventManager\EventManagerInterface'); - $this->hydrator = new AggregateHydrator(); - - $this->hydrator->setEventManager($this->eventManager); - } - - /** - * @covers \Zend\Stdlib\Hydrator\Aggregate\AggregateHydrator::add - */ - public function testAdd() - { - $attached = $this->getMock('Zend\Hydrator\HydratorInterface'); - - $this - ->eventManager - ->expects($this->once()) - ->method('attachAggregate') - ->with($this->isInstanceOf('Zend\Hydrator\Aggregate\HydratorListener'), 123); - - $this->hydrator->add($attached, 123); - } - - /** - * @covers \Zend\Stdlib\Hydrator\Aggregate\AggregateHydrator::hydrate - */ - public function testHydrate() - { - $object = new stdClass(); - - $this - ->eventManager - ->expects($this->once()) - ->method('trigger') - ->with($this->isInstanceOf('Zend\Hydrator\Aggregate\HydrateEvent')); - - $this->assertSame($object, $this->hydrator->hydrate(['foo' => 'bar'], $object)); - } - - /** - * @covers \Zend\Stdlib\Hydrator\Aggregate\AggregateHydrator::extract - */ - public function testExtract() - { - $object = new stdClass(); - - $this - ->eventManager - ->expects($this->once()) - ->method('trigger') - ->with($this->isInstanceOf('Zend\Hydrator\Aggregate\ExtractEvent')); - - $this->assertSame([], $this->hydrator->extract($object)); - } - - /** - * @covers \Zend\Stdlib\Hydrator\Aggregate\AggregateHydrator::getEventManager - * @covers \Zend\Stdlib\Hydrator\Aggregate\AggregateHydrator::setEventManager - */ - public function testGetSetManager() - { - $hydrator = new AggregateHydrator(); - $eventManager = $this->getMock('Zend\EventManager\EventManagerInterface'); - - $this->assertInstanceOf('Zend\EventManager\EventManagerInterface', $hydrator->getEventManager()); - - $eventManager - ->expects($this->once()) - ->method('setIdentifiers') - ->with( - [ - 'Zend\Hydrator\Aggregate\AggregateHydrator', - 'Zend\Stdlib\Hydrator\Aggregate\AggregateHydrator', - ] - ); - - $hydrator->setEventManager($eventManager); - - $this->assertSame($eventManager, $hydrator->getEventManager()); - } -} diff --git a/test/Hydrator/Aggregate/ExtractEventTest.php b/test/Hydrator/Aggregate/ExtractEventTest.php deleted file mode 100644 index cbc64f3e4..000000000 --- a/test/Hydrator/Aggregate/ExtractEventTest.php +++ /dev/null @@ -1,54 +0,0 @@ - 'Marvin']; - $object2 = new stdClass(); - - $this->assertSame(ExtractEvent::EVENT_EXTRACT, $event->getName()); - $this->assertSame($target, $event->getTarget()); - $this->assertSame($object1, $event->getExtractionObject()); - $this->assertSame([], $event->getExtractedData()); - - $event->setExtractedData($data2); - - $this->assertSame($data2, $event->getExtractedData()); - - - $event->setExtractionObject($object2); - - $this->assertSame($object2, $event->getExtractionObject()); - - $event->mergeExtractedData(['president' => 'Zaphod']); - - $extracted = $event->getExtractedData(); - - $this->assertCount(2, $extracted); - $this->assertSame('Marvin', $extracted['maintainer']); - $this->assertSame('Zaphod', $extracted['president']); - } -} diff --git a/test/Hydrator/Aggregate/HydrateEventTest.php b/test/Hydrator/Aggregate/HydrateEventTest.php deleted file mode 100644 index c4ae90717..000000000 --- a/test/Hydrator/Aggregate/HydrateEventTest.php +++ /dev/null @@ -1,47 +0,0 @@ - 'Zaphod']; - $event = new HydrateEvent($target, $hydrated1, $data1); - $data2 = ['maintainer' => 'Marvin']; - $hydrated2 = new stdClass(); - - $this->assertSame(HydrateEvent::EVENT_HYDRATE, $event->getName()); - $this->assertSame($target, $event->getTarget()); - $this->assertSame($hydrated1, $event->getHydratedObject()); - $this->assertSame($data1, $event->getHydrationData()); - - $event->setHydrationData($data2); - - $this->assertSame($data2, $event->getHydrationData()); - - - $event->setHydratedObject($hydrated2); - - $this->assertSame($hydrated2, $event->getHydratedObject()); - } -} diff --git a/test/Hydrator/Aggregate/HydratorListenerTest.php b/test/Hydrator/Aggregate/HydratorListenerTest.php deleted file mode 100644 index 9e754de16..000000000 --- a/test/Hydrator/Aggregate/HydratorListenerTest.php +++ /dev/null @@ -1,117 +0,0 @@ -hydrator = $this->getMock('Zend\Hydrator\HydratorInterface'); - $this->listener = new HydratorListener($this->hydrator); - } - - /** - * @covers \Zend\Stdlib\Hydrator\Aggregate\HydratorListener::attach - */ - public function testAttach() - { - $eventManager = $this->getMock('Zend\EventManager\EventManagerInterface'); - - $eventManager - ->expects($this->exactly(2)) - ->method('attach') - ->with( - $this->logicalOr(HydrateEvent::EVENT_HYDRATE, ExtractEvent::EVENT_EXTRACT), - $this->logicalAnd( - $this->callback('is_callable'), - $this->logicalOr([$this->listener, 'onHydrate'], [$this->listener, 'onExtract']) - ) - ); - - $this->listener->attach($eventManager); - } - - /** - * @covers \Zend\Stdlib\Hydrator\Aggregate\HydratorListener::onHydrate - */ - public function testOnHydrate() - { - $object = new stdClass(); - $hydrated = new stdClass(); - $data = ['foo' => 'bar']; - $event = $this - ->getMockBuilder('Zend\Stdlib\Hydrator\Aggregate\HydrateEvent') - ->disableOriginalConstructor() - ->getMock(); - - $event->expects($this->any())->method('getHydratedObject')->will($this->returnValue($object)); - $event->expects($this->any())->method('getHydrationData')->will($this->returnValue($data)); - - $this - ->hydrator - ->expects($this->once()) - ->method('hydrate') - ->with($data, $object) - ->will($this->returnValue($hydrated)); - $event->expects($this->once())->method('setHydratedObject')->with($hydrated); - - $this->assertSame($hydrated, $this->listener->onHydrate($event)); - } - - /** - * @covers \Zend\Stdlib\Hydrator\Aggregate\HydratorListener::onExtract - */ - public function testOnExtract() - { - $object = new stdClass(); - $data = ['foo' => 'bar']; - $event = $this - ->getMockBuilder('Zend\Stdlib\Hydrator\Aggregate\ExtractEvent') - ->disableOriginalConstructor() - ->getMock(); - - - $event->expects($this->any())->method('getExtractionObject')->will($this->returnValue($object)); - - $this - ->hydrator - ->expects($this->once()) - ->method('extract') - ->with($object) - ->will($this->returnValue($data)); - $event->expects($this->once())->method('mergeExtractedData')->with($data); - - $this->assertSame($data, $this->listener->onExtract($event)); - } -} diff --git a/test/Hydrator/ClassMethodsTest.php b/test/Hydrator/ClassMethodsTest.php deleted file mode 100644 index 310848bfb..000000000 --- a/test/Hydrator/ClassMethodsTest.php +++ /dev/null @@ -1,76 +0,0 @@ -hydrator = new ClassMethods(); - } - - /** - * Verifies that extraction can happen even when a getter has parameters if those are all optional - */ - public function testCanExtractFromMethodsWithOptionalParameters() - { - $this->assertSame(['foo' => 'bar'], $this->hydrator->extract(new ClassMethodsOptionalParameters())); - } - - /** - * Verifies that the hydrator can act on different instance types - */ - public function testCanHydratedPromiscuousInstances() - { - /* @var $classMethodsCamelCase ClassMethodsCamelCase */ - $classMethodsCamelCase = $this->hydrator->hydrate( - ['fooBar' => 'baz-tab'], - new ClassMethodsCamelCase() - ); - /* @var $classMethodsCamelCaseMissing ClassMethodsCamelCaseMissing */ - $classMethodsCamelCaseMissing = $this->hydrator->hydrate( - ['fooBar' => 'baz-tab'], - new ClassMethodsCamelCaseMissing() - ); - /* @var $arraySerializable ArraySerializable */ - $arraySerializable = $this->hydrator->hydrate(['fooBar' => 'baz-tab'], new ArraySerializable()); - - $this->assertSame('baz-tab', $classMethodsCamelCase->getFooBar()); - $this->assertSame('baz-tab', $classMethodsCamelCaseMissing->getFooBar()); - $this->assertSame( - [ - "foo" => "bar", - "bar" => "foo", - "blubb" => "baz", - "quo" => "blubb" - ], - $arraySerializable->getArrayCopy() - ); - } -} diff --git a/test/Hydrator/DelegatingHydratorFactoryTest.php b/test/Hydrator/DelegatingHydratorFactoryTest.php deleted file mode 100644 index e5a59ec57..000000000 --- a/test/Hydrator/DelegatingHydratorFactoryTest.php +++ /dev/null @@ -1,25 +0,0 @@ -getMock('Zend\ServiceManager\ServiceLocatorInterface'); - $factory = new DelegatingHydratorFactory(); - $this->assertInstanceOf( - 'Zend\Hydrator\DelegatingHydrator', - $factory->createService($hydratorManager) - ); - } -} diff --git a/test/Hydrator/DelegatingHydratorTest.php b/test/Hydrator/DelegatingHydratorTest.php deleted file mode 100644 index 5109661f7..000000000 --- a/test/Hydrator/DelegatingHydratorTest.php +++ /dev/null @@ -1,89 +0,0 @@ -hydrators = $this->getMock('Zend\ServiceManager\ServiceLocatorInterface'); - $this->hydrator = new DelegatingHydrator($this->hydrators); - $this->object = new ArrayObject; - } - - public function testExtract() - { - $this->hydrators->expects($this->any()) - ->method('has') - ->with('ArrayObject') - ->will($this->returnValue(true)); - - $hydrator = $this->getMock('Zend\Stdlib\Hydrator\HydratorInterface'); - - $this->hydrators->expects($this->any()) - ->method('get') - ->with('ArrayObject') - ->will($this->returnValue($hydrator)); - - $hydrator->expects($this->any()) - ->method('extract') - ->with($this->object) - ->will($this->returnValue(['foo' => 'bar'])); - - $this->assertEquals(['foo' => 'bar'], $hydrator->extract($this->object)); - } - - public function testHydrate() - { - $this->hydrators->expects($this->any()) - ->method('has') - ->with('ArrayObject') - ->will($this->returnValue(true)); - - $hydrator = $this->getMock('Zend\Stdlib\Hydrator\HydratorInterface'); - - $this->hydrators->expects($this->any()) - ->method('get') - ->with('ArrayObject') - ->will($this->returnValue($hydrator)); - - $hydrator->expects($this->any()) - ->method('hydrate') - ->with(['foo' => 'bar'], $this->object) - ->will($this->returnValue($this->object)); - $this->assertEquals($this->object, $hydrator->hydrate(['foo' => 'bar'], $this->object)); - } -} diff --git a/test/Hydrator/Filter/NumberOfParameterFilterTest.php b/test/Hydrator/Filter/NumberOfParameterFilterTest.php deleted file mode 100644 index fc4350da9..000000000 --- a/test/Hydrator/Filter/NumberOfParameterFilterTest.php +++ /dev/null @@ -1,54 +0,0 @@ -assertTrue($filter->filter(__CLASS__ . '::methodWithNoParameters')); - $this->assertFalse($filter->filter(__CLASS__ . '::methodWithOptionalParameters')); - } - - /** - * @group 6083 - */ - public function testArityOne() - { - $filter = new NumberOfParameterFilter(1); - $this->assertFalse($filter->filter(__CLASS__ . '::methodWithNoParameters')); - $this->assertTrue($filter->filter(__CLASS__ . '::methodWithOptionalParameters')); - } - - /** - * Test asset method - */ - public function methodWithOptionalParameters($parameter = 'foo') - { - } - - /** - * Test asset method - */ - public function methodWithNoParameters() - { - } -} diff --git a/test/Hydrator/Filter/OptionalParametersFilterTest.php b/test/Hydrator/Filter/OptionalParametersFilterTest.php deleted file mode 100644 index f2f3429ea..000000000 --- a/test/Hydrator/Filter/OptionalParametersFilterTest.php +++ /dev/null @@ -1,120 +0,0 @@ -filter = new OptionalParametersFilter(); - } - - /** - * Verifies a list of methods against expected results - * - * @param string $method - * @param bool $expectedResult - * - * @dataProvider methodProvider - */ - public function testMethods($method, $expectedResult) - { - $this->assertSame($expectedResult, $this->filter->filter($method)); - } - - /** - * Verifies a list of methods against expected results over subsequent calls, checking - * that the filter behaves consistently regardless of cache optimizations - * - * @param string $method - * @param bool $expectedResult - * - * @dataProvider methodProvider - */ - public function testMethodsOnSubsequentCalls($method, $expectedResult) - { - for ($i = 0; $i < 5; $i += 1) { - $this->assertSame($expectedResult, $this->filter->filter($method)); - } - } - - public function testTriggersExceptionOnUnknownMethod() - { - $this->setExpectedException('InvalidArgumentException'); - $this->filter->filter(__CLASS__ . '::' . 'nonExistingMethod'); - } - - /** - * Provides a list of methods to be checked against the filter - * - * @return array - */ - public function methodProvider() - { - return [ - [__CLASS__ . '::' . 'methodWithoutParameters', true], - [__CLASS__ . '::' . 'methodWithSingleMandatoryParameter', false], - [__CLASS__ . '::' . 'methodWithSingleOptionalParameter', true], - [__CLASS__ . '::' . 'methodWithMultipleMandatoryParameters', false], - [__CLASS__ . '::' . 'methodWithMultipleOptionalParameters', true], - ]; - } - - /** - * Test asset method - */ - public function methodWithoutParameters() - { - } - - /** - * Test asset method - */ - public function methodWithSingleMandatoryParameter($parameter) - { - } - - /** - * Test asset method - */ - public function methodWithSingleOptionalParameter($parameter = null) - { - } - - /** - * Test asset method - */ - public function methodWithMultipleMandatoryParameters($parameter, $otherParameter) - { - } - - /** - * Test asset method - */ - public function methodWithMultipleOptionalParameters($parameter = null, $otherParameter = null) - { - } -} diff --git a/test/Hydrator/HydratorAwareTraitTest.php b/test/Hydrator/HydratorAwareTraitTest.php deleted file mode 100644 index 1051d0fa7..000000000 --- a/test/Hydrator/HydratorAwareTraitTest.php +++ /dev/null @@ -1,45 +0,0 @@ -getObjectForTrait('\Zend\Stdlib\Hydrator\HydratorAwareTrait'); - - $this->assertAttributeEquals(null, 'hydrator', $object); - - $hydrator = $this->getMockForAbstractClass('\Zend\Stdlib\Hydrator\AbstractHydrator'); - - $object->setHydrator($hydrator); - - $this->assertAttributeEquals($hydrator, 'hydrator', $object); - } - - public function testGetHydrator() - { - $object = $this->getObjectForTrait('\Zend\Stdlib\Hydrator\HydratorAwareTrait'); - - $this->assertNull($object->getHydrator()); - - $hydrator = $this->getMockForAbstractClass('\Zend\Stdlib\Hydrator\AbstractHydrator'); - - $object->setHydrator($hydrator); - - $this->assertEquals($hydrator, $object->getHydrator()); - } -} diff --git a/test/Hydrator/HydratorManagerTest.php b/test/Hydrator/HydratorManagerTest.php deleted file mode 100644 index cf5035157..000000000 --- a/test/Hydrator/HydratorManagerTest.php +++ /dev/null @@ -1,41 +0,0 @@ -manager = new HydratorPluginManager(); - } - - public function testRegisteringInvalidElementRaisesException() - { - $this->setExpectedException('Zend\Hydrator\Exception\RuntimeException'); - $this->manager->setService('test', $this); - } - - public function testLoadingInvalidElementRaisesException() - { - $this->manager->setInvokableClass('test', get_class($this)); - $this->setExpectedException('Zend\Hydrator\Exception\RuntimeException'); - $this->manager->get('test'); - } -} diff --git a/test/Hydrator/Iterator/HydratingArrayIteratorTest.php b/test/Hydrator/Iterator/HydratingArrayIteratorTest.php deleted file mode 100644 index f84098244..000000000 --- a/test/Hydrator/Iterator/HydratingArrayIteratorTest.php +++ /dev/null @@ -1,58 +0,0 @@ - 'bar'], - ['baz' => 'bat'], - ]; - - $object = new ArrayObject(); - - $hydratingIterator = new HydratingArrayIterator(new ArraySerializable(), $data, $object); - - $hydratingIterator->rewind(); - $this->assertEquals(new ArrayObject($data[0]), $hydratingIterator->current()); - $this->assertNotSame( - $object, - $hydratingIterator->current(), - 'Hydrating Iterator did not clone the object' - ); - - $hydratingIterator->next(); - $this->assertEquals(new ArrayObject($data[1]), $hydratingIterator->current()); - } - - public function testUsingStringForObjectName() - { - $data = [ - ['foo' => 'bar'], - ]; - - $hydratingIterator = new HydratingArrayIterator(new ArraySerializable(), $data, '\ArrayObject'); - - $hydratingIterator->rewind(); - $this->assertEquals(new ArrayObject($data[0]), $hydratingIterator->current()); - } - - public function testThrowingInvalidArguementExceptionWhenSettingPrototypeToInvalidClass() - { - $this->setExpectedException('Zend\Hydrator\Exception\InvalidArgumentException'); - $hydratingIterator = new HydratingArrayIterator(new ArraySerializable(), [], 'not a real class'); - } -} diff --git a/test/Hydrator/Iterator/HydratingIteratorIteratorTest.php b/test/Hydrator/Iterator/HydratingIteratorIteratorTest.php deleted file mode 100644 index 58900f7e8..000000000 --- a/test/Hydrator/Iterator/HydratingIteratorIteratorTest.php +++ /dev/null @@ -1,66 +0,0 @@ - 'bar'], - ['baz' => 'bat'], - ]; - - $iterator = new ArrayIterator($data); - $object = new ArrayObject(); - - $hydratingIterator = new HydratingIteratorIterator(new ArraySerializable(), $iterator, $object); - - $hydratingIterator->rewind(); - $this->assertEquals(new ArrayObject($data[0]), $hydratingIterator->current()); - $this->assertNotSame( - $object, - $hydratingIterator->current(), - 'Hydrating Iterator did not clone the object' - ); - - $hydratingIterator->next(); - $this->assertEquals(new ArrayObject($data[1]), $hydratingIterator->current()); - } - - public function testUsingStringForObjectName() - { - $data = [ - ['foo' => 'bar'], - ]; - - $iterator = new ArrayIterator($data); - - $hydratingIterator = new HydratingIteratorIterator(new ArraySerializable(), $iterator, '\ArrayObject'); - - $hydratingIterator->rewind(); - $this->assertEquals(new ArrayObject($data[0]), $hydratingIterator->current()); - } - - public function testThrowingInvalidArguementExceptionWhenSettingPrototypeToInvalidClass() - { - $this->setExpectedException('Zend\Hydrator\Exception\InvalidArgumentException'); - $hydratingIterator = new HydratingIteratorIterator( - new ArraySerializable(), - new ArrayIterator(), - 'not a real class' - ); - } -} diff --git a/test/Hydrator/NamingStrategy/ArrayMapNamingStrategyTest.php b/test/Hydrator/NamingStrategy/ArrayMapNamingStrategyTest.php deleted file mode 100644 index 3327a2124..000000000 --- a/test/Hydrator/NamingStrategy/ArrayMapNamingStrategyTest.php +++ /dev/null @@ -1,39 +0,0 @@ -assertEquals('some_stuff', $strategy->hydrate('some_stuff')); - $this->assertEquals('some_stuff', $strategy->extract('some_stuff')); - } - - public function testExtract() - { - $strategy = new ArrayMapNamingStrategy(['stuff3' => 'stuff4']); - $this->assertEquals('stuff4', $strategy->extract('stuff3')); - } - - public function testHydrate() - { - $strategy = new ArrayMapNamingStrategy(['foo' => 'bar']); - $this->assertEquals('foo', $strategy->hydrate('bar')); - } -} diff --git a/test/Hydrator/NamingStrategy/CompositeNamingStrategyTest.php b/test/Hydrator/NamingStrategy/CompositeNamingStrategyTest.php deleted file mode 100644 index 950cdad20..000000000 --- a/test/Hydrator/NamingStrategy/CompositeNamingStrategyTest.php +++ /dev/null @@ -1,74 +0,0 @@ - $this->getMock('Zend\Stdlib\Hydrator\NamingStrategy\NamingStrategyInterface') - ]); - - $this->assertEquals('bar', $compositeNamingStrategy->hydrate('bar')); - $this->assertEquals('bar', $compositeNamingStrategy->extract('bar')); - } - - public function testUseDefaultNamingStrategy() - { - /* @var $defaultNamingStrategy NamingStrategyInterface|\PHPUnit_Framework_MockObject_MockObject*/ - $defaultNamingStrategy = $this->getMock('Zend\Stdlib\Hydrator\NamingStrategy\NamingStrategyInterface'); - $defaultNamingStrategy->expects($this->at(0)) - ->method('hydrate') - ->with('foo') - ->will($this->returnValue('Foo')); - $defaultNamingStrategy->expects($this->at(1)) - ->method('extract') - ->with('Foo') - ->will($this->returnValue('foo')); - - $compositeNamingStrategy = new CompositeNamingStrategy( - ['bar' => $this->getMock('Zend\Stdlib\Hydrator\NamingStrategy\NamingStrategyInterface')], - $defaultNamingStrategy - ); - $this->assertEquals('Foo', $compositeNamingStrategy->hydrate('foo')); - $this->assertEquals('foo', $compositeNamingStrategy->extract('Foo')); - } - - public function testHydrate() - { - $fooNamingStrategy = $this->getMock('Zend\Stdlib\Hydrator\NamingStrategy\NamingStrategyInterface'); - $fooNamingStrategy->expects($this->once()) - ->method('hydrate') - ->with('foo') - ->will($this->returnValue('FOO')); - $compositeNamingStrategy = new CompositeNamingStrategy(['foo' => $fooNamingStrategy]); - $this->assertEquals('FOO', $compositeNamingStrategy->hydrate('foo')); - } - - public function testExtract() - { - $fooNamingStrategy = $this->getMock('Zend\Stdlib\Hydrator\NamingStrategy\NamingStrategyInterface'); - $fooNamingStrategy->expects($this->once()) - ->method('extract') - ->with('FOO') - ->will($this->returnValue('foo')); - $compositeNamingStrategy = new CompositeNamingStrategy(['FOO' => $fooNamingStrategy]); - $this->assertEquals('foo', $compositeNamingStrategy->extract('FOO')); - } -} diff --git a/test/Hydrator/NamingStrategy/IdentityNamingStrategyTest.php b/test/Hydrator/NamingStrategy/IdentityNamingStrategyTest.php deleted file mode 100644 index 6ab8ef1e4..000000000 --- a/test/Hydrator/NamingStrategy/IdentityNamingStrategyTest.php +++ /dev/null @@ -1,59 +0,0 @@ -assertSame($name, $namingStrategy->hydrate($name)); - } - - /** - * @dataProvider getTestedNames - * - * @param string $name - */ - public function testExtract($name) - { - $namingStrategy = new IdentityNamingStrategy(); - - $this->assertSame($name, $namingStrategy->extract($name)); - } - - /** - * Data provider - * - * @return string[][] - */ - public function getTestedNames() - { - return [ - [123], - [0], - ['foo'], - ['bar'], - ]; - } -} diff --git a/test/Hydrator/NamingStrategy/MapNamingStrategyTest.php b/test/Hydrator/NamingStrategy/MapNamingStrategyTest.php deleted file mode 100644 index a0eb27afb..000000000 --- a/test/Hydrator/NamingStrategy/MapNamingStrategyTest.php +++ /dev/null @@ -1,40 +0,0 @@ - 'bar']); - - $this->assertEquals('bar', $namingStrategy->hydrate('foo')); - $this->assertEquals('foo', $namingStrategy->extract('bar')); - } - - public function testHydrateAndExtractMaps() - { - $namingStrategy = new MapNamingStrategy( - ['foo' => 'foo-hydrated'], - ['bar' => 'bar-extracted'] - ); - - $this->assertEquals('foo-hydrated', $namingStrategy->hydrate('foo')); - $this->assertEquals('bar-extracted', $namingStrategy->extract('bar')); - } - - public function testSingleMapInvalidValue() - { - $this->setExpectedException('InvalidArgumentException'); - new MapNamingStrategy(['foo' => 3.1415]); - } -} diff --git a/test/Hydrator/NamingStrategy/UnderscoreNamingStrategyTest.php b/test/Hydrator/NamingStrategy/UnderscoreNamingStrategyTest.php deleted file mode 100644 index d74bbbec4..000000000 --- a/test/Hydrator/NamingStrategy/UnderscoreNamingStrategyTest.php +++ /dev/null @@ -1,43 +0,0 @@ -assertEquals('fooBarBaz', $strategy->hydrate('foo_bar_baz')); - } - - public function testNameExtractsToUnderscore() - { - $strategy = new UnderscoreNamingStrategy(); - $this->assertEquals('foo_bar_baz', $strategy->extract('fooBarBaz')); - } - - /** - * @group 6422 - * @group 6420 - */ - public function testNameHydratesToStudlyCaps() - { - $strategy = new UnderscoreNamingStrategy(); - - $this->assertEquals('fooBarBaz', $strategy->hydrate('Foo_Bar_Baz')); - } -} diff --git a/test/Hydrator/ObjectPropertyTest.php b/test/Hydrator/ObjectPropertyTest.php deleted file mode 100644 index 7158b276e..000000000 --- a/test/Hydrator/ObjectPropertyTest.php +++ /dev/null @@ -1,166 +0,0 @@ -hydrator = new ObjectProperty(); - } - - /** - * Verify that we get an exception when trying to extract on a non-object - */ - public function testHydratorExtractThrowsExceptionOnNonObjectParameter() - { - $this->setExpectedException('BadMethodCallException'); - $this->hydrator->extract('thisIsNotAnObject'); - } - - /** - * Verify that we get an exception when trying to hydrate a non-object - */ - public function testHydratorHydrateThrowsExceptionOnNonObjectParameter() - { - $this->setExpectedException('BadMethodCallException'); - $this->hydrator->hydrate(['some' => 'data'], 'thisIsNotAnObject'); - } - - /** - * Verifies that the hydrator can extract from property of stdClass objects - */ - public function testCanExtractFromStdClass() - { - $object = new \stdClass(); - $object->foo = 'bar'; - - $this->assertSame(['foo' => 'bar'], $this->hydrator->extract($object)); - } - - /** - * Verifies that the extraction process works on classes that aren't stdClass - */ - public function testCanExtractFromGenericClass() - { - $this->assertSame( - [ - 'foo' => 'bar', - 'bar' => 'foo', - 'blubb' => 'baz', - 'quo' => 'blubb' - ], - $this->hydrator->extract(new ObjectPropertyTestAsset()) - ); - } - - /** - * Verify hydration of {@see \stdClass} - */ - public function testCanHydrateStdClass() - { - $object = new \stdClass(); - $object->foo = 'bar'; - - $object = $this->hydrator->hydrate(['foo' => 'baz'], $object); - - $this->assertEquals('baz', $object->foo); - } - - /** - * Verify that new properties are created if the object is stdClass - */ - public function testCanHydrateAdditionalPropertiesToStdClass() - { - $object = new \stdClass(); - $object->foo = 'bar'; - - $object = $this->hydrator->hydrate(['foo' => 'baz', 'bar' => 'baz'], $object); - - $this->assertEquals('baz', $object->foo); - $this->assertObjectHasAttribute('bar', $object); - $this->assertAttributeSame('baz', 'bar', $object); - } - - /** - * Verify that it can hydrate our class public properties - */ - public function testCanHydrateGenericClassPublicProperties() - { - $object = $this->hydrator->hydrate( - [ - 'foo' => 'foo', - 'bar' => 'bar', - 'blubb' => 'blubb', - 'quo' => 'quo', - 'quin' => 'quin' - ], - new ObjectPropertyTestAsset() - ); - - $this->assertAttributeSame('foo', 'foo', $object); - $this->assertAttributeSame('bar', 'bar', $object); - $this->assertAttributeSame('blubb', 'blubb', $object); - $this->assertAttributeSame('quo', 'quo', $object); - $this->assertAttributeNotSame('quin', 'quin', $object); - } - - /** - * Verify that it can hydrate new properties on generic classes - */ - public function testCanHydrateGenericClassNonExistingProperties() - { - $object = $this->hydrator->hydrate(['newProperty' => 'newPropertyValue'], new ObjectPropertyTestAsset()); - - $this->assertAttributeSame('newPropertyValue', 'newProperty', $object); - } - - /** - * Verify that hydration is skipped for class properties (it is an object hydrator after all) - */ - public function testSkipsPublicStaticClassPropertiesHydration() - { - $this->hydrator->hydrate( - ['foo' => '1', 'bar' => '2', 'baz' => '3'], - new ClassWithPublicStaticProperties() - ); - - $this->assertSame('foo', ClassWithPublicStaticProperties::$foo); - $this->assertSame('bar', ClassWithPublicStaticProperties::$bar); - $this->assertSame('baz', ClassWithPublicStaticProperties::$baz); - } - - /** - * Verify that extraction is skipped for class properties (it is an object hydrator after all) - */ - public function testSkipsPublicStaticClassPropertiesExtraction() - { - $this->assertEmpty($this->hydrator->extract(new ClassWithPublicStaticProperties())); - } -} diff --git a/test/Hydrator/ReflectionTest.php b/test/Hydrator/ReflectionTest.php deleted file mode 100644 index 80af19711..000000000 --- a/test/Hydrator/ReflectionTest.php +++ /dev/null @@ -1,47 +0,0 @@ -hydrator = new Reflection(); - } - - public function testCanExtract() - { - $this->assertSame([], $this->hydrator->extract(new stdClass())); - } - - public function testCanHydrate() - { - $object = new stdClass(); - - $this->assertSame($object, $this->hydrator->hydrate(['foo' => 'bar'], $object)); - } -} diff --git a/test/Hydrator/Strategy/BooleanStrategyTest.php b/test/Hydrator/Strategy/BooleanStrategyTest.php deleted file mode 100644 index 6254a16cc..000000000 --- a/test/Hydrator/Strategy/BooleanStrategyTest.php +++ /dev/null @@ -1,102 +0,0 @@ -assertInstanceOf('Zend\Stdlib\Hydrator\Strategy\BooleanStrategy', new BooleanStrategy(1, 0)); - } - - public function testConstructorWithValidString() - { - $this->assertInstanceOf('Zend\Stdlib\Hydrator\Strategy\BooleanStrategy', new BooleanStrategy('true', 'false')); - } - - public function testExceptionOnWrongTrueValueInConstructor() - { - $this->setExpectedException( - 'Zend\Hydrator\Exception\InvalidArgumentException', - 'Expected int or string as $trueValue.' - ); - - new BooleanStrategy(true, 0); - } - - public function testExceptionOnWrongFalseValueInConstructor() - { - $this->setExpectedException( - 'Zend\Hydrator\Exception\InvalidArgumentException', - 'Expected int or string as $falseValue.' - ); - - new BooleanStrategy(1, false); - } - - public function testExtractString() - { - $hydrator = new BooleanStrategy('true', 'false'); - $this->assertEquals('true', $hydrator->extract(true)); - $this->assertEquals('false', $hydrator->extract(false)); - } - - public function testExtractInteger() - { - $hydrator = new BooleanStrategy(1, 0); - - $this->assertEquals(1, $hydrator->extract(true)); - $this->assertEquals(0, $hydrator->extract(false)); - } - - public function testExtractThrowsExceptionOnUnknownValue() - { - $hydrator = new BooleanStrategy(1, 0); - - $this->setExpectedException('Zend\Hydrator\Exception\InvalidArgumentException', 'Unable to extract'); - - $hydrator->extract(5); - } - - public function testHydrateString() - { - $hydrator = new BooleanStrategy('true', 'false'); - $this->assertEquals(true, $hydrator->hydrate('true')); - $this->assertEquals(false, $hydrator->hydrate('false')); - } - - public function testHydrateInteger() - { - $hydrator = new BooleanStrategy(1, 0); - $this->assertEquals(true, $hydrator->hydrate(1)); - $this->assertEquals(false, $hydrator->hydrate(0)); - } - - public function testHydrateUnexpectedValueThrowsException() - { - $this->setExpectedException('Zend\Hydrator\Exception\InvalidArgumentException', 'Unexpected value'); - $hydrator = new BooleanStrategy(1, 0); - $hydrator->hydrate(2); - } - - public function testHydrateInvalidArgument() - { - $this->setExpectedException('Zend\Hydrator\Exception\InvalidArgumentException', 'Unable to hydrate'); - $hydrator = new BooleanStrategy(1, 0); - $hydrator->hydrate(new \stdClass()); - } -} diff --git a/test/Hydrator/Strategy/ClosureStrategyTest.php b/test/Hydrator/Strategy/ClosureStrategyTest.php deleted file mode 100644 index e52dc0f44..000000000 --- a/test/Hydrator/Strategy/ClosureStrategyTest.php +++ /dev/null @@ -1,108 +0,0 @@ - 'foo', 'bar' => 'bar']), - ['foo' => 'FOO', 'bar' => 'BAR'], - ], - [ - function ($value, $data) { return isset($data['bar']) ? strtoupper($value) : $value; }, - new \ArrayObject(['foo' => 'foo', 'bar' => 'bar']), - ['foo' => 'FOO', 'bar' => 'BAR'], - ], - [ - function ($value, $data) { return isset($data['bar']) ? strtoupper($value) : $value; }, - new \ArrayObject(['foo' => 'foo', 'baz' => 'baz']), - ['foo' => 'foo', 'baz' => 'baz'], - ], - ]; - } - - /** - * @return array - */ - public function hydrateDataProvider() - { - return [ - [ - function ($value) { return strtoupper($value); }, - ['foo' => 'foo', 'bar' => 'bar'], - ['foo' => 'FOO', 'bar' => 'BAR'], - ], - [ - function ($value, $data) { return strtoupper($value); }, - ['foo' => 'foo', 'bar' => 'bar'], - ['foo' => 'FOO', 'bar' => 'BAR'], - ], - [ - function ($value, $data) { return isset($data['bar']) ? strtoupper($value) : $value; }, - ['foo' => 'foo', 'bar' => 'bar'], - ['foo' => 'FOO', 'bar' => 'BAR'], - ], - [ - function ($value, $data) { return isset($data['bar']) ? strtoupper($value) : $value; }, - ['foo' => 'foo', 'baz' => 'baz'], - ['foo' => 'foo', 'baz' => 'baz'], - ], - ]; - } - - /** - * @covers \Zend\Stdlib\Hydrator\Strategy\ClosureStrategy::extract() - * @dataProvider extractDataProvider - * - * @param Callable $extractFunc - * @param array $data - * @param array $expected - */ - public function testExtract($extractFunc, $data, $expected) - { - $strategy = new ClosureStrategy($extractFunc); - - $actual = []; - foreach ($data as $k => $value) { - $actual[$k] = $strategy->extract($value, $data); - } - - $this->assertSame($actual, $expected); - } - - /** - * @covers \Zend\Stdlib\Hydrator\Strategy\ClosureStrategy::hydrate() - * @dataProvider hydrateDataProvider - * - * @param Callable $hydrateFunc - * @param array $data - * @param array $expected - */ - public function testHydrate($hydrateFunc, $data, $expected) - { - $strategy = new ClosureStrategy(null, $hydrateFunc); - - $actual = []; - foreach ($data as $k => $value) { - $actual[$k] = $strategy->hydrate($value, $data); - } - - $this->assertSame($actual, $expected); - } -} diff --git a/test/Hydrator/Strategy/DateTimeFormatterStrategyTest.php b/test/Hydrator/Strategy/DateTimeFormatterStrategyTest.php deleted file mode 100644 index 67a106a2b..000000000 --- a/test/Hydrator/Strategy/DateTimeFormatterStrategyTest.php +++ /dev/null @@ -1,70 +0,0 @@ -assertEquals('2014-04-26', $strategy->hydrate('2014-04-26')->format('Y-m-d')); - - $strategy = new DateTimeFormatterStrategy('Y-m-d', new \DateTimeZone('Asia/Kathmandu')); - - $date = $strategy->hydrate('2014-04-26'); - $this->assertEquals('Asia/Kathmandu', $date->getTimezone()->getName()); - } - - public function testExtract() - { - $strategy = new DateTimeFormatterStrategy('d/m/Y'); - $this->assertEquals('26/04/2014', $strategy->extract(new \DateTime('2014-04-26'))); - } - - public function testGetNullWithInvalidDateOnHydration() - { - $strategy = new DateTimeFormatterStrategy('Y-m-d'); - $this->assertEquals(null, $strategy->hydrate(null)); - $this->assertEquals(null, $strategy->hydrate('')); - } - - public function testCanExtractIfNotDateTime() - { - $strategy = new DateTimeFormatterStrategy(); - $date = $strategy->extract(new \stdClass); - - $this->assertInstanceOf('stdClass', $date); - } - - public function testCanHydrateWithInvalidDateTime() - { - $strategy = new DateTimeFormatterStrategy('d/m/Y'); - $this->assertSame('foo bar baz', $strategy->hydrate('foo bar baz')); - } - - public function testAcceptsStringCastableDateTimeFormat() - { - $format = $this->getMock('stdClass', ['__toString']); - - $format->expects($this->once())->method('__toString')->will($this->returnValue('d/m/Y')); - - $strategy = new DateTimeFormatterStrategy($format); - - $this->assertEquals('26/04/2014', $strategy->extract(new \DateTime('2014-04-26'))); - $this->assertEquals('26/04/2015', $strategy->extract(new \DateTime('2015-04-26'))); - } -} diff --git a/test/Hydrator/Strategy/ExplodeStrategyTest.php b/test/Hydrator/Strategy/ExplodeStrategyTest.php deleted file mode 100644 index a43fa2768..000000000 --- a/test/Hydrator/Strategy/ExplodeStrategyTest.php +++ /dev/null @@ -1,154 +0,0 @@ -assertEquals($expected, $strategy->extract($extractValue)); - } else { - $this->assertSame($expected, $strategy->extract($extractValue)); - } - } - - public function testGetExceptionWithInvalidArgumentOnExtraction() - { - $strategy = new ExplodeStrategy(); - - $this->setExpectedException('Zend\Hydrator\Strategy\Exception\InvalidArgumentException'); - - $strategy->extract(''); - } - - public function testGetEmptyArrayWhenHydratingNullValue() - { - $strategy = new ExplodeStrategy(); - - $this->assertSame([], $strategy->hydrate(null)); - } - - public function testGetExceptionWithEmptyDelimiter() - { - $this->setExpectedException('Zend\Hydrator\Strategy\Exception\InvalidArgumentException'); - - new ExplodeStrategy(''); - } - - public function testGetExceptionWithInvalidDelimiter() - { - $this->setExpectedException('Zend\Hydrator\Strategy\Exception\InvalidArgumentException'); - - new ExplodeStrategy([]); - } - - public function testHydrateWithExplodeLimit() - { - $strategy = new ExplodeStrategy('-', 2); - $this->assertSame(['foo', 'bar-baz-bat'], $strategy->hydrate('foo-bar-baz-bat')); - - $strategy = new ExplodeStrategy('-', '3'); - $this->assertSame(['foo', 'bar', 'baz-bat'], $strategy->hydrate('foo-bar-baz-bat')); - } - - public function testHydrateWithInvalidScalarType() - { - $strategy = new ExplodeStrategy(); - - $this->setExpectedException( - 'Zend\Hydrator\Strategy\Exception\InvalidArgumentException', - 'Zend\Hydrator\Strategy\ExplodeStrategy::hydrate expects argument 1 to be string,' - . ' array provided instead' - ); - - $strategy->hydrate([]); - } - - public function testHydrateWithInvalidObjectType() - { - $strategy = new ExplodeStrategy(); - - $this->setExpectedException( - 'Zend\Hydrator\Strategy\Exception\InvalidArgumentException', - 'Zend\Hydrator\Strategy\ExplodeStrategy::hydrate expects argument 1 to be string,' - . ' stdClass provided instead' - ); - - $strategy->hydrate(new \stdClass()); - } - - public function testExtractWithInvalidObjectType() - { - $strategy = new ExplodeStrategy(); - - $this->setExpectedException( - 'Zend\Hydrator\Strategy\Exception\InvalidArgumentException', - 'Zend\Hydrator\Strategy\ExplodeStrategy::extract expects argument 1 to be array,' - . ' stdClass provided instead' - ); - - $strategy->extract(new \stdClass()); - } - - /** - * @dataProvider getValidHydratedValues - * - * @param mixed $value - * @param string $delimiter - * @param string[] $expected - */ - public function testHydration($value, $delimiter, array $expected) - { - $strategy = new ExplodeStrategy($delimiter); - - $this->assertSame($expected, $strategy->hydrate($value)); - } - - /** - * Data provider - * - * @return mixed[][] - */ - public function getValidHydratedValues() - { - return [ - [null, ',', []], - ['', ',', ['']], - ['foo', ',', ['foo']], - ['foo,bar', ',', ['foo', 'bar']], - ['foo.bar', '.', ['foo', 'bar']], - ['foo.bar', ',', ['foo.bar']], - [123, ',', ['123']], - [123, '2', ['1', '3']], - [123.456, ',', ['123.456']], - [123.456, '.', ['123', '456']], - ['foo,bar,dev,null', ',', ['foo', 'bar', 'dev', 'null']], - ['foo;bar;dev;null', ';', ['foo', 'bar', 'dev', 'null']], - ['', ',', ['']], - ]; - } -} diff --git a/test/Hydrator/Strategy/StrategyChainTest.php b/test/Hydrator/Strategy/StrategyChainTest.php deleted file mode 100644 index 765898cd6..000000000 --- a/test/Hydrator/Strategy/StrategyChainTest.php +++ /dev/null @@ -1,122 +0,0 @@ -assertEquals('something', $chain->hydrate('something')); - $this->assertEquals('something', $chain->extract('something')); - } - - public function testExtract() - { - $chain = new StrategyChain([ - new ClosureStrategy( - function ($value) { - return $value % 12; - } - ), - new ClosureStrategy( - function ($value) { - return $value % 9; - } - ), - ]); - $this->assertEquals(3, $chain->extract(87)); - - $chain = new StrategyChain([ - new ClosureStrategy( - function ($value) { - return $value % 8; - } - ), - new ClosureStrategy( - function ($value) { - return $value % 3; - } - ), - ]); - $this->assertEquals(1, $chain->extract(20)); - - $chain = new StrategyChain([ - new ClosureStrategy( - function ($value) { - return $value % 7; - } - ), - new ClosureStrategy( - function ($value) { - return $value % 6; - } - ), - ]); - $this->assertEquals(2, $chain->extract(30)); - } - - public function testHydrate() - { - $chain = new StrategyChain([ - new ClosureStrategy( - null, - function ($value) { - return $value % 3; - } - ), - new ClosureStrategy( - null, - function ($value) { - return $value % 7; - } - ) - ]); - $this->assertEquals(0, $chain->hydrate(87)); - - $chain = new StrategyChain([ - new ClosureStrategy( - null, - function ($value) { - return $value % 8; - } - ), - new ClosureStrategy( - null, - function ($value) { - return $value % 3; - } - ), - ]); - $this->assertEquals(2, $chain->hydrate(20)); - - $chain = new StrategyChain([ - new ClosureStrategy( - null, - function ($value) { - return $value % 4; - } - ), - new ClosureStrategy( - null, - function ($value) { - return $value % 9; - } - ), - ]); - $this->assertEquals(3, $chain->hydrate(30)); - } -} diff --git a/test/HydratorClosureStrategyTest.php b/test/HydratorClosureStrategyTest.php deleted file mode 100644 index d5ea3cc09..000000000 --- a/test/HydratorClosureStrategyTest.php +++ /dev/null @@ -1,120 +0,0 @@ -hydrator = new ObjectProperty(); - } - - public function testAddingStrategy() - { - $this->assertAttributeCount(0, 'strategies', $this->hydrator); - - $this->hydrator->addStrategy('myStrategy', new ClosureStrategy()); - - $this->assertAttributeCount(1, 'strategies', $this->hydrator); - } - - public function testCheckStrategyEmpty() - { - $this->assertFalse($this->hydrator->hasStrategy('myStrategy')); - } - - public function testCheckStrategyNotEmpty() - { - $this->hydrator->addStrategy('myStrategy', new ClosureStrategy()); - - $this->assertTrue($this->hydrator->hasStrategy('myStrategy')); - } - - public function testRemovingStrategy() - { - $this->assertAttributeCount(0, 'strategies', $this->hydrator); - - $this->hydrator->addStrategy('myStrategy', new ClosureStrategy()); - $this->assertAttributeCount(1, 'strategies', $this->hydrator); - - $this->hydrator->removeStrategy('myStrategy'); - $this->assertAttributeCount(0, 'strategies', $this->hydrator); - } - - public function testRetrieveStrategy() - { - $strategy = new ClosureStrategy(); - $this->hydrator->addStrategy('myStrategy', $strategy); - - $this->assertEquals($strategy, $this->hydrator->getStrategy('myStrategy')); - } - - public function testExtractingObjects() - { - $this->hydrator->addStrategy('field1', new ClosureStrategy( - function ($value) { - return sprintf('%s', $value); - }, - null - )); - $this->hydrator->addStrategy('field2', new ClosureStrategy( - function ($value) { - return sprintf('hello, %s!', $value); - }, - null - )); - - $entity = new TestAsset\HydratorClosureStrategyEntity(111, 'world'); - $values = $this->hydrator->extract($entity); - - $this->assertEquals(111, $values['field1']); - $this->assertEquals('hello, world!', $values['field2']); - } - - public function testHydratingObjects() - { - $this->hydrator->addStrategy('field2', new ClosureStrategy( - null, - function ($value) { - return sprintf('hello, %s!', $value); - } - )); - $this->hydrator->addStrategy('field3', new ClosureStrategy( - null, - function ($value) { - return new TestAsset\HydratorClosureStrategyEntity($value, sprintf('111%s', $value)); - } - )); - - $entity = new TestAsset\HydratorClosureStrategyEntity(111, 'world'); - - $values = $this->hydrator->extract($entity); - $values['field3'] = 333; - - $this->assertCount(2, (array) $entity); - $this->hydrator->hydrate($values, $entity); - $this->assertCount(3, (array) $entity); - - $this->assertInstanceOf('ZendTest\Stdlib\TestAsset\HydratorClosureStrategyEntity', $entity->field3); - } -} diff --git a/test/HydratorDeprecationTest.php b/test/HydratorDeprecationTest.php deleted file mode 100644 index 6b498b04c..000000000 --- a/test/HydratorDeprecationTest.php +++ /dev/null @@ -1,59 +0,0 @@ -fail('Catchable fatal error was triggered: ' . $errstr); - }, E_RECOVERABLE_ERROR); - $hydratorInjected->setHydrator($hydrator); - $this->assertSame($hydrator, $hydratorInjected->hydrator); - } - - public function testDeprecatedHydratorInterfaceIsAcceptedByMethodsTypehintedWithNewInterface() - { - $hydratorInjected = new TestAsset\HydratorInjectedObjectUsingDeprecatedInterfaceTypehint(); - $hydrator = new TestAsset\DeprecatedInterfaceHydrator(); - set_error_handler(function ($errno, $errstr) { - $this->fail('Catchable fatal error was triggered: ' . $errstr); - }, E_RECOVERABLE_ERROR); - $hydratorInjected->setHydrator($hydrator); - $this->assertSame($hydrator, $hydratorInjected->hydrator); - } - - public function testDeprecatedHydratorInterfaceIsAcceptedByMethodsTypehintedWithDeprecatedHydrationInterface() - { - $hydratorInjected = new TestAsset\HydratorInjectedObjectUsingDeprecatedHydrationInterfaceTypehint(); - $hydrator = new TestAsset\DeprecatedInterfaceHydrator(); - set_error_handler(function ($errno, $errstr) { - $this->fail('Catchable fatal error was triggered: ' . $errstr); - }, E_RECOVERABLE_ERROR); - $hydratorInjected->setHydrator($hydrator); - $this->assertSame($hydrator, $hydratorInjected->hydrator); - } - - public function testDeprecatedHydratorInterfaceIsAcceptedByMethodsTypehintedWithDeprecatedExtractionInterface() - { - $hydratorInjected = new TestAsset\HydratorInjectedObjectUsingDeprecatedExtractionInterfaceTypehint(); - $hydrator = new TestAsset\DeprecatedInterfaceHydrator(); - set_error_handler(function ($errno, $errstr) { - $this->fail('Catchable fatal error was triggered: ' . $errstr); - }, E_RECOVERABLE_ERROR); - $hydratorInjected->setExtractor($hydrator); - $this->assertSame($hydrator, $hydratorInjected->extractor); - } -} diff --git a/test/HydratorObjectPropertyTest.php b/test/HydratorObjectPropertyTest.php deleted file mode 100644 index f1cafe8f1..000000000 --- a/test/HydratorObjectPropertyTest.php +++ /dev/null @@ -1,57 +0,0 @@ -hydrator = new ObjectProperty(); - } - - public function testMultipleInvocationsWithDifferentFiltersFindsAllProperties() - { - $instance = (object) []; - - $instance->id = 4; - $instance->array = [4, 3, 5, 6]; - $instance->object = (object) []; - $instance->object->id = 4; - - $this->hydrator->addFilter('values', function ($property) { - return true; - }); - $result = $this->hydrator->extract($instance); - $this->assertArrayHasKey('id', $result); - $this->assertEquals($instance->id, $result['id']); - $this->assertArrayHasKey('array', $result); - $this->assertEquals($instance->array, $result['array']); - $this->assertArrayHasKey('object', $result); - $this->assertSame($instance->object, $result['object']); - - $this->hydrator->removeFilter('values'); - $this->hydrator->addFilter('complex', function ($property) { - switch ($property) { - case 'array': - case 'object': - return false; - default: - return true; - } - }); - $result = $this->hydrator->extract($instance); - $this->assertArrayHasKey('id', $result); - $this->assertEquals($instance->id, $result['id']); - $this->assertArrayNotHasKey('array', $result); - $this->assertArrayNotHasKey('object', $result); - } -} diff --git a/test/HydratorStrategyTest.php b/test/HydratorStrategyTest.php deleted file mode 100644 index fc0c179fd..000000000 --- a/test/HydratorStrategyTest.php +++ /dev/null @@ -1,166 +0,0 @@ -hydrator = new ClassMethods(); - } - - public function testAddingStrategy() - { - $this->assertAttributeCount(0, 'strategies', $this->hydrator); - - $this->hydrator->addStrategy('myStrategy', new TestAsset\HydratorStrategy()); - - $this->assertAttributeCount(1, 'strategies', $this->hydrator); - } - - public function testCheckStrategyEmpty() - { - $this->assertFalse($this->hydrator->hasStrategy('myStrategy')); - } - - public function testCheckStrategyNotEmpty() - { - $this->hydrator->addStrategy('myStrategy', new TestAsset\HydratorStrategy()); - - $this->assertTrue($this->hydrator->hasStrategy('myStrategy')); - } - - public function testRemovingStrategy() - { - $this->assertAttributeCount(0, 'strategies', $this->hydrator); - - $this->hydrator->addStrategy('myStrategy', new TestAsset\HydratorStrategy()); - $this->assertAttributeCount(1, 'strategies', $this->hydrator); - - $this->hydrator->removeStrategy('myStrategy'); - $this->assertAttributeCount(0, 'strategies', $this->hydrator); - } - - public function testRetrieveStrategy() - { - $strategy = new TestAsset\HydratorStrategy(); - $this->hydrator->addStrategy('myStrategy', $strategy); - - $this->assertEquals($strategy, $this->hydrator->getStrategy('myStrategy')); - } - - public function testExtractingObjects() - { - $this->hydrator->addStrategy('entities', new TestAsset\HydratorStrategy()); - - $entityA = new TestAsset\HydratorStrategyEntityA(); - $entityA->addEntity(new TestAsset\HydratorStrategyEntityB(111, 'AAA')); - $entityA->addEntity(new TestAsset\HydratorStrategyEntityB(222, 'BBB')); - - $attributes = $this->hydrator->extract($entityA); - - $this->assertContains(111, $attributes['entities']); - $this->assertContains(222, $attributes['entities']); - } - - public function testHydratingObjects() - { - $this->hydrator->addStrategy('entities', new TestAsset\HydratorStrategy()); - - $entityA = new TestAsset\HydratorStrategyEntityA(); - $entityA->addEntity(new TestAsset\HydratorStrategyEntityB(111, 'AAA')); - $entityA->addEntity(new TestAsset\HydratorStrategyEntityB(222, 'BBB')); - - $attributes = $this->hydrator->extract($entityA); - $attributes['entities'][] = 333; - - $this->hydrator->hydrate($attributes, $entityA); - $entities = $entityA->getEntities(); - - $this->assertCount(3, $entities); - } - - /** - * @dataProvider underscoreHandlingDataProvider - */ - public function testWhenUsingUnderscoreSeparatedKeysHydratorStrategyIsAlwaysConsideredUnderscoreSeparatedToo($underscoreSeparatedKeys, $formFieldKey) - { - $hydrator = new ClassMethods($underscoreSeparatedKeys); - - $strategy = $this->getMock('Zend\Stdlib\Hydrator\Strategy\StrategyInterface'); - - $entity = new TestAsset\ClassMethodsUnderscore(); - $value = $entity->getFooBar(); - - $hydrator->addStrategy($formFieldKey, $strategy); - - $strategy - ->expects($this->once()) - ->method('extract') - ->with($this->identicalTo($value)) - ->will($this->returnValue($value)) - ; - - $attributes = $hydrator->extract($entity); - - $strategy - ->expects($this->once()) - ->method('hydrate') - ->with($this->identicalTo($value)) - ->will($this->returnValue($value)) - ; - - $hydrator->hydrate($attributes, $entity); - } - - public function underscoreHandlingDataProvider() - { - return [ - [true, 'foo_bar'], - [false, 'fooBar'], - ]; - } - - public function testContextAwarenessExtract() - { - $strategy = new TestAsset\HydratorStrategyContextAware(); - $this->hydrator->addStrategy('field2', $strategy); - - $entityB = new TestAsset\HydratorStrategyEntityB('X', 'Y'); - $attributes = $this->hydrator->extract($entityB); - - $this->assertEquals($entityB, $strategy->object); - } - - public function testContextAwarenessHydrate() - { - $strategy = new TestAsset\HydratorStrategyContextAware(); - $this->hydrator->addStrategy('field2', $strategy); - - $entityB = new TestAsset\HydratorStrategyEntityB('X', 'Y'); - $data = ['field1' => 'A', 'field2' => 'B']; - $attributes = $this->hydrator->hydrate($data, $entityB); - - $this->assertEquals($data, $strategy->data); - } -} diff --git a/test/HydratorTest.php b/test/HydratorTest.php deleted file mode 100644 index 4e67cd4d8..000000000 --- a/test/HydratorTest.php +++ /dev/null @@ -1,489 +0,0 @@ -classMethodsCamelCase = new ClassMethodsCamelCase(); - $this->classMethodsTitleCase = new ClassMethodsTitleCase(); - $this->classMethodsCamelCaseMissing = new ClassMethodsCamelCaseMissing(); - $this->classMethodsUnderscore = new ClassMethodsUnderscore(); - $this->classMethodsInvalidParameter = new ClassMethodsInvalidParameter(); - $this->reflection = new ReflectionAsset; - $this->classMethodsInvalidParameter = new ClassMethodsInvalidParameter(); - } - - public function testInitiateValues() - { - $this->assertEquals($this->classMethodsCamelCase->getFooBar(), '1'); - $this->assertEquals($this->classMethodsCamelCase->getFooBarBaz(), '2'); - $this->assertEquals($this->classMethodsCamelCase->getIsFoo(), true); - $this->assertEquals($this->classMethodsCamelCase->isBar(), true); - $this->assertEquals($this->classMethodsCamelCase->getHasFoo(), true); - $this->assertEquals($this->classMethodsCamelCase->hasBar(), true); - $this->assertEquals($this->classMethodsTitleCase->getFooBar(), '1'); - $this->assertEquals($this->classMethodsTitleCase->getFooBarBaz(), '2'); - $this->assertEquals($this->classMethodsTitleCase->getIsFoo(), true); - $this->assertEquals($this->classMethodsTitleCase->getIsBar(), true); - $this->assertEquals($this->classMethodsTitleCase->getHasFoo(), true); - $this->assertEquals($this->classMethodsTitleCase->getHasBar(), true); - $this->assertEquals($this->classMethodsUnderscore->getFooBar(), '1'); - $this->assertEquals($this->classMethodsUnderscore->getFooBarBaz(), '2'); - $this->assertEquals($this->classMethodsUnderscore->getIsFoo(), true); - $this->assertEquals($this->classMethodsUnderscore->isBar(), true); - $this->assertEquals($this->classMethodsUnderscore->getHasFoo(), true); - $this->assertEquals($this->classMethodsUnderscore->hasBar(), true); - } - - public function testHydratorReflection() - { - $hydrator = new Reflection; - $datas = $hydrator->extract($this->reflection); - $this->assertTrue(isset($datas['foo'])); - $this->assertEquals($datas['foo'], '1'); - $this->assertTrue(isset($datas['fooBar'])); - $this->assertEquals($datas['fooBar'], '2'); - $this->assertTrue(isset($datas['fooBarBaz'])); - $this->assertEquals($datas['fooBarBaz'], '3'); - - $test = $hydrator->hydrate(['foo' => 'foo', 'fooBar' => 'bar', 'fooBarBaz' => 'baz'], $this->reflection); - $this->assertEquals($test->foo, 'foo'); - $this->assertEquals($test->getFooBar(), 'bar'); - $this->assertEquals($test->getFooBarBaz(), 'baz'); - } - - public function testHydratorClassMethodsCamelCase() - { - $hydrator = new ClassMethods(false); - $datas = $hydrator->extract($this->classMethodsCamelCase); - $this->assertTrue(isset($datas['fooBar'])); - $this->assertEquals($datas['fooBar'], '1'); - $this->assertTrue(isset($datas['fooBarBaz'])); - $this->assertFalse(isset($datas['foo_bar'])); - $this->assertTrue(isset($datas['isFoo'])); - $this->assertEquals($datas['isFoo'], true); - $this->assertTrue(isset($datas['isBar'])); - $this->assertEquals($datas['isBar'], true); - $this->assertTrue(isset($datas['hasFoo'])); - $this->assertEquals($datas['hasFoo'], true); - $this->assertTrue(isset($datas['hasBar'])); - $this->assertEquals($datas['hasBar'], true); - $test = $hydrator->hydrate( - [ - 'fooBar' => 'foo', - 'fooBarBaz' => 'bar', - 'isFoo' => false, - 'isBar' => false, - 'hasFoo' => false, - 'hasBar' => false, - ], - $this->classMethodsCamelCase - ); - $this->assertSame($this->classMethodsCamelCase, $test); - $this->assertEquals($test->getFooBar(), 'foo'); - $this->assertEquals($test->getFooBarBaz(), 'bar'); - $this->assertEquals($test->getIsFoo(), false); - $this->assertEquals($test->isBar(), false); - $this->assertEquals($test->getHasFoo(), false); - $this->assertEquals($test->hasBar(), false); - } - - public function testHydratorClassMethodsTitleCase() - { - $hydrator = new ClassMethods(false); - $datas = $hydrator->extract($this->classMethodsTitleCase); - $this->assertTrue(isset($datas['FooBar'])); - $this->assertEquals($datas['FooBar'], '1'); - $this->assertTrue(isset($datas['FooBarBaz'])); - $this->assertFalse(isset($datas['foo_bar'])); - $this->assertTrue(isset($datas['IsFoo'])); - $this->assertEquals($datas['IsFoo'], true); - $this->assertTrue(isset($datas['IsBar'])); - $this->assertEquals($datas['IsBar'], true); - $this->assertTrue(isset($datas['HasFoo'])); - $this->assertEquals($datas['HasFoo'], true); - $this->assertTrue(isset($datas['HasBar'])); - $this->assertEquals($datas['HasBar'], true); - $test = $hydrator->hydrate( - [ - 'FooBar' => 'foo', - 'FooBarBaz' => 'bar', - 'IsFoo' => false, - 'IsBar' => false, - 'HasFoo' => false, - 'HasBar' => false, - ], - $this->classMethodsTitleCase - ); - $this->assertSame($this->classMethodsTitleCase, $test); - $this->assertEquals($test->getFooBar(), 'foo'); - $this->assertEquals($test->getFooBarBaz(), 'bar'); - $this->assertEquals($test->getIsFoo(), false); - $this->assertEquals($test->getIsBar(), false); - $this->assertEquals($test->getHasFoo(), false); - $this->assertEquals($test->getHasBar(), false); - } - - public function testHydratorClassMethodsUnderscore() - { - $hydrator = new ClassMethods(true); - $datas = $hydrator->extract($this->classMethodsUnderscore); - $this->assertTrue(isset($datas['foo_bar'])); - $this->assertEquals($datas['foo_bar'], '1'); - $this->assertTrue(isset($datas['foo_bar_baz'])); - $this->assertFalse(isset($datas['fooBar'])); - $this->assertTrue(isset($datas['is_foo'])); - $this->assertFalse(isset($datas['isFoo'])); - $this->assertEquals($datas['is_foo'], true); - $this->assertTrue(isset($datas['is_bar'])); - $this->assertFalse(isset($datas['isBar'])); - $this->assertEquals($datas['is_bar'], true); - $this->assertTrue(isset($datas['has_foo'])); - $this->assertFalse(isset($datas['hasFoo'])); - $this->assertEquals($datas['has_foo'], true); - $this->assertTrue(isset($datas['has_bar'])); - $this->assertFalse(isset($datas['hasBar'])); - $this->assertEquals($datas['has_bar'], true); - $test = $hydrator->hydrate( - [ - 'foo_bar' => 'foo', - 'foo_bar_baz' => 'bar', - 'is_foo' => false, - 'is_bar' => false, - 'has_foo' => false, - 'has_bar' => false, - ], - $this->classMethodsUnderscore - ); - $this->assertSame($this->classMethodsUnderscore, $test); - $this->assertEquals($test->getFooBar(), 'foo'); - $this->assertEquals($test->getFooBarBaz(), 'bar'); - $this->assertEquals($test->getIsFoo(), false); - $this->assertEquals($test->isBar(), false); - $this->assertEquals($test->getHasFoo(), false); - $this->assertEquals($test->hasBar(), false); - } - - public function testHydratorClassMethodsUnderscoreWithUnderscoreUpperCasedHydrateDataKeys() - { - $hydrator = new ClassMethods(true); - $datas = $hydrator->extract($this->classMethodsUnderscore); - $test = $hydrator->hydrate( - [ - 'FOO_BAR' => 'foo', - 'FOO_BAR_BAZ' => 'bar', - 'IS_FOO' => false, - 'IS_BAR' => false, - 'HAS_FOO' => false, - 'HAS_BAR' => false, - ], - $this->classMethodsUnderscore - ); - $this->assertSame($this->classMethodsUnderscore, $test); - $this->assertEquals($test->getFooBar(), 'foo'); - $this->assertEquals($test->getFooBarBaz(), 'bar'); - $this->assertEquals($test->getIsFoo(), false); - $this->assertEquals($test->isBar(), false); - $this->assertEquals($test->getHasFoo(), false); - $this->assertEquals($test->hasBar(), false); - } - - public function testHydratorClassMethodsOptions() - { - $hydrator = new ClassMethods(); - $this->assertTrue($hydrator->getUnderscoreSeparatedKeys()); - $hydrator->setOptions(['underscoreSeparatedKeys' => false]); - $this->assertFalse($hydrator->getUnderscoreSeparatedKeys()); - $hydrator->setUnderscoreSeparatedKeys(true); - $this->assertTrue($hydrator->getUnderscoreSeparatedKeys()); - } - - public function testHydratorClassMethodsIgnoresInvalidValues() - { - $hydrator = new ClassMethods(true); - $data = [ - 'foo_bar' => '1', - 'foo_bar_baz' => '2', - 'invalid' => 'value' - ]; - $test = $hydrator->hydrate($data, $this->classMethodsUnderscore); - $this->assertSame($this->classMethodsUnderscore, $test); - } - - public function testHydratorClassMethodsDefaultBehaviorIsConvertUnderscoreToCamelCase() - { - $hydrator = new ClassMethods(); - $datas = $hydrator->extract($this->classMethodsUnderscore); - $this->assertTrue(isset($datas['foo_bar'])); - $this->assertEquals($datas['foo_bar'], '1'); - $this->assertTrue(isset($datas['foo_bar_baz'])); - $this->assertFalse(isset($datas['fooBar'])); - $test = $hydrator->hydrate(['foo_bar' => 'foo', 'foo_bar_baz' => 'bar'], $this->classMethodsUnderscore); - $this->assertSame($this->classMethodsUnderscore, $test); - $this->assertEquals($test->getFooBar(), 'foo'); - $this->assertEquals($test->getFooBarBaz(), 'bar'); - } - - public function testRetrieveWildStrategyAndOther() - { - $hydrator = new ClassMethods(); - $hydrator->addStrategy('default', new DefaultStrategy()); - $hydrator->addStrategy('*', new SerializableStrategy('phpserialize')); - $default = $hydrator->getStrategy('default'); - $this->assertEquals(get_class($default), 'Zend\Stdlib\Hydrator\Strategy\DefaultStrategy'); - $serializable = $hydrator->getStrategy('*'); - $this->assertEquals(get_class($serializable), 'Zend\Stdlib\Hydrator\Strategy\SerializableStrategy'); - } - - public function testUseWildStrategyByDefault() - { - $hydrator = new ClassMethods(); - $datas = $hydrator->extract($this->classMethodsUnderscore); - $this->assertEquals($datas['foo_bar'], '1'); - $hydrator->addStrategy('*', new SerializableStrategy('phpserialize')); - $datas = $hydrator->extract($this->classMethodsUnderscore); - $this->assertEquals($datas['foo_bar'], 's:1:"1";'); - } - - public function testUseWildStrategyAndOther() - { - $hydrator = new ClassMethods(); - $datas = $hydrator->extract($this->classMethodsUnderscore); - $this->assertEquals($datas['foo_bar'], '1'); - $hydrator->addStrategy('foo_bar', new DefaultStrategy()); - $hydrator->addStrategy('*', new SerializableStrategy('phpserialize')); - $datas = $hydrator->extract($this->classMethodsUnderscore); - $this->assertEquals($datas['foo_bar'], '1'); - $this->assertEquals($datas['foo_bar_baz'], 's:1:"2";'); - } - - public function testHydratorClassMethodsCamelCaseWithSetterMissing() - { - $hydrator = new ClassMethods(false); - - $datas = $hydrator->extract($this->classMethodsCamelCaseMissing); - $this->assertTrue(isset($datas['fooBar'])); - $this->assertEquals($datas['fooBar'], '1'); - $this->assertTrue(isset($datas['fooBarBaz'])); - $this->assertFalse(isset($datas['foo_bar'])); - $test = $hydrator->hydrate(['fooBar' => 'foo', 'fooBarBaz' => 1], $this->classMethodsCamelCaseMissing); - $this->assertSame($this->classMethodsCamelCaseMissing, $test); - $this->assertEquals($test->getFooBar(), 'foo'); - $this->assertEquals($test->getFooBarBaz(), '2'); - } - - public function testHydratorClassMethodsManipulateFilter() - { - $hydrator = new ClassMethods(false); - $datas = $hydrator->extract($this->classMethodsCamelCase); - - $this->assertTrue(isset($datas['fooBar'])); - $this->assertEquals($datas['fooBar'], '1'); - $this->assertTrue(isset($datas['fooBarBaz'])); - $this->assertFalse(isset($datas['foo_bar'])); - $this->assertTrue(isset($datas['isFoo'])); - $this->assertEquals($datas['isFoo'], true); - $this->assertTrue(isset($datas['isBar'])); - $this->assertEquals($datas['isBar'], true); - $this->assertTrue(isset($datas['hasFoo'])); - $this->assertEquals($datas['hasFoo'], true); - $this->assertTrue(isset($datas['hasBar'])); - $this->assertEquals($datas['hasBar'], true); - - $hydrator->removeFilter('has'); - $datas = $hydrator->extract($this->classMethodsCamelCase); - $this->assertTrue(isset($datas['hasFoo'])); //method is getHasFoo - $this->assertFalse(isset($datas['hasBar'])); //method is hasBar - } - - public function testHydratorClassMethodsWithCustomFilter() - { - $hydrator = new ClassMethods(false); - $datas = $hydrator->extract($this->classMethodsCamelCase); - $hydrator->addFilter("exclude", - function ($property) { - list($class, $method) = explode('::', $property); - - if ($method == 'getHasFoo') { - return false; - } - - return true; - }, FilterComposite::CONDITION_AND - ); - - $datas = $hydrator->extract($this->classMethodsCamelCase); - $this->assertFalse(isset($datas['hasFoo'])); - } - - /** - * @dataProvider filterProvider - */ - public function testArraySerializableFilter($hydrator, $serializable) - { - $this->assertSame( - [ - "foo" => "bar", - "bar" => "foo", - "blubb" => "baz", - "quo" => "blubb" - ], - $hydrator->extract($serializable) - ); - - $hydrator->addFilter("foo", function ($property) { - if ($property == "foo") { - return false; - } - return true; - }); - - $this->assertSame( - [ - "bar" => "foo", - "blubb" => "baz", - "quo" => "blubb" - ], - $hydrator->extract($serializable) - ); - - $hydrator->addFilter("len", function ($property) { - if (strlen($property) !== 3) { - return false; - } - return true; - }, FilterComposite::CONDITION_AND); - - $this->assertSame( - [ - "bar" => "foo", - "quo" => "blubb" - ], - $hydrator->extract($serializable) - ); - - $hydrator->removeFilter("len"); - $hydrator->removeFilter("foo"); - - $this->assertSame( - [ - "foo" => "bar", - "bar" => "foo", - "blubb" => "baz", - "quo" => "blubb" - ], - $hydrator->extract($serializable) - ); - } - - public function filterProvider() - { - return [ - [new ObjectProperty(), new ObjectPropertyAsset], - [new ArraySerializable(), new ArraySerializableAsset], - [new Reflection(), new ReflectionFilter] - ]; - } - - public function testHydratorClassMethodsWithInvalidNumberOfParameters() - { - $hydrator = new ClassMethods(false); - $datas = $hydrator->extract($this->classMethodsInvalidParameter); - - $this->assertTrue($datas['hasBar']); - $this->assertEquals('Bar', $datas['foo']); - $this->assertFalse($datas['isBla']); - } - - public function testObjectBasedFilters() - { - $hydrator = new ClassMethods(false); - $foo = new ClassMethodsFilterProviderInterface(); - $data = $hydrator->extract($foo); - $this->assertArrayNotHasKey("filter", $data); - $this->assertSame("bar", $data["foo"]); - $this->assertSame("foo", $data["bar"]); - } - - public function testHydratorClassMethodsWithProtectedSetter() - { - $hydrator = new ClassMethods(false); - $object = new ClassMethodsProtectedSetter(); - $hydrator->hydrate(['foo' => 'bar', 'bar' => 'BAR'], $object); - $data = $hydrator->extract($object); - - $this->assertEquals($data['bar'], 'BAR'); - } - - public function testHydratorClassMethodsWithMagicMethodSetter() - { - $hydrator = new ClassMethods(false); - $object = new ClassMethodsMagicMethodSetter(); - $hydrator->hydrate(['foo' => 'bar'], $object); - $data = $hydrator->extract($object); - - $this->assertEquals($data['foo'], 'bar'); - } -} diff --git a/test/Strategy/SerializableStrategyTest.php b/test/Strategy/SerializableStrategyTest.php deleted file mode 100644 index b06be5d82..000000000 --- a/test/Strategy/SerializableStrategyTest.php +++ /dev/null @@ -1,52 +0,0 @@ -setExpectedException('Zend\Hydrator\Exception\InvalidArgumentException'); - $serializerStrategy = new SerializableStrategy(false); - } - - public function testUseBadSerilizerObject() - { - $serializer = Serializer::factory('phpserialize'); - $serializerStrategy = new SerializableStrategy($serializer); - $this->assertEquals($serializer, $serializerStrategy->getSerializer()); - } - - public function testUseBadSerilizerString() - { - $serializerStrategy = new SerializableStrategy('phpserialize'); - $this->assertEquals('Zend\Serializer\Adapter\PhpSerialize', get_class($serializerStrategy->getSerializer())); - } - - public function testCanSerialize() - { - $serializer = Serializer::factory('phpserialize'); - $serializerStrategy = new SerializableStrategy($serializer); - $serialized = $serializerStrategy->extract('foo'); - $this->assertEquals($serialized, 's:3:"foo";'); - } - - public function testCanUnserialize() - { - $serializer = Serializer::factory('phpserialize'); - $serializerStrategy = new SerializableStrategy($serializer); - $serialized = $serializerStrategy->hydrate('s:3:"foo";'); - $this->assertEquals($serialized, 'foo'); - } -} diff --git a/test/TestAsset/AggregateObject.php b/test/TestAsset/AggregateObject.php deleted file mode 100644 index b2471064f..000000000 --- a/test/TestAsset/AggregateObject.php +++ /dev/null @@ -1,59 +0,0 @@ - 'Zaphod'); - - /** - * @var string - */ - public $maintainer = 'Marvin'; - - /** - * @return string - */ - public function getMaintainer() - { - return $this->maintainer; - } - - /** - * @param string $maintainer - */ - public function setMaintainer($maintainer) - { - $this->maintainer = $maintainer; - } - - /** - * @return array - */ - public function getArrayCopy() - { - return $this->arrayData; - } - - /** - * @param array $data - */ - public function exchangeArray(array $data) - { - $this->arrayData = $data; - } -} diff --git a/test/TestAsset/ClassMethodsCamelCase.php b/test/TestAsset/ClassMethodsCamelCase.php deleted file mode 100644 index 552528032..000000000 --- a/test/TestAsset/ClassMethodsCamelCase.php +++ /dev/null @@ -1,91 +0,0 @@ -fooBar; - } - - public function setFooBar($value) - { - $this->fooBar = $value; - return $this; - } - - public function getFooBarBaz() - { - return $this->fooBarBaz; - } - - public function setFooBarBaz($value) - { - $this->fooBarBaz = $value; - return $this; - } - - public function getIsFoo() - { - return $this->isFoo; - } - - public function setIsFoo($value) - { - $this->isFoo = $value; - return $this; - } - - public function isBar() - { - return $this->isBar; - } - - public function setIsBar($value) - { - $this->isBar = $value; - return $this; - } - - public function getHasFoo() - { - return $this->hasFoo; - } - - public function setHasFoo($value) - { - $this->hasFoo = $value; - return $this; - } - - public function hasBar() - { - return $this->hasBar; - } - - public function setHasBar($value) - { - $this->hasBar = $value; - return $this; - } -} diff --git a/test/TestAsset/ClassMethodsCamelCaseMissing.php b/test/TestAsset/ClassMethodsCamelCaseMissing.php deleted file mode 100644 index eb359deaa..000000000 --- a/test/TestAsset/ClassMethodsCamelCaseMissing.php +++ /dev/null @@ -1,43 +0,0 @@ -fooBar; - } - - public function setFooBar($value) - { - $this->fooBar = $value; - return $this; - } - - public function getFooBarBaz() - { - return $this->fooBarBaz; - } - - /* - * comment to detection verification - * - public function setFooBarBaz($value) - { - $this->fooBarBaz = $value; - return $this; - } - */ -} diff --git a/test/TestAsset/ClassMethodsExtendsHydrator.php b/test/TestAsset/ClassMethodsExtendsHydrator.php deleted file mode 100644 index af79cefca..000000000 --- a/test/TestAsset/ClassMethodsExtendsHydrator.php +++ /dev/null @@ -1,228 +0,0 @@ -setUnderscoreSeparatedKeys($underscoreSeparatedKeys); - $this->setExtractExtendedProperties($extractExtendedProperties); - - $this->callableMethodFilter = new OptionalParametersFilter(); - - $this->filterComposite->addFilter('is', new IsFilter()); - $this->filterComposite->addFilter('has', new HasFilter()); - $this->filterComposite->addFilter('get', new GetFilter()); - $this->filterComposite->addFilter('parameter', new OptionalParametersFilter(), FilterComposite::CONDITION_AND); - } - - /** - * @param array|Traversable $options - * @return ClassMethodsExtends - * @throws Exception\InvalidArgumentException - */ - public function setOptions($options) - { - if ($options instanceof Traversable) { - $options = ArrayUtils::iteratorToArray($options); - } elseif (!is_array($options)) { - throw new Exception\InvalidArgumentException( - 'The options parameter must be an array or a Traversable' - ); - } - if (isset($options['underscoreSeparatedKeys'])) { - $this->setUnderscoreSeparatedKeys($options['underscoreSeparatedKeys']); - } - if (isset($options['extractExtendedProperties'])) { - $this->setExtractExtendedProperties($options['extractExtendedProperties']); - } - - return $this; - } - - /** - * @param bool $underscoreSeparatedKeys - * @return ClassMethodsExtends - */ - public function setUnderscoreSeparatedKeys($underscoreSeparatedKeys) - { - $this->underscoreSeparatedKeys = (bool) $underscoreSeparatedKeys; - - if ($this->underscoreSeparatedKeys) { - $this->setNamingStrategy(new UnderscoreNamingStrategy); - } elseif ($this->getNamingStrategy() instanceof UnderscoreNamingStrategy) { - $this->removeNamingStrategy(); - } - - return $this; - } - - /** - * @return bool - */ - public function getUnderscoreSeparatedKeys() - { - return $this->underscoreSeparatedKeys; - } - - /** - * @param bool $extractExtendedProperties - * @return ClassMethodsExtends - */ - public function setExtractExtendedProperties($extractExtendedProperties) - { - $this->extractExtendedProperties = (bool) $extractExtendedProperties; - - if ($this->extractExtendedProperties) { - $this->filterComposite->removeFilter('skipExtended'); - } else { - $this->filterComposite->addFilter('skipExtended', new MethodMatchFilter('getExtended'), FilterComposite::CONDITION_AND); - } - - return $this; - } - - /** - * @return bool - */ - public function getExtractExtendedProperties() - { - return $this->extractExtendedProperties; - } - - /** - * Extract values from an object with class methods - * - * Extracts the getter/setter of the given $object. - * - * @param object $object - * @return array - * @throws Exception\BadMethodCallException for a non-object $object - */ - public function extract($object) - { - if (!is_object($object)) { - throw new Exception\BadMethodCallException( - sprintf('%s expects the provided $object to be a PHP object)', __METHOD__) - ); - } - - $filter = null; - if ($object instanceof FilterProviderInterface) { - $filter = new FilterComposite( - array($object->getFilter()), - array(new MethodMatchFilter('getFilter')) - ); - } else { - $filter = $this->filterComposite; - } - - $attributes = array(); - $methods = get_class_methods($object); - - foreach ($methods as $method) { - if (!$filter->filter(get_class($object) . '::' . $method)) { - continue; - } - - if (!$this->callableMethodFilter->filter(get_class($object) . '::' . $method)) { - continue; - } - - $attribute = $method; - if (preg_match('/^get/', $method)) { - $attribute = substr($method, 3); - if (!property_exists($object, $attribute)) { - $attribute = lcfirst($attribute); - } - } - - $attribute = $this->extractName($attribute, $object); - $attributes[$attribute] = $this->extractValue($attribute, $object->$method(), $object); - } - - return $attributes; - } - - /** - * Hydrate an object by populating getter/setter methods - * - * Hydrates an object by getter/setter methods of the object. - * - * @param array $data - * @param object $object - * @return object - * @throws Exception\BadMethodCallException for a non-object $object - */ - public function hydrate(array $data, $object) - { - if (!is_object($object)) { - throw new Exception\BadMethodCallException( - sprintf('%s expects the provided $object to be a PHP object)', __METHOD__) - ); - } - - foreach ($data as $property => $value) { - $method = 'set' . ucfirst($this->hydrateName($property, $data)); - $value = $this->hydrateValue($property, $value, $data); - if (is_callable(array($object, $method))) { - $object->$method($value); - } else if (is_callable(array($object, 'setExtended'))) { - $object->setExtended($property, $value); - } - } - - return $object; - } -} diff --git a/test/TestAsset/ClassMethodsFilterProviderInterface.php b/test/TestAsset/ClassMethodsFilterProviderInterface.php deleted file mode 100644 index f5b9662f4..000000000 --- a/test/TestAsset/ClassMethodsFilterProviderInterface.php +++ /dev/null @@ -1,69 +0,0 @@ -addFilter("get", new GetFilter()); - $excludes = new FilterComposite(); - $excludes->addFilter( - "servicemanager", - new MethodMatchFilter("getServiceManager"), - FilterComposite::CONDITION_AND - ); - $excludes->addFilter( - "eventmanager", - new MethodMatchFilter("getEventManager"), - FilterComposite::CONDITION_AND - ); - $filterComposite->addFilter("excludes", $excludes, FilterComposite::CONDITION_AND); - - return $filterComposite; - } -} diff --git a/test/TestAsset/ClassMethodsInvalidParameter.php b/test/TestAsset/ClassMethodsInvalidParameter.php deleted file mode 100644 index ac3162dc5..000000000 --- a/test/TestAsset/ClassMethodsInvalidParameter.php +++ /dev/null @@ -1,42 +0,0 @@ - 3 && strtolower(substr($method, 3)) == 'foo') { - $this->foo = $args[0]; - } - } - - public function getFoo() - { - return $this->foo; - } -} diff --git a/test/TestAsset/ClassMethodsOptionalParameters.php b/test/TestAsset/ClassMethodsOptionalParameters.php deleted file mode 100644 index e21deb38a..000000000 --- a/test/TestAsset/ClassMethodsOptionalParameters.php +++ /dev/null @@ -1,40 +0,0 @@ -foo; - } - - /** - * @param string $foo - * @param mixed $optional - */ - public function setFoo($foo, $optional = null) - { - $this->foo = (string) $foo; - } -} diff --git a/test/TestAsset/ClassMethodsProtectedSetter.php b/test/TestAsset/ClassMethodsProtectedSetter.php deleted file mode 100644 index 1b2852990..000000000 --- a/test/TestAsset/ClassMethodsProtectedSetter.php +++ /dev/null @@ -1,30 +0,0 @@ -foo = $foo; - } - - public function setBar($bar) - { - $this->bar = $bar; - } - - public function getBar() - { - return $this->bar; - } -} diff --git a/test/TestAsset/ClassMethodsTitleCase.php b/test/TestAsset/ClassMethodsTitleCase.php deleted file mode 100644 index e805c5d2d..000000000 --- a/test/TestAsset/ClassMethodsTitleCase.php +++ /dev/null @@ -1,90 +0,0 @@ -FooBar; - } - - public function setFooBar($value) - { - $this->FooBar = $value; - return $this; - } - - public function getFooBarBaz() - { - return $this->FooBarBaz; - } - - public function setFooBarBaz($value) - { - $this->FooBarBaz = $value; - return $this; - } - - public function getIsFoo() - { - return $this->IsFoo; - } - - public function setIsFoo($IsFoo) - { - $this->IsFoo = $IsFoo; - return $this; - } - - public function getIsBar() - { - return $this->IsBar; - } - - public function setIsBar($IsBar) - { - $this->IsBar = $IsBar; - return $this; - } - - public function getHasFoo() - { - return $this->HasFoo; - } - - public function getHasBar() - { - return $this->HasBar; - } - - public function setHasFoo($HasFoo) - { - $this->HasFoo = $HasFoo; - return $this; - } - - public function setHasBar($HasBar) - { - $this->HasBar = $HasBar; - } -} diff --git a/test/TestAsset/ClassMethodsUnderscore.php b/test/TestAsset/ClassMethodsUnderscore.php deleted file mode 100644 index e5a47db54..000000000 --- a/test/TestAsset/ClassMethodsUnderscore.php +++ /dev/null @@ -1,91 +0,0 @@ -foo_bar; - } - - public function setFooBar($value) - { - $this->foo_bar = $value; - return $this; - } - - public function getFooBarBaz() - { - return $this->foo_bar_baz; - } - - public function setFooBarBaz($value) - { - $this->foo_bar_baz = $value; - return $this; - } - - public function getIsFoo() - { - return $this->is_foo; - } - - public function setIsFoo($value) - { - $this->is_foo = $value; - return $this; - } - - public function isBar() - { - return $this->is_bar; - } - - public function setIsBar($value) - { - $this->is_bar = $value; - return $this; - } - - public function getHasFoo() - { - return $this->has_foo; - } - - public function setHasFoo($value) - { - $this->has_foo = $value; - return $this; - } - - public function hasBar() - { - return $this->has_bar; - } - - public function setHasBar($value) - { - $this->has_bar = $value; - return $this; - } -} diff --git a/test/TestAsset/ClassWithPublicStaticProperties.php b/test/TestAsset/ClassWithPublicStaticProperties.php deleted file mode 100644 index a0216ee4f..000000000 --- a/test/TestAsset/ClassWithPublicStaticProperties.php +++ /dev/null @@ -1,28 +0,0 @@ -field1 = $field1; - $this->field2 = $field2; - } -} diff --git a/test/TestAsset/HydratorInjectedObject.php b/test/TestAsset/HydratorInjectedObject.php deleted file mode 100644 index 1b7509e8e..000000000 --- a/test/TestAsset/HydratorInjectedObject.php +++ /dev/null @@ -1,24 +0,0 @@ -hydrator = $hydrator; - } -} diff --git a/test/TestAsset/HydratorInjectedObjectUsingDeprecatedExtractionInterfaceTypehint.php b/test/TestAsset/HydratorInjectedObjectUsingDeprecatedExtractionInterfaceTypehint.php deleted file mode 100644 index 45ba286eb..000000000 --- a/test/TestAsset/HydratorInjectedObjectUsingDeprecatedExtractionInterfaceTypehint.php +++ /dev/null @@ -1,24 +0,0 @@ -extractor = $extractor; - } -} diff --git a/test/TestAsset/HydratorInjectedObjectUsingDeprecatedHydrationInterfaceTypehint.php b/test/TestAsset/HydratorInjectedObjectUsingDeprecatedHydrationInterfaceTypehint.php deleted file mode 100644 index f7c72bce6..000000000 --- a/test/TestAsset/HydratorInjectedObjectUsingDeprecatedHydrationInterfaceTypehint.php +++ /dev/null @@ -1,24 +0,0 @@ -hydrator = $hydrator; - } -} diff --git a/test/TestAsset/HydratorInjectedObjectUsingDeprecatedInterfaceTypehint.php b/test/TestAsset/HydratorInjectedObjectUsingDeprecatedInterfaceTypehint.php deleted file mode 100644 index b403f9c57..000000000 --- a/test/TestAsset/HydratorInjectedObjectUsingDeprecatedInterfaceTypehint.php +++ /dev/null @@ -1,24 +0,0 @@ -hydrator = $hydrator; - } -} diff --git a/test/TestAsset/HydratorStrategy.php b/test/TestAsset/HydratorStrategy.php deleted file mode 100644 index 970b2f2d0..000000000 --- a/test/TestAsset/HydratorStrategy.php +++ /dev/null @@ -1,63 +0,0 @@ -simulatedStorageDevice = array(); - $this->simulatedStorageDevice[] = new HydratorStrategyEntityB(111, 'AAA'); - $this->simulatedStorageDevice[] = new HydratorStrategyEntityB(222, 'BBB'); - $this->simulatedStorageDevice[] = new HydratorStrategyEntityB(333, 'CCC'); - } - - public function extract($value) - { - $result = array(); - foreach ($value as $instance) { - $result[] = $instance->getField1(); - } - return $result; - } - - public function hydrate($value) - { - $result = $value; - if (is_array($value)) { - $result = array(); - foreach ($value as $field1) { - $result[] = $this->findEntity($field1); - } - } - return $result; - } - - private function findEntity($field1) - { - $result = null; - foreach ($this->simulatedStorageDevice as $entity) { - if ($entity->getField1() == $field1) { - $result = $entity; - break; - } - } - return $result; - } -} diff --git a/test/TestAsset/HydratorStrategyContextAware.php b/test/TestAsset/HydratorStrategyContextAware.php deleted file mode 100644 index c456bcd3c..000000000 --- a/test/TestAsset/HydratorStrategyContextAware.php +++ /dev/null @@ -1,30 +0,0 @@ -object = $object; - return $value; - } - - public function hydrate($value, $data = null) - { - $this->data = $data; - return $value; - } -} diff --git a/test/TestAsset/HydratorStrategyEntityA.php b/test/TestAsset/HydratorStrategyEntityA.php deleted file mode 100644 index 1a4374ad0..000000000 --- a/test/TestAsset/HydratorStrategyEntityA.php +++ /dev/null @@ -1,74 +0,0 @@ -entities = array(); - } - - public function addEntity(HydratorStrategyEntityB $entity) - { - $this->entities[] = $entity; - } - - public function getEntities() - { - return $this->entities; - } - - public function setEntities($entities) - { - $this->entities = $entities; - } - - public function getInputFilter() - { - if (!$this->inputFilter) { - $input = new Input(); - $input->setName('entities'); - $input->setRequired(false); - - $this->inputFilter = new InputFilter(); - $this->inputFilter->add($input); - } - - return $this->inputFilter; - } - - public function setInputFilter(InputFilterInterface $inputFilter) - { - $this->inputFilter = $inputFilter; - } - - // Add the getArrayCopy method so we can test the ArraySerializable hydrator: - public function getArrayCopy() - { - return get_object_vars($this); - } - - // Add the populate method so we can test the ArraySerializable hydrator: - public function populate($data) - { - foreach ($data as $name => $value) { - $this->$name = $value; - } - } -} diff --git a/test/TestAsset/HydratorStrategyEntityB.php b/test/TestAsset/HydratorStrategyEntityB.php deleted file mode 100644 index 9106a51da..000000000 --- a/test/TestAsset/HydratorStrategyEntityB.php +++ /dev/null @@ -1,45 +0,0 @@ -field1 = $field1; - $this->field2 = $field2; - } - - public function getField1() - { - return $this->field1; - } - - public function getField2() - { - return $this->field2; - } - - public function setField1($value) - { - $this->field1 = $value; - return $this; - } - - public function setField2($value) - { - $this->field2 = $value; - return $this; - } -} diff --git a/test/TestAsset/ObjectProperty.php b/test/TestAsset/ObjectProperty.php deleted file mode 100644 index f38ff01de..000000000 --- a/test/TestAsset/ObjectProperty.php +++ /dev/null @@ -1,32 +0,0 @@ -foo = "bar"; - $this->bar = "foo"; - $this->blubb = "baz"; - $this->quo = "blubb"; - $this->quin = 'five'; - } - -} diff --git a/test/TestAsset/Reflection.php b/test/TestAsset/Reflection.php deleted file mode 100644 index cb8dec722..000000000 --- a/test/TestAsset/Reflection.php +++ /dev/null @@ -1,29 +0,0 @@ -fooBar; - } - - public function getFooBarBaz() - { - return $this->fooBarBaz; - } -} diff --git a/test/TestAsset/ReflectionFilter.php b/test/TestAsset/ReflectionFilter.php deleted file mode 100644 index 23ded08c6..000000000 --- a/test/TestAsset/ReflectionFilter.php +++ /dev/null @@ -1,30 +0,0 @@ -foo = "bar"; - $this->bar = "foo"; - $this->blubb = "baz"; - $this->quo = "blubb"; - } - -}