Skip to content

Commit

Permalink
Add missing deprecation notice
Browse files Browse the repository at this point in the history
  • Loading branch information
tux-rampage committed Aug 31, 2018
1 parent 49eb25c commit 6547e0a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
7 changes: 7 additions & 0 deletions src/Resolver/ValueInjection.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Psr\Container\ContainerInterface;
use ReflectionObject;
use Zend\Di\Exception\RuntimeException;
use function trigger_error;
use const E_USER_DEPRECATED;

/**
* Wrapper for values that should be directly injected
Expand Down Expand Up @@ -92,6 +94,11 @@ public function toValue(ContainerInterface $container)
*/
public function getValue()
{
trigger_error(
__METHOD__ . ' is deprecated, please migrate to ' . __CLASS__ . '::toValue().',
E_USER_DEPRECATED
);

return $this->value;
}
}
19 changes: 11 additions & 8 deletions test/Resolver/DependencyResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@

namespace ZendTest\Di\Resolver;

use ArrayIterator;
use ArrayObject;
use IteratorAggregate;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use stdClass;
use Zend\Di\Config;
use Zend\Di\ConfigInterface;
use Zend\Di\Definition\ClassDefinitionInterface;
Expand All @@ -20,10 +24,6 @@
use Zend\Di\Resolver\TypeInjection;
use Zend\Di\Resolver\ValueInjection;
use ZendTest\Di\TestAsset;
use ArrayIterator;
use ArrayObject;
use IteratorAggregate;
use stdClass;

/**
* @coversDefaultClass Zend\Di\Resolver\DependencyResolver
Expand Down Expand Up @@ -213,18 +213,20 @@ public function testResolveClassWithoutParameters($class)

public function testResolveWithOptionalArgs()
{
$container = $this->prophesize(ContainerInterface::class)->reveal();
$resolver = new DependencyResolver(new RuntimeDefinition(), new Config());
$result = $resolver->resolveParameters(TestAsset\Constructor\OptionalArguments::class);

$this->assertInternalType('array', $result);
$this->assertCount(2, $result);
$this->assertContainsOnlyInstancesOf(ValueInjection::class, $result);
$this->assertSame(null, $result['foo']->getValue());
$this->assertSame('something', $result['bar']->getValue());
$this->assertSame(null, $result['foo']->toValue($container));
$this->assertSame('something', $result['bar']->toValue($container));
}

public function testResolvePassedDependenciesWithoutType()
{
$container = $this->prophesize(ContainerInterface::class)->reveal();
$resolver = new DependencyResolver(new RuntimeDefinition(), new Config());

$expected = 'Some Value';
Expand All @@ -234,7 +236,7 @@ public function testResolvePassedDependenciesWithoutType()

$this->assertCount(3, $result);
$this->assertInstanceOf(ValueInjection::class, $result['anyDep']);
$this->assertSame($expected, $result['anyDep']->getValue());
$this->assertSame($expected, $result['anyDep']->toValue($container));
}

public function providePreferenceConfigs()
Expand Down Expand Up @@ -411,12 +413,13 @@ public function testUsableConfigParametersAreAccepted(string $type, $value, bool
],
]);

$container = $this->prophesize(ContainerInterface::class)->reveal();
$resolver = new DependencyResolver($definition, $config);
$result = $resolver->resolveParameters($class);

$this->assertArrayHasKey($paramName, $result);
$this->assertInstanceOf(ValueInjection::class, $result[$paramName]);
$this->assertSame($value, $result[$paramName]->getValue());
$this->assertSame($value, $result[$paramName]->toValue($container));
}

/**
Expand Down
11 changes: 11 additions & 0 deletions test/Resolver/ValueInjectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace ZendTest\Di\Resolver;

use PHPUnit\Framework\Error\Deprecated;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Psr\Container\ContainerInterface;
Expand All @@ -15,6 +16,7 @@
use Zend\Di\Resolver\InjectionInterface;
use Zend\Di\Resolver\ValueInjection;
use ZendTest\Di\TestAsset;
use function uniqid;

/**
* @coversDefaultClass Zend\Di\Resolver\ValueInjection
Expand Down Expand Up @@ -151,4 +153,13 @@ public function testExportWithExportableValues($value)
$this->assertInternalType('string', $result, 'Export is expected to return a string value');
$this->assertNotEquals('', $result, 'The exported value must not be empty');
}

public function testGetValueTriggersDeprecatedNotice()
{
$value = uniqid();
$subject = new ValueInjection($value);

$this->expectException(Deprecated::class);
self::assertSame($value, $subject->getValue());
}
}

0 comments on commit 6547e0a

Please sign in to comment.