Updated DependencyInjection component

Signed-off-by: Gregory PLANCHAT <g.planchat@gmail.com>
This commit is contained in:
Gregory PLANCHAT 2012-07-17 20:10:13 +02:00
commit 8e8b4b3513
19 changed files with 462 additions and 146 deletions

View file

@ -5,9 +5,9 @@ MODULES_DIR="`pwd`/src/application/modules"
for file in `find $MODULES_DIR -mindepth 1 -maxdepth 1 -type d` for file in `find $MODULES_DIR -mindepth 1 -maxdepth 1 -type d`
do do
echo " * Running `basename ${file}` module tests (Unit tests)" echo " * Running `basename ${file}` module tests (Unit tests)"
phpunit --strict --configuration ${file}/test/phpunit.xml ${file}/test/php/WootookUnit phpunit --strict --colors --configuration ${file}/test/phpunit.xml ${file}/test/php/WootookUnit
#echo " * Running `basename ${file}` module tests (Integration tests)" #echo " * Running `basename ${file}` module tests (Integration tests)"
#phpunit --strict --configuration ${file}/test/phpunit.xml ${file}/test/php/WootookUnit #phpunit --strict --colors --configuration ${file}/test/phpunit.xml ${file}/test/php/WootookUnit
done done

View file

@ -4,6 +4,7 @@
'Wootook\\Core\\Base\\DataContainer' => __DIR__ . '/src/Wootook/Core/Base/DataContainer.php', 'Wootook\\Core\\Base\\DataContainer' => __DIR__ . '/src/Wootook/Core/Base/DataContainer.php',
'Wootook\\Core\\Base\\Service\\App' => __DIR__ . '/src/Wootook/Core/Base/Service/App.php', 'Wootook\\Core\\Base\\Service\\App' => __DIR__ . '/src/Wootook/Core/Base/Service/App.php',
'Wootook\\Core\\Base\\Singleton' => __DIR__ . '/src/Wootook/Core/Base/Singleton.php', 'Wootook\\Core\\Base\\Singleton' => __DIR__ . '/src/Wootook/Core/Base/Singleton.php',
'Wootook\\Core\\Base\\Util\FileSystem' => __DIR__ . '/src/Wootook/Core/Base/Util/FileSystem.php',
'Wootook\\Core\\Block\\Concat' => __DIR__ . '/src/Wootook/Core/Block/Concat.php', 'Wootook\\Core\\Block\\Concat' => __DIR__ . '/src/Wootook/Core/Block/Concat.php',
'Wootook\\Core\\Block\\Deprecated' => __DIR__ . '/src/Wootook/Core/Block/Deprecated.php', 'Wootook\\Core\\Block\\Deprecated' => __DIR__ . '/src/Wootook/Core/Block/Deprecated.php',
'Wootook\\Core\\Block\\Html\\Form' => __DIR__ . '/src/Wootook/Core/Block/Html/Form.php', 'Wootook\\Core\\Block\\Html\\Form' => __DIR__ . '/src/Wootook/Core/Block/Html/Form.php',

View file

@ -0,0 +1,68 @@
<?php
/**
* This file is part of Wootook
*
* @license http://www.gnu.org/licenses/agpl-3.0.txt
* @see http://wootook.org/
*
* Copyright (c) 2011-Present, Grégory PLANCHAT <g.planchat@gmail.com>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* --> NOTICE <--
* This file is part of the core development branch, changing its contents will
* make you unable to use the automatic updates manager. Please refer to the
* documentation for further information about customizing Wootook.
*
*/
namespace Wootook\Core\Base\Util;
use Wootook\Core\Profiler;
class FileSystem
{
public function fileExists($fileName)
{
if ($fileName === null || empty($fileName)) {
return false;
}
if (($fp = @fopen($fileName, 'r', true)) === false) {
return false;
}
fclose($fp);
return true;
}
public function directoryExists($directoryName)
{
if ($directoryName === null || empty($directoryName)) {
return false;
}
return is_dir($directoryName);
}
public function includeFile($fileName)
{
if ($fileName === null || empty($fileName)) {
return null;
}
return include $fileName;
}
}

View file

@ -30,25 +30,29 @@
namespace Wootook\Core\Config\Adapter; namespace Wootook\Core\Config\Adapter;
use Wootook\Core\Exception as CoreException; use Wootook\Core\Base\Util,
Wootook\Core\Exception as CoreException;
class PhpArray class PhpArray
extends Adapter extends Adapter
{ {
protected $_ioHelper = null;
public function __construct($filename = null) public function __construct($filename = null)
{ {
if ($filename !== null) { if ($filename !== null) {
$this->load($filename); $this->load($filename);
} }
$this->_ioHelper = new Util\FileSystem();
} }
public function load($filename) public function load($filename)
{ {
// Undesired dependency to the \Wootook class if (!$this->_ioHelper->fileExists($filename)) {
if (!\Wootook::fileExists($filename)) {
throw new CoreException\DataAccessException(sprintf('Could not load config file "%s"', $filename)); throw new CoreException\DataAccessException(sprintf('Could not load config file "%s"', $filename));
} }
$data = include $filename; $data = $this->_ioHelper->includeFile($filename);
if (!is_array($data)) { if (!is_array($data)) {
throw new CoreException\DataAccessException('Configuration file could not be loaded.'); throw new CoreException\DataAccessException('Configuration file could not be loaded.');

View file

@ -61,28 +61,28 @@ abstract class Condition
return $this->_query; return $this->_query;
} }
protected function _addPlaceholder(Placeholder\Placeholder $placeholder) public function addPlaceholder(Placeholder\Placeholder $placeholder)
{ {
$this->_placeholders[] = $placeholder; $this->_placeholders[] = $placeholder;
return $this; return $this;
} }
protected function _clearPlaceholders() public function clearPlaceholders()
{ {
$this->_placeholders = array(); $this->_placeholders = array();
return $this; return $this;
} }
protected function _getAllPlaceholders() public function getAllPlaceholders()
{ {
return $this->_placeholders; return $this->_placeholders;
} }
public function beforePrepare(Statement\Statement $statement) public function beforePrepare(Statement\Statement $statement)
{ {
foreach ($this->_getAllPlaceholders() as $placeholder) { foreach ($this->getAllPlaceholders() as $placeholder) {
/** @var \Wootook\Core\Database\Sql\Placeholder\Placeholder $placeholder */ /** @var \Wootook\Core\Database\Sql\Placeholder\Placeholder $placeholder */
$placeholder->beforePrepare($statement); $placeholder->beforePrepare($statement);
} }
@ -92,7 +92,7 @@ abstract class Condition
public function afterPrepare(Statement\Statement $statement) public function afterPrepare(Statement\Statement $statement)
{ {
foreach ($this->_getAllPlaceholders() as $placeholder) { foreach ($this->getAllPlaceholders() as $placeholder) {
/** @var \Wootook\Core\Database\Sql\Placeholder\Placeholder $placeholder */ /** @var \Wootook\Core\Database\Sql\Placeholder\Placeholder $placeholder */
$placeholder->afterPrepare($statement); $placeholder->afterPrepare($statement);
} }
@ -102,7 +102,7 @@ abstract class Condition
public function beforeExecute(Statement\Statement $statement) public function beforeExecute(Statement\Statement $statement)
{ {
foreach ($this->_getAllPlaceholders() as $placeholder) { foreach ($this->getAllPlaceholders() as $placeholder) {
/** @var \Wootook\Core\Database\Sql\Placeholder\Placeholder $placeholder */ /** @var \Wootook\Core\Database\Sql\Placeholder\Placeholder $placeholder */
$placeholder->beforeExecute($statement); $placeholder->beforeExecute($statement);
} }
@ -112,7 +112,7 @@ abstract class Condition
public function afterExecute(Statement\Statement $statement) public function afterExecute(Statement\Statement $statement)
{ {
foreach ($this->_getAllPlaceholders() as $placeholder) { foreach ($this->getAllPlaceholders() as $placeholder) {
/** @var \Wootook\Core\Database\Sql\Placeholder\Placeholder $placeholder */ /** @var \Wootook\Core\Database\Sql\Placeholder\Placeholder $placeholder */
$placeholder->afterExecute($statement); $placeholder->afterExecute($statement);
} }

View file

@ -28,10 +28,10 @@
* *
*/ */
namespace Wootook\Core\Database\Sql; namespace Wootook\Core\Database\Sql\Dml;
class Delete class Delete
extends DmlFilterableQuery extends DmlQuery
{ {
const FROM = 'FROM'; const FROM = 'FROM';

View file

@ -28,7 +28,7 @@
* *
*/ */
namespace Wootook\Core\Database\Sql; namespace Wootook\Core\Database\Sql\Dml;
use Wootook\Core\Database\Sql\Placeholder; use Wootook\Core\Database\Sql\Placeholder;

View file

@ -37,24 +37,6 @@ use Wootook\Core,
trait Where trait Where
{ {
const WHERE = 'WHERE';
const OPERATOR_AND = 'AND';
const OPERATOR_OR = 'OR';
const OPERATOR_XOR = 'XOR';
const OPERATOR_EQUALS = 'EQ';
const OPERATOR_NOT_EQUALS = 'NEQ';
const OPERATOR_LOWER = 'LT';
const OPERATOR_GREATER = 'GT';
const OPERATOR_LOWER_EQUALS = 'LTEQ';
const OPERATOR_GREATER_EQUALS = 'GTEQ';
const OPERATOR_IS_NULL = 'NULL';
const OPERATOR_IN = 'IN';
const OPERATOR_NOT_IN = 'NIN';
const OPERATOR_FIND_IN_SET = 'FINSET';
const OPERATOR_NOT_FIND_IN_SET = 'NFINSET';
const OPERATOR_DATE = 'DATE';
public function where($condition, $value = null) public function where($condition, $value = null)
{ {
if ($condition instanceof Placeholder\Placeholder) { if ($condition instanceof Placeholder\Placeholder) {

View file

@ -28,7 +28,7 @@
* *
*/ */
namespace Wootook\Core\Database\Sql; namespace Wootook\Core\Database\Sql\Dml;
use Wootook\Core\Database\Sql\Dml\Section, use Wootook\Core\Database\Sql\Dml\Section,
Wootook\Core\Database\Sql\Placeholder; Wootook\Core\Database\Sql\Placeholder;

View file

@ -28,7 +28,7 @@
* *
*/ */
namespace Wootook\Core\Database\Sql; namespace Wootook\Core\Database\Sql\Dml;
use Wootook\Core\Database\Sql\Dml\Section, use Wootook\Core\Database\Sql\Dml\Section,
Wootook\Core\Database\Sql\Placeholder; Wootook\Core\Database\Sql\Placeholder;

View file

@ -32,7 +32,6 @@ namespace Wootook\Core\Database\Statement;
use Wootook\Core\Database, use Wootook\Core\Database,
Wootook\Core\Database\Adapter, Wootook\Core\Database\Adapter,
Wootook\Core\Database\Statement,
Wootook\Core\Database\Sql, Wootook\Core\Database\Sql,
Wootook\Core\Exception as CoreException; Wootook\Core\Exception as CoreException;

View file

@ -34,6 +34,6 @@ namespace Wootook\Core\DateTime;
* Date formatter and parser * Date formatter and parser
*/ */
class Formatter class Formatter
extends \IntlDateFormatter // extends \IntlDateFormatter
{ {
} }

View file

@ -2,22 +2,22 @@
namespace Wootook\Core\DependencyInjection\Config; namespace Wootook\Core\DependencyInjection\Config;
use Wootook\Core\Config, use Wootook\Core\Config\Node,
Wootook\Core\DependencyInjection; Wootook\Core\DependencyInjection;
class Config class Config
{ {
public function __invoke(DependencyInjection\Factory $factory, Config\Node $config) public function __invoke(DependencyInjection\Factory $factory, Node $config)
{ {
foreach ($config as $className => $classConfig) { foreach ($config as $className => $classConfig) {
$classDefinition = $factory->initClassDefinition($className); $classDefinition = $factory->initClassDefinition($className);
$factory->registerClassDefinition($className, $classDefinition); $factory->registerClassDefinition($className, $classDefinition);
if ($classConfig->methods instanceof Config\Node) { if ($classConfig->methods instanceof Node) {
foreach ($classConfig->methods as $methodName => $methodConfig) { foreach ($classConfig->methods as $methodName => $methodConfig) {
$classDefinition-> //$classDefinition->
} }
} }
} }
} }
} }

View file

@ -51,13 +51,9 @@ class ArgumentDefinition
public function __construct(MethodDefinition $methodDefinition, $argumentName, DependencyInjection\Registry $registry = null) public function __construct(MethodDefinition $methodDefinition, $argumentName, DependencyInjection\Registry $registry = null)
{ {
$this->_methodDefinition = $methodDefinition; $this->_methodDefinition = $methodDefinition;
$this->_argumentName = $argumentName; $this->_argumentName = $argumentName;
try {
$this->setReflector($methodDefinition->getArgumentReflector($argumentName)); $this->setReflector($methodDefinition->getArgumentReflector($argumentName));
} catch (\ReflectionException $e) {
throw new CoreException\DependencyInjection\BadMethodCallException($e->getMessage(), $e->getCode(), $e);
}
$this->_registry = $registry; $this->_registry = $registry;
} }
@ -98,6 +94,16 @@ class ArgumentDefinition
return $this; return $this;
} }
public function getType()
{
return $this->_type;
}
public function getValue()
{
return $this->_value;
}
public function getReflector() public function getReflector()
{ {
return $this->_reflector; return $this->_reflector;

View file

@ -72,11 +72,19 @@ class MethodDefinition
$this->_registry = $registry; $this->_registry = $registry;
} }
/**
* @param $argumentPosition
* @return \Wootook\Core\DependencyInjection\Definition\ArgumentDefinition
*/
protected function _getArgumentDefinitionInstance($argumentPosition) protected function _getArgumentDefinitionInstance($argumentPosition)
{ {
return new $this->_argumentDefinitionHandlerClass($this, $argumentPosition); return new $this->_argumentDefinitionHandlerClass($this, $argumentPosition);
} }
/**
* @param \Wootook\Core\DependencyInjection\Registry $registry
* @return MethodDefinition
*/
public function setRegistry(DependencyInjection\Registry $registry) public function setRegistry(DependencyInjection\Registry $registry)
{ {
$this->_registry = $registry; $this->_registry = $registry;
@ -84,91 +92,100 @@ class MethodDefinition
return $this; return $this;
} }
/**
* @return null|\Wootook\Core\DependencyInjection\Registry
*/
public function getRegistry() public function getRegistry()
{ {
return $this->_registry; return $this->_registry;
} }
/**
* @param string|int $argumentPosition
* @param mixed $argumentValue
* @return MethodDefinition
* @throws \Wootook\Core\Exception\DependencyInjection\InvalidArgumentException
*/
public function bindArgumentValue($argumentPosition, $argumentValue) public function bindArgumentValue($argumentPosition, $argumentValue)
{ {
if (is_numeric($argumentPosition)) { $this->getArgumentDefinition($argumentPosition)->bindValue($argumentValue);
$this->_arguments[$argumentPosition] = $argumentValue;
} else if (is_string($argumentPosition) && isset($this->_argumentIndex[$argumentPosition])) {
$this->_arguments[$this->_argumentIndex[$argumentPosition]] = $argumentValue;
} else {
throw new CoreException\DependencyInjection\InvalidArgumentException('No such argument');
}
return $this; return $this;
} }
/**
* @param string|int $argumentPosition
* @param mixed $argumentVariable
* @return MethodDefinition
* @throws \Wootook\Core\Exception\DependencyInjection\InvalidArgumentException
*/
public function bindArgumentVariable($argumentPosition, &$argumentVariable) public function bindArgumentVariable($argumentPosition, &$argumentVariable)
{ {
if (is_numeric($argumentPosition)) { $this->getArgumentDefinition($argumentPosition)->bindVariable($argumentVariable);
if (is_object($argumentVariable)) {
$this->_arguments[$argumentPosition] = $argumentVariable;
} else {
$this->_arguments[$argumentPosition] =& $argumentVariable;
}
} else if (is_string($argumentPosition) && isset($this->_argumentIndex[$argumentPosition])) {
if (is_object($argumentVariable)) {
$this->_arguments[$this->_argumentIndex[$argumentPosition]] = $argumentVariable;
} else {
$this->_arguments[$this->_argumentIndex[$argumentPosition]] =& $argumentVariable;
}
} else {
throw new CoreException\DependencyInjection\InvalidArgumentException('No such argument');
}
return $this; return $this;
} }
public function bindArgumentRegistry($argumentPosition, $argumentKey) /**
* @param string|int $argumentPosition
* @param string $registryKey
* @return MethodDefinition
* @throws \Wootook\Core\Exception\DependencyInjection\RuntimeException
* @throws \Wootook\Core\Exception\DependencyInjection\InvalidArgumentException
*/
public function bindArgumentRegistryEntry($argumentPosition, $registryKey)
{ {
if (($registry = $this->getRegistry()) === null) { if (($registry = $this->getRegistry()) === null) {
throw new CoreException\DependencyInjection\RuntimeException('No registry available'); throw new CoreException\DependencyInjection\RuntimeException('No registry available');
} }
if (is_numeric($argumentPosition)) { $this->getArgumentDefinition($argumentPosition)->bindRegistryEntry($registryKey);
$this->_arguments[$argumentPosition] = $argumentVariable;
} else if (is_string($argumentPosition) && isset($this->_argumentIndex[$argumentPosition])) {
$this->_arguments[$this->_argumentIndex[$argumentPosition]] = $argumentVariable;
} else {
throw new CoreException\DependencyInjection\InvalidArgumentException('No such argument');
}
return $this; return $this;
} }
/**
* @param int|string $argumentPosition
* @return \Wootook\Core\DependencyInjection\Definition\ArgumentDefinition
* @throws \Wootook\Core\Exception\DependencyInjection\InvalidArgumentException
*/
public function getArgumentDefinition($argumentPosition) public function getArgumentDefinition($argumentPosition)
{ {
if (is_numeric($argumentPosition)) { if (is_string($argumentPosition) && isset($this->_argumentIndex[$argumentPosition])) {
if (!isset($this->_arguments[$argumentPosition])) { $argumentPosition = $this->_argumentIndex[$argumentPosition];
$this->_arguments[$argumentPosition] = $this->_getArgumentDefinitionInstance($argumentPosition);
}
return $this->_arguments[$argumentPosition];
} else if (is_string($argumentPosition) && isset($this->_argumentIndex[$argumentPosition])) {
if (!isset($this->_arguments[$this->_argumentIndex[$argumentPosition]])) {
$this->_arguments[$this->_argumentIndex[$argumentPosition]] = $this->_getArgumentDefinitionInstance($this->_argumentIndex[$argumentPosition]);
}
return $this->_arguments[$this->_argumentIndex[$argumentPosition]];
} else {
throw new CoreException\InvalidArgumentException('Argument not found.');
} }
if (!is_int($argumentPosition)) {
throw new CoreException\DependencyInjection\InvalidArgumentException('Argument not found.');
}
if (!isset($this->_arguments[$argumentPosition])) {
$this->_arguments[$argumentPosition] = $this->_getArgumentDefinitionInstance($argumentPosition);
}
return $this->_arguments[$argumentPosition];
} }
/**
* @return array
*/
public function getAllArgumentDefinitions() public function getAllArgumentDefinitions()
{ {
return $this->_arguments; return $this->_arguments;
} }
/**
* @return \ReflectionMethod
*/
public function getReflector() public function getReflector()
{ {
return $this->_reflector; return $this->_reflector;
} }
/**
* @param \ReflectionMethod $reflector
* @return MethodDefinition
*/
public function setReflector(\ReflectionMethod $reflector) public function setReflector(\ReflectionMethod $reflector)
{ {
$this->_reflector = $reflector; $this->_reflector = $reflector;
@ -184,14 +201,21 @@ class MethodDefinition
return $this; return $this;
} }
/**
* @param $argumentPosition
* @return \ReflectionParameter
* @throws \Wootook\Core\Exception\DependencyInjection\InvalidArgumentException
*/
public function getArgumentReflector($argumentPosition) public function getArgumentReflector($argumentPosition)
{ {
if (is_numeric($argumentPosition)) { if (is_string($argumentPosition) && isset($this->_argumentIndex[$argumentPosition])) {
return $this->_argumentReflectors[$argumentPosition]; $argumentPosition = $this->_argumentIndex[$argumentPosition];
} else if (is_string($argumentPosition) && isset($this->_argumentIndex[$argumentPosition])) {
return $this->_argumentReflectors[$this->_argumentIndex[$argumentPosition]];
} else {
throw new CoreException\DependencyInjection\InvalidArgumentException('No such argument');
} }
if (!is_int($argumentPosition) || !isset($this->_argumentReflectors[$argumentPosition])) {
throw new CoreException\DependencyInjection\InvalidArgumentException('Argument not found.');
}
return $this->_argumentReflectors[$argumentPosition];
} }
} }

View file

@ -11,4 +11,3 @@ spl_autoload_register(function ($class) {
return require $map[$class]; return require $map[$class];
}); });
require dirname(dirname(dirname(__DIR__))) . '/code/core/Wootook.php';

View file

@ -123,9 +123,9 @@ class ConditionTest
$conditionMock = $this->buildMock(); $conditionMock = $this->buildMock();
$placeholderMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder'); $placeholderMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder');
$this->callNonPublicMethod($conditionMock, '_addPlaceholder', array($placeholderMock)); $conditionMock->addPlaceholder($placeholderMock);
$result = $this->callNonPublicMethod($conditionMock, '_getAllPlaceholders'); $result = $conditionMock->getAllPlaceholders();
$this->assertArrayHasKey(0, $result); $this->assertArrayHasKey(0, $result);
$this->assertSame($placeholderMock, $result[0]); $this->assertSame($placeholderMock, $result[0]);
} }
@ -135,25 +135,27 @@ class ConditionTest
$conditionMock = $this->buildMock(); $conditionMock = $this->buildMock();
$placeholderMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder'); $placeholderMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder');
$this->callNonPublicMethod($conditionMock, '_addPlaceholder', array($placeholderMock)); $conditionMock->addPlaceholder($placeholderMock);
$this->callNonPublicMethod($conditionMock, '_addPlaceholder', array($placeholderMock)); $conditionMock->addPlaceholder($placeholderMock);
$this->callNonPublicMethod($conditionMock, '_clearPlaceholders'); $conditionMock->clearPlaceholders();
$expected = array(); $expected = array();
$this->assertEquals($expected, $this->callNonPublicMethod($conditionMock, '_getAllPlaceholders')); $this->assertEquals($expected, $conditionMock->getAllPlaceholders());
} }
public function testPlaceholderCallTrigger_beforePrepare() public function testPlaceholderCallTrigger_beforePrepare()
{ {
/** @var \Wootook\Core\Database\Sql\Dml\Condition\Condition $conditionMock */
$conditionMock = $this->buildMock(); $conditionMock = $this->buildMock();
$placeholderMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder'); $placeholderMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder',
array(), '', true, true, true, array('beforePrepare'));
$placeholderMock->expects($this->any()) $placeholderMock->expects($this->once())
->method('beforePrepare') ->method('beforePrepare')
->with($this->_statementMock) ->with($this->_statementMock)
; ;
$this->callNonPublicMethod($conditionMock, '_addPlaceholder', array($placeholderMock)); $conditionMock->addPlaceholder($placeholderMock);
$conditionMock->beforePrepare($this->_statementMock); $conditionMock->beforePrepare($this->_statementMock);
} }
@ -161,14 +163,15 @@ class ConditionTest
public function testPlaceholderCallTrigger_afterPrepare() public function testPlaceholderCallTrigger_afterPrepare()
{ {
$conditionMock = $this->buildMock(); $conditionMock = $this->buildMock();
$placeholderMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder'); $placeholderMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder',
array(), '', true, true, true, array('afterPrepare'));
$placeholderMock->expects($this->any()) $placeholderMock->expects($this->once())
->method('afterPrepare') ->method('afterPrepare')
->with($this->_statementMock) ->with($this->_statementMock)
; ;
$this->callNonPublicMethod($conditionMock, '_addPlaceholder', array($placeholderMock)); $conditionMock->addPlaceholder($placeholderMock);
$conditionMock->afterPrepare($this->_statementMock); $conditionMock->afterPrepare($this->_statementMock);
} }
@ -176,14 +179,15 @@ class ConditionTest
public function testPlaceholderCallTrigger_beforeExecute() public function testPlaceholderCallTrigger_beforeExecute()
{ {
$conditionMock = $this->buildMock(); $conditionMock = $this->buildMock();
$placeholderMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder'); $placeholderMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder',
array(), '', true, true, true, array('beforeExecute'));
$placeholderMock->expects($this->any()) $placeholderMock->expects($this->once())
->method('beforeExecute') ->method('beforeExecute')
->with($this->_statementMock) ->with($this->_statementMock)
; ;
$this->callNonPublicMethod($conditionMock, '_addPlaceholder', array($placeholderMock)); $conditionMock->addPlaceholder($placeholderMock);
$conditionMock->beforeExecute($this->_statementMock); $conditionMock->beforeExecute($this->_statementMock);
} }
@ -191,14 +195,15 @@ class ConditionTest
public function testPlaceholderCallTrigger_afterExecute() public function testPlaceholderCallTrigger_afterExecute()
{ {
$conditionMock = $this->buildMock(); $conditionMock = $this->buildMock();
$placeholderMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder'); $placeholderMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder',
array(), '', true, true, true, array('afterExecute'));
$placeholderMock->expects($this->any()) $placeholderMock->expects($this->once())
->method('afterExecute') ->method('afterExecute')
->with($this->_statementMock) ->with($this->_statementMock)
; ;
$this->callNonPublicMethod($conditionMock, '_addPlaceholder', array($placeholderMock)); $conditionMock->addPlaceholder($placeholderMock);
$conditionMock->afterExecute($this->_statementMock); $conditionMock->afterExecute($this->_statementMock);
} }

View file

@ -3,6 +3,7 @@
namespace WootookUnit\Core\DependencyInjection\Definition; namespace WootookUnit\Core\DependencyInjection\Definition;
use Wootook\Core\Config, use Wootook\Core\Config,
Wootook\Core\DependencyInjection,
Wootook\Core\DependencyInjection\Definition; Wootook\Core\DependencyInjection\Definition;
class MethodDefinitionTest extends \PHPUnit_Framework_TestCase class MethodDefinitionTest extends \PHPUnit_Framework_TestCase
@ -42,9 +43,31 @@ class MethodDefinitionTest extends \PHPUnit_Framework_TestCase
$this->assertInstanceOf($argumentDefinitionClassName, $definition->getArgumentDefinition('fooArgumentOne')); $this->assertInstanceOf($argumentDefinitionClassName, $definition->getArgumentDefinition('fooArgumentOne'));
} }
public function testMethodDefinitionInstantiation_withRegistry_withSpecialArgumentDefinitionClassName()
{
$app = $this->getMock('Wootook\\Core\\App\\App', array(), array(), '', false);
/** @var \Wootook\Core\DependencyInjection\Registry $registry */
$registry = $this->getMock('Wootook\\Core\\DependencyInjection\\Registry', array(), array($app));
$argumentDefinitionClassName = \uniqid('WootookUnit_Core_DependencyInjection_Mock_ArgumentDefinition_TestNewInstance_');
$this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\ArgumentDefinition', array(), array(), $argumentDefinitionClassName, false);
/** @var \Wootook\Core\DependencyInjection\Definition\ClassDefinition $mock */
$mock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition', array('getReflector'), array(), '', false);
$mock->expects($this->once())
->method('getReflector')
->will($this->returnValue(new \ReflectionClass(__CLASS__)))
;
$definition = new Definition\MethodDefinition($mock, 'methodToTest', $registry, $argumentDefinitionClassName);
$this->assertInstanceOf($argumentDefinitionClassName, $definition->getArgumentDefinition('fooArgumentOne'));
}
public function testMethodDefinitionAccessors_getReflector() public function testMethodDefinitionAccessors_getReflector()
{ {
$mock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition', array(), array(), '', false); $mock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition', array('getReflector'), array(), '', false);
$mock->expects($this->once()) $mock->expects($this->once())
->method('getReflector') ->method('getReflector')
@ -58,7 +81,7 @@ class MethodDefinitionTest extends \PHPUnit_Framework_TestCase
public function testMethodDefinitionMutators_setReflector() public function testMethodDefinitionMutators_setReflector()
{ {
$mock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition', array(), array(), '', false); $mock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition', array('getReflector'), array(), '', false);
$mock->expects($this->once()) $mock->expects($this->once())
->method('getReflector') ->method('getReflector')
@ -71,43 +94,237 @@ class MethodDefinitionTest extends \PHPUnit_Framework_TestCase
$this->assertSame($reflector, $definition->getReflector()); $this->assertSame($reflector, $definition->getReflector());
} }
/*
public function testBuildWithoutConstructorArguments_callBindConstructorArgumentValue() public function testMethodDefinition_accessorAndMutatorForRegistry()
{ {
$definition = new Definition\ClassDefinition('MyNamespace\\MyClass'); $registryMock = $this->getMock('Wootook\\Core\\DependencyInjection\\Registry', array(), array(), '', false);
$classDefinitionMock = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition', array('getReflector'), array(), '', false);
$definition->bindConstructorArgumentValue(0, 36); $classDefinitionMock->expects($this->once())
$this->assertEquals(36, $definition->getConstructorArgument(0)); ->method('getReflector')
} ->will($this->returnValue(new \ReflectionClass(__CLASS__)))
public function testBuildWithoutConstructorArguments_callBindConstructorArgumentVariable()
{
$definition = new Definition\ClassDefinition('MyNamespace\\MyClass');
$variable = 36;
$definition->bindConstructorArgumentVariable(0, $variable);
$variable = 12;
$this->assertEquals(12, $definition->getConstructorArgument(0));
$this->assertSame($variable, $definition->getConstructorArgument(0));
}
public function testBuildWithoutConstructorArguments_callBindConstructorArgumentRegistry()
{
$definition = new Definition\ClassDefinition('MyNamespace\\MyClass');
$registry = $this->getMock('Wootook\\Core\\DependencyInjection\\Registry');
$object = new \StdClass();
$registry->expects($this->once())
->method('get')
->with('my_object')
->will($this->returnValue($object))
; ;
$definition->setRegistry($registry); $definition = new Definition\MethodDefinition($classDefinitionMock, __FUNCTION__);
$definition->bindConstructorArgumentRegistry(0, 'my_object'); $definition->setRegistry($registryMock);
$this->assertSame($object, $definition->getConstructorArgument(0)); $this->assertSame($registryMock, $definition->getRegistry());
}
public function testMethodDefinition_bindArgumentValue_withNumericArgumentIndex()
{
$classDefinition = new Definition\ClassDefinition(__CLASS__);
$definition = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition',
array('getArgumentDefinition'), array($classDefinition, 'methodToTest'));
$definition->expects($this->once())
->method('getArgumentDefinition')
->with(0)
->will($this->returnValue(new Definition\ArgumentDefinition($definition, 0)))
;
/** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */
$definition->bindArgumentValue(0, 65);
}
public function testMethodDefinition_bindArgumentVariable_withNumericArgumentIndex()
{
$classDefinition = new Definition\ClassDefinition(__CLASS__);
$definition = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition',
array('getArgumentDefinition'), array($classDefinition, 'methodToTest'));
$definition->expects($this->once())
->method('getArgumentDefinition')
->with(0)
->will($this->returnValue(new Definition\ArgumentDefinition($definition, 0)))
;
$variable = 65;
/** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */
$definition->bindArgumentVariable(0, $variable);
}
public function testMethodDefinition_bindArgumentRegistryEntry_withNumericArgumentIndex()
{
$classDefinition = new Definition\ClassDefinition(__CLASS__);
$registry = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Registry')
->disableOriginalConstructor()
->setMethods(array('get'))
->getMock();
$registry->expects($this->any())->method('get')->will($this->returnValue(36));
$definition = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition',
array('getArgumentDefinition'), array($classDefinition, 'methodToTest', $registry));
$definition->expects($this->once())
->method('getArgumentDefinition')
->with(0)
->will($this->returnValue(new Definition\ArgumentDefinition($definition, 0, $registry)))
;
/** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */
$definition->bindArgumentRegistryEntry(0, 'foo');
}
public function testMethodDefinition_bindArgumentValue_withNamedArgumentIndex()
{
$classDefinition = new Definition\ClassDefinition(__CLASS__);
$definition = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition',
array('getArgumentDefinition'), array($classDefinition, 'methodToTest'));
$definition->expects($this->once())
->method('getArgumentDefinition')
->with('fooArgumentOne')
->will($this->returnValue(new Definition\ArgumentDefinition($definition, 0)))
;
/** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */
$definition->bindArgumentValue('fooArgumentOne', 65);
}
public function testMethodDefinition_bindArgumentVariable_withNamedArgumentIndex()
{
$classDefinition = new Definition\ClassDefinition(__CLASS__);
$definition = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition',
array('getArgumentDefinition'), array($classDefinition, 'methodToTest'));
$definition->expects($this->once())
->method('getArgumentDefinition')
->with('fooArgumentOne')
->will($this->returnValue(new Definition\ArgumentDefinition($definition, 0)))
;
$variable = 65;
/** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */
$definition->bindArgumentVariable('fooArgumentOne', $variable);
}
public function testMethodDefinition_bindArgumentRegistryEntry_withNamedArgumentIndex()
{
$classDefinition = new Definition\ClassDefinition(__CLASS__);
$registry = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Registry')
->disableOriginalConstructor()
->setMethods(array('get'))
->getMock();
$registry->expects($this->any())->method('get')->will($this->returnValue(36));
$definition = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition',
array('getArgumentDefinition'), array($classDefinition, 'methodToTest', $registry));
$definition->expects($this->once())
->method('getArgumentDefinition')
->with('fooArgumentOne')
->will($this->returnValue(new Definition\ArgumentDefinition($definition, 0, $registry)))
;
/** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */
$definition->bindArgumentRegistryEntry('fooArgumentOne', 'foo');
}
public function testMethodDefinition_bindArgumentRegistryEntry_withNoRegistry()
{
$classDefinition = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition')
->disableOriginalConstructor()
->getMock()
;
$classDefinition->expects($this->once())
->method('getReflector')
->will($this->returnValue(new \ReflectionClass(__CLASS__)))
;
$definition = $this->getMock('Wootook\\Core\\DependencyInjection\\Definition\\MethodDefinition',
array('getArgumentDefinition'), array($classDefinition, 'methodToTest'));
$this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\RuntimeException');
/** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */
$definition->bindArgumentRegistryEntry('fooArgumentOne', 'foo');
}
public function testMethodDefinition_getArgumentDefinition_withInvalidArgumentId()
{
$classDefinition = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition')
->disableOriginalConstructor()
->getMock()
;
$classDefinition->expects($this->once())
->method('getReflector')
->will($this->returnValue(new \ReflectionClass(__CLASS__)))
;
$definition = new Definition\MethodDefinition($classDefinition, 'methodToTest');
$this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\InvalidArgumentException');
/** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */
$definition->getArgumentDefinition(1.5);
}
public function testMethodDefinition_getArgumentReflector_withNumericArgumentId()
{
$classDefinition = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition')
->disableOriginalConstructor()
->getMock()
;
$classDefinition->expects($this->once())
->method('getReflector')
->will($this->returnValue(new \ReflectionClass(__CLASS__)))
;
$definition = new Definition\MethodDefinition($classDefinition, 'methodToTest');
/** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */
$reflector = $definition->getArgumentReflector(0);
$this->assertInstanceOf('ReflectionParameter', $reflector);
$this->assertEquals(0, $reflector->getPosition());
}
public function testMethodDefinition_getArgumentReflector_withNamedArgumentId()
{
$classDefinition = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition')
->disableOriginalConstructor()
->getMock()
;
$classDefinition->expects($this->once())
->method('getReflector')
->will($this->returnValue(new \ReflectionClass(__CLASS__)))
;
$definition = new Definition\MethodDefinition($classDefinition, 'methodToTest');
/** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */
$reflector = $definition->getArgumentReflector('fooArgumentOne');
$this->assertInstanceOf('ReflectionParameter', $reflector);
$this->assertEquals(0, $reflector->getPosition());
}
public function testMethodDefinition_getArgumentReflector_withInvalidArgumentId()
{
$classDefinition = $this->getMockBuilder('Wootook\\Core\\DependencyInjection\\Definition\\ClassDefinition')
->disableOriginalConstructor()
->getMock()
;
$classDefinition->expects($this->once())
->method('getReflector')
->will($this->returnValue(new \ReflectionClass(__CLASS__)))
;
$definition = new Definition\MethodDefinition($classDefinition, 'methodToTest');
$this->setExpectedException('Wootook\\Core\\Exception\\DependencyInjection\\InvalidArgumentException');
/** @var \Wootook\Core\DependencyInjection\Definition\MethodDefinition $definition */
$definition->getArgumentReflector(1.5);
} }
*/
} }

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<phpunit backupGlobals="false" <phpunit backupGlobals="false"
backupStaticAttributes="false" backupStaticAttributes="false"
colors="true" colors="false"
convertErrorsToExceptions="true" convertErrorsToExceptions="true"
convertNoticesToExceptions="true" convertNoticesToExceptions="true"
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
@ -13,7 +13,7 @@
<testsuites> <testsuites>
<testsuite name="Wootook Core module - Unit tests"> <testsuite name="Wootook Core module - Unit tests">
<directory>./php/WootookTest/Core</directory> <directory>./php/WootookUnit/Core</directory>
</testsuite> </testsuite>
<!-- <!--
<testsuite name="Wootook Core module - Integration tests"> <testsuite name="Wootook Core module - Integration tests">
@ -21,4 +21,15 @@
</testsuite> </testsuite>
--> -->
</testsuites> </testsuites>
<filter>
<whitelist>
<directory suffix=".php">../src/Wootook/Core</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="./coverage/unit/html" charset="UTF-8" yui="true" highlight="false" lowUpperBound="40" highLowerBound="80"/>
</logging>
</phpunit> </phpunit>