public function testSecondSecondObjectWithDifferentNameSpace()
 {
     XmlContainer::addNamespaceToClassLoader('Second', 'test/src');
     $second = new Second();
     $this->assertInstanceOf('Second\\Test\\Second', $second);
     $this->assertEquals('Second\\Test', $second->getNameSpace(), 'Namespace different from Second\\Test');
     //Check that Simple is already in classpath
     $simple = new Simple();
     $this->assertInstanceOf('Test\\Simple', $simple);
     $this->assertEquals('Test', $simple->getNameSpace(), 'Namespace different from Test');
 }
Пример #2
0
<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);
use Ovo\Container\XmlContainer;
use Ovo\Test\Shop\Repository\ProductRepository;
use Ovo\Common\Properties\PropertiesLoader;
//OVO-CONTAINER Framework
require_once '../../src/Ovo/Container/OvoLoader.php';
//Application file to classpath
XmlContainer::addNamespaceToClassLoader('Ovo\\Test', '../src/');
//DI Container
$container = new XmlContainer('../config/shopContext.xml', '../config/property.ini');
//empty the basket
if (isset($_GET['void'])) {
    $container->destroyBean('basket');
}
//get basket bean, defined as session and init only first time
$basket = $container->getBean('basket');
//Business logic
if (isset($_GET['add']) and is_int((int) $_GET['add'])) {
    $basket->addToBasket((int) $_GET['add']);
}
if (isset($_GET['remove']) and is_int((int) $_GET['remove'])) {
    $basket->removeFromBasket((int) $_GET['remove']);
}
//View - Print all product shop
$shop = new ProductRepository();
echo PropertiesLoader::getProperty('shop_name') . '<hr>';
foreach ($shop->getShopProducts() as $k => $v) {
    echo 'ID: ' . $v->getId() . ' Description: ' . $v->getDescription() . '
 /**
  * @expectedException Ovo\Container\Exception\OvoLoaderException
  */
 public function testCircularDependencyOnInit()
 {
     XmlContainer::addNamespaceToClassLoader('Circular', 'test/src');
     $this->container = new XmlContainer(__DIR__ . self::CONFIG_FILE);
 }