| Server IP : 193.146.211.90 / Your IP : 10.85.6.55 Web Server : Apache System : Linux wordpress-gti-69dcdb54f7-n4wdq 6.11.8-arch1-2 #1 SMP PREEMPT_DYNAMIC Fri, 15 Nov 2024 15:35:07 +0000 x86_64 User : 1001 ( 1001) PHP Version : 8.2.25 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /bitnami/wordpress/wp-content/plugins/presto-player/vendor/level-2/dice/tests/ |
Upload File : |
<?php
/* @description Dice - A minimal Dependency Injection Container for PHP *
* @author Tom Butler tom@r.je *
* @copyright 2012-2018 Tom Butler <tom@r.je> | https:// r.je/dice.html *
* @license http:// www.opensource.org/licenses/bsd-license.php BSD License *
* @version 3.0 */
class NamespaceTest extends DiceTest {
public function testNamespaceBasic() {
$a = $this->dice->create('Foo\\A');
$this->assertInstanceOf('Foo\\A', $a);
}
public function testNamespaceWithSlash() {
$a = $this->dice->create('\\Foo\\A');
$this->assertInstanceOf('\\Foo\\A', $a);
}
public function testNamespaceWithSlashrule() {
$rule = [];
$rule['substitutions']['Foo\\A'] = [\Dice\Dice::INSTANCE => 'Foo\\ExtendedA'];
$dice = $this->dice->addRule('\\Foo\\B', $rule);
$b = $dice->create('\\Foo\\B');
$this->assertInstanceOf('Foo\\ExtendedA', $b->a);
}
public function testNamespaceWithSlashruleInstance() {
$rule = [];
$rule['substitutions']['Foo\\A'] = [\Dice\Dice::INSTANCE => 'Foo\\ExtendedA'];
$dice = $this->dice->addRule('\\Foo\\B', $rule);
$b = $dice->create('\\Foo\\B');
$this->assertInstanceOf('Foo\\ExtendedA', $b->a);
}
public function testNamespaceTypeHint() {
$rule = [];
$rule['shared'] = true;
$dice = $this->dice->addRule('Bar\\A', $rule);
$c = $dice->create('Foo\\C');
$this->assertInstanceOf('Bar\\A', $c->a);
$c2 = $dice->create('Foo\\C');
$this->assertNotSame($c, $c2);
//Check the rule has been correctly recognised for type hinted classes in a different namespace PrestoPlayer\$this->assertSame($c2->a, $c->a);
}
public function testNamespaceInjection() {
$b = $this->dice->create('Foo\\B');
$this->assertInstanceOf('Foo\\B', $b);
$this->assertInstanceOf('Foo\\A', $b->a);
}
public function testNamespaceRuleSubstitution() {
$rule = [];
$rule['substitutions']['Foo\\A'] = [\Dice\Dice::INSTANCE => 'Foo\\ExtendedA'];
$dice = $this->dice->addRule('Foo\\B', $rule);
$b = $dice->create('Foo\\B');
$this->assertInstanceOf('Foo\\ExtendedA', $b->a);
}
}