Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge f68fea3 into 615fc00
Browse files Browse the repository at this point in the history
  • Loading branch information
tux-rampage committed Jan 10, 2019
2 parents 615fc00 + f68fea3 commit a7de3d4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/Resolver/DependencyResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -640,4 +640,39 @@ public function testParametresResolverShouldNotCheckTheTypeForString()
$this->assertInstanceOf(TypeInjection::class, $parameters['a']);
$this->assertSame('my-service', $parameters['a']->__toString());
}

/**
* Ensures the documented preference resolver behavior as documented
*
* @see https://docs.zendframework.com/zend-di/config/#type-preferences
*/
public function testResolvePreferenceFallsBackToGlobalPreferenceWhenNotSuitableForRequirement()
{
$definition = new RuntimeDefinition();
$config = new Config();
$config->setTypePreference(TestAsset\A::class, TestAsset\B::class, TestAsset\RequiresA::class);
$config->setTypePreference(TestAsset\A::class, TestAsset\ExtendedA::class);
$resolver = new DependencyResolver($definition, $config);

$this->assertSame(
TestAsset\ExtendedA::class,
$resolver->resolvePreference(TestAsset\A::class, TestAsset\RequiresA::class)
);
}

/**
* Ensures the documented preference resolver behavior as documented
*
* @see https://docs.zendframework.com/zend-di/config/#type-preferences
*/
public function testResolvePreferenceReturnsNullWhenNothingIsSuitableForRequirement()
{
$definition = new RuntimeDefinition();
$config = new Config();
$config->setTypePreference(TestAsset\A::class, TestAsset\ExtendedB::class, TestAsset\RequiresA::class);
$config->setTypePreference(TestAsset\A::class, TestAsset\B::class);
$resolver = new DependencyResolver($definition, $config);

$this->assertNull($resolver->resolvePreference(TestAsset\A::class, TestAsset\RequiresA::class));
}
}
12 changes: 12 additions & 0 deletions test/TestAsset/ExtendedA.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/**
* @see https://github.com/zendframework/zend-di for the canonical source repository
* @copyright Copyright (c) 2019 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-di/blob/master/LICENSE.md New BSD License
*/

namespace ZendTest\Di\TestAsset;

class ExtendedA extends A
{
}

0 comments on commit a7de3d4

Please sign in to comment.