<?php
/**
* This class will test the annotation driver.
*
* PHP Version 5
*
* @category Ding
* @package Test
* @subpackage Ioc.Annotation
* @author Marcelo Gornstein <marcelog@gmail.com>
* @license http://marcelog.github.com/ Apache License 2.0
* @link http://marcelog.github.com/
*
* Copyright 2011 Marcelo Gornstein <marcelog@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Ding\Container\Impl\ContainerImpl;
/**
* This class will test the annotation driver.
*
* PHP Version 5
*
* @category Ding
* @package Test
* @subpackage Ioc.Annotation
* @author Marcelo Gornstein <marcelog@gmail.com>
* @license http://marcelog.github.com/ Apache License 2.0
* @link http://marcelog.github.com/
*/
class Test_Annotation_IoC extends PHPUnit_Framework_TestCase
{
private $_properties = array();
public function setUp()
{
$this->_properties = array(
'ding' => array(
'log4php.properties' => RESOURCES_DIR . DIRECTORY_SEPARATOR . 'log4php.properties',
'factory' => array(
'bdef' => array(
'annotation' => array(
'scanDir' => array(realpath(__DIR__))
)
),
'properties' => array('aProperty' => 'aValue')
)
)
);
}
/**
* @test
* For issue #104
*/
public function can_get_class_with_underscore()
{
$container = ContainerImpl::getInstance($this->_properties);
$bean = $container->getBean('aBeanFromUnderscoreClass');
$this->assertTrue($bean instanceof Some_UnderScore_Class);
}
/**
* @test
*/
public function can_get_from_a_namespaced_class()
{
$container = ContainerImpl::getInstance($this->_properties);
$bean = $container->getBean('aBeanFromANamespacedClass');
$this->assertTrue($bean instanceof Some\Namespaces\Clazz\SomeOtherNamespacedClass);
}
/**
* @test
*/
public function can_singleton()
{
$container = ContainerImpl::getInstance($this->_properties);
$bean = $container->getBean('aSimpleSingletonBean');
$bean2 = $container->getBean('aSimpleSingletonBean');
$this->assertTrue($bean instanceof ClassSimpleAnnotation);
$this->assertTrue($bean2 instanceof ClassSimpleAnnotation);
// If this is truly a singleton, both "sets" will go to the same
// object reference.
$bean->setSomething(rand(1, microtime(true)));
$bean2->setSomething(rand(1, microtime(true)));
$this->assertTrue($bean->getSomething() === $bean2->getSomething());
}
/**
* @test
*/
public function can_at_singleton()
{
$container = ContainerImpl::getInstance($this->_properties);
$bean = $container->getBean('atSingleton');
$bean2 = $container->getBean('atSingleton');
$this->assertEquals($bean::$instances, 1);
}
/**
* @test
*/
public function can_at_prototype()
{
$container = ContainerImpl::getInstance($this->_properties);
$bean = $container->getBean('atPrototype');
$bean2 = $container->getBean('atPrototype');
$this->assertEquals($bean::$instances, 2);
}
/**
* @test
*/
public function can_prototype()
{
$container = ContainerImpl::getInstance($this->_properties);
$bean = $container->getBean('aSimplePrototypeBean');
$bean2 = $container->getBean('aSimplePrototypeBean');
$this->assertTrue($bean instanceof ClassSimpleAnnotation);
$this->assertTrue($bean2 instanceof ClassSimpleAnnotation);
// Contrary to what happens with singletons, in this case both "sets"
// will go to different instances.
$bean->setSomething(rand(1, microtime(true)));
$bean2->setSomething(rand(1, microtime(true)));
$this->assertFalse($bean->getSomething() === $bean2->getSomething());
}
/**
* @test
*/
public function can_rename()
{
$container = ContainerImpl::getInstance($this->_properties);
$bean = $container->getBean('renamedBean');
$this->assertTrue($bean instanceof ClassSimpleAnnotation);
}
/**
* @test
*/
public function can_init_method()
{
$container = ContainerImpl::getInstance($this->_properties);
$bean = $container->getBean('aSimpleInitMethodBean');
$this->assertTrue($bean->something);
}
/**
* @test
*/
public function can_at_postconstruct()
{
$container = ContainerImpl::getInstance($this->_properties);
$bean = $container->getBean('postConstructBean');
$this->assertTrue($bean->something);
}
/**
* @test
*/
public function can_at_predestroy()
{
$container = ContainerImpl::getInstance($this->_properties);
$bean = $container->getBean('preDestroyBean');
// XXX bad... unset() does not work because ContainerImpl is a singleton
// and holds a reference to itself, so the destructor is never called.
$container->__destruct();
$this->assertNull($bean->something);
}
/**
* @test
*/
public function can_destroy_method()
{
$container = ContainerImpl::getInstance($this->_properties);
$bean = $container->getBean('aSimpleDestroyMethodBean');
// XXX bad... unset() does not work because ContainerImpl is a singleton
// and holds a reference to itself, so the destructor is never called.
$container->__destruct();
$this->assertNull($bean->something);
}
/**
* @test
*/
public function can_at_resource()
{
$container = ContainerImpl::getInstance($this->_properties);
$bean = $container->getBean('injectedBean');
$this->assertTrue($bean->aSimplePrototypeBean instanceof ClassSimpleAnnotation);
$this->assertTrue($bean->getASimpleSingletonBean() instanceof ClassSimpleAnnotation);
$this->assertTrue($bean->somethingElse instanceof ASimpleDestroyInitClass);
}
/**
* @test
*/
public function can_at_resource_with_name()
{
$container = ContainerImpl::getInstance($this->_properties);
$bean = $container->getBean('injectedBean');
$this->assertTrue($bean->injectedWithName instanceof ClassSimpleAnnotation);
$this->assertTrue($bean->injectedWithNameAndSetter instanceof ClassSimpleAnnotation);
}
/**
* @test
*/
public function can_at_required()
{
$container = ContainerImpl::getInstance($this->_properties);
$bean = $container->getBean('required');
$this->assertTrue($bean->value1 instanceof ClassSimpleAnnotation2);
}
/**
* @test
* @expectedException Ding\Bean\Factory\Exception\BeanFactoryException
*/
public function cannot_at_required_missing_property()
{
$container = ContainerImpl::getInstance($this->_properties);
$bean = $container->getBean('requiredFails');
}
/**
* @test
*/
public function can_class_init_method()
{
$container = ContainerImpl::getInstance($this->_properties);
$bean = $container->getBean('aSimpleInitMethodClass');
$this->assertTrue($bean->something);
}
/**
* @test
*/
没有合适的资源?快使用搜索试试~ 我知道了~
PHP实例开发源码—Ding 框架 v1.zip
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共411个文件
php:236个
xml:78个
properties:31个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 199 浏览量
2022-11-14
02:13:34
上传
评论
收藏 469KB ZIP 举报
温馨提示
PHP实例开发源码—Ding 框架 v1.zip
资源推荐
资源详情
资源评论
![thumb](https://img-home.csdnimg.cn/images/20210720083646.png)
![thumb](https://img-home.csdnimg.cn/images/20210720083646.png)
![thumb](https://img-home.csdnimg.cn/images/20210720083646.png)
![thumb](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![thumb](https://img-home.csdnimg.cn/images/20210720083646.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/HTML.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 411 条
- 1
- 2
- 3
- 4
- 5
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/d447968c226a4cefba6233e2f2a4df24_m0_62396648.jpg!1)
毕业_设计
- 粉丝: 1947
- 资源: 1万+
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)