diff --git a/build/build.sh b/build/build.sh index 90e032f..76df89f 100644 --- a/build/build.sh +++ b/build/build.sh @@ -5,9 +5,9 @@ MODULES_DIR="`pwd`/src/application/modules" for file in `find $MODULES_DIR -mindepth 1 -maxdepth 1 -type d` do 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)" - #phpunit --strict --configuration ${file}/test/phpunit.xml ${file}/test/php/WootookUnit + #phpunit --strict --colors --configuration ${file}/test/phpunit.xml ${file}/test/php/WootookUnit done diff --git a/src/application/modules/WootookCore/autoload_classmap.php b/src/application/modules/WootookCore/autoload_classmap.php index 1a3400c..52d6e08 100644 --- a/src/application/modules/WootookCore/autoload_classmap.php +++ b/src/application/modules/WootookCore/autoload_classmap.php @@ -4,6 +4,7 @@ '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\\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\\Deprecated' => __DIR__ . '/src/Wootook/Core/Block/Deprecated.php', 'Wootook\\Core\\Block\\Html\\Form' => __DIR__ . '/src/Wootook/Core/Block/Html/Form.php', diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Base/Util/FileSystem.php b/src/application/modules/WootookCore/src/Wootook/Core/Base/Util/FileSystem.php new file mode 100644 index 0000000..3516202 --- /dev/null +++ b/src/application/modules/WootookCore/src/Wootook/Core/Base/Util/FileSystem.php @@ -0,0 +1,68 @@ + + * 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 . + * + * --> 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; + } +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Config/Adapter/PhpArray.php b/src/application/modules/WootookCore/src/Wootook/Core/Config/Adapter/PhpArray.php index 18e158a..0282447 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/Config/Adapter/PhpArray.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Config/Adapter/PhpArray.php @@ -30,25 +30,29 @@ namespace Wootook\Core\Config\Adapter; -use Wootook\Core\Exception as CoreException; +use Wootook\Core\Base\Util, + Wootook\Core\Exception as CoreException; class PhpArray extends Adapter { + protected $_ioHelper = null; + public function __construct($filename = null) { if ($filename !== null) { $this->load($filename); } + + $this->_ioHelper = new Util\FileSystem(); } public function load($filename) { - // Undesired dependency to the \Wootook class - if (!\Wootook::fileExists($filename)) { + if (!$this->_ioHelper->fileExists($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)) { throw new CoreException\DataAccessException('Configuration file could not be loaded.'); diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Condition/Condition.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Condition/Condition.php index 64e94c2..cc807d3 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Condition/Condition.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Condition/Condition.php @@ -61,28 +61,28 @@ abstract class Condition return $this->_query; } - protected function _addPlaceholder(Placeholder\Placeholder $placeholder) + public function addPlaceholder(Placeholder\Placeholder $placeholder) { $this->_placeholders[] = $placeholder; return $this; } - protected function _clearPlaceholders() + public function clearPlaceholders() { $this->_placeholders = array(); return $this; } - protected function _getAllPlaceholders() + public function getAllPlaceholders() { return $this->_placeholders; } public function beforePrepare(Statement\Statement $statement) { - foreach ($this->_getAllPlaceholders() as $placeholder) { + foreach ($this->getAllPlaceholders() as $placeholder) { /** @var \Wootook\Core\Database\Sql\Placeholder\Placeholder $placeholder */ $placeholder->beforePrepare($statement); } @@ -92,7 +92,7 @@ abstract class Condition public function afterPrepare(Statement\Statement $statement) { - foreach ($this->_getAllPlaceholders() as $placeholder) { + foreach ($this->getAllPlaceholders() as $placeholder) { /** @var \Wootook\Core\Database\Sql\Placeholder\Placeholder $placeholder */ $placeholder->afterPrepare($statement); } @@ -102,7 +102,7 @@ abstract class Condition public function beforeExecute(Statement\Statement $statement) { - foreach ($this->_getAllPlaceholders() as $placeholder) { + foreach ($this->getAllPlaceholders() as $placeholder) { /** @var \Wootook\Core\Database\Sql\Placeholder\Placeholder $placeholder */ $placeholder->beforeExecute($statement); } @@ -112,7 +112,7 @@ abstract class Condition public function afterExecute(Statement\Statement $statement) { - foreach ($this->_getAllPlaceholders() as $placeholder) { + foreach ($this->getAllPlaceholders() as $placeholder) { /** @var \Wootook\Core\Database\Sql\Placeholder\Placeholder $placeholder */ $placeholder->afterExecute($statement); } diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Delete.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Delete.php index 025cd52..5302b13 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Delete.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Delete.php @@ -28,10 +28,10 @@ * */ -namespace Wootook\Core\Database\Sql; +namespace Wootook\Core\Database\Sql\Dml; class Delete - extends DmlFilterableQuery + extends DmlQuery { const FROM = 'FROM'; diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Insert.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Insert.php index c262915..14abfaf 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Insert.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Insert.php @@ -28,7 +28,7 @@ * */ -namespace Wootook\Core\Database\Sql; +namespace Wootook\Core\Database\Sql\Dml; use Wootook\Core\Database\Sql\Placeholder; diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Where.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Where.php index 1807256..55e2ee1 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Where.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Section/Renderer/Where.php @@ -37,24 +37,6 @@ use Wootook\Core, 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) { if ($condition instanceof Placeholder\Placeholder) { diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Select.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Select.php index e18e588..95f36a1 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Select.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Select.php @@ -28,7 +28,7 @@ * */ -namespace Wootook\Core\Database\Sql; +namespace Wootook\Core\Database\Sql\Dml; use Wootook\Core\Database\Sql\Dml\Section, Wootook\Core\Database\Sql\Placeholder; diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Update.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Update.php index 018d80e..51a297a 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Update.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Sql/Dml/Update.php @@ -28,7 +28,7 @@ * */ -namespace Wootook\Core\Database\Sql; +namespace Wootook\Core\Database\Sql\Dml; use Wootook\Core\Database\Sql\Dml\Section, Wootook\Core\Database\Sql\Placeholder; diff --git a/src/application/modules/WootookCore/src/Wootook/Core/Database/Statement/Mysql.php b/src/application/modules/WootookCore/src/Wootook/Core/Database/Statement/Mysql.php index 9d9a87d..6904516 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/Database/Statement/Mysql.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/Database/Statement/Mysql.php @@ -32,7 +32,6 @@ namespace Wootook\Core\Database\Statement; use Wootook\Core\Database, Wootook\Core\Database\Adapter, - Wootook\Core\Database\Statement, Wootook\Core\Database\Sql, Wootook\Core\Exception as CoreException; diff --git a/src/application/modules/WootookCore/src/Wootook/Core/DateTime/Formatter.php b/src/application/modules/WootookCore/src/Wootook/Core/DateTime/Formatter.php index c1f4954..44b8196 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/DateTime/Formatter.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/DateTime/Formatter.php @@ -34,6 +34,6 @@ namespace Wootook\Core\DateTime; * Date formatter and parser */ class Formatter - extends \IntlDateFormatter +// extends \IntlDateFormatter { } diff --git a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Config/Config.php b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Config/Config.php index 3f04a2c..10be5d5 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Config/Config.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Config/Config.php @@ -2,22 +2,22 @@ namespace Wootook\Core\DependencyInjection\Config; -use Wootook\Core\Config, +use Wootook\Core\Config\Node, Wootook\Core\DependencyInjection; class Config { - public function __invoke(DependencyInjection\Factory $factory, Config\Node $config) + public function __invoke(DependencyInjection\Factory $factory, Node $config) { foreach ($config as $className => $classConfig) { $classDefinition = $factory->initClassDefinition($className); $factory->registerClassDefinition($className, $classDefinition); - if ($classConfig->methods instanceof Config\Node) { + if ($classConfig->methods instanceof Node) { foreach ($classConfig->methods as $methodName => $methodConfig) { - $classDefinition-> + //$classDefinition-> } } } } -} \ No newline at end of file +} diff --git a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/ArgumentDefinition.php b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/ArgumentDefinition.php index 4336845..9b5281e 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/ArgumentDefinition.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/ArgumentDefinition.php @@ -51,13 +51,9 @@ class ArgumentDefinition public function __construct(MethodDefinition $methodDefinition, $argumentName, DependencyInjection\Registry $registry = null) { $this->_methodDefinition = $methodDefinition; - $this->_argumentName = $argumentName; - try { - $this->setReflector($methodDefinition->getArgumentReflector($argumentName)); - } catch (\ReflectionException $e) { - throw new CoreException\DependencyInjection\BadMethodCallException($e->getMessage(), $e->getCode(), $e); - } + + $this->setReflector($methodDefinition->getArgumentReflector($argumentName)); $this->_registry = $registry; } @@ -98,6 +94,16 @@ class ArgumentDefinition return $this; } + public function getType() + { + return $this->_type; + } + + public function getValue() + { + return $this->_value; + } + public function getReflector() { return $this->_reflector; diff --git a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/MethodDefinition.php b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/MethodDefinition.php index 142634e..5d73f4f 100644 --- a/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/MethodDefinition.php +++ b/src/application/modules/WootookCore/src/Wootook/Core/DependencyInjection/Definition/MethodDefinition.php @@ -72,11 +72,19 @@ class MethodDefinition $this->_registry = $registry; } + /** + * @param $argumentPosition + * @return \Wootook\Core\DependencyInjection\Definition\ArgumentDefinition + */ protected function _getArgumentDefinitionInstance($argumentPosition) { return new $this->_argumentDefinitionHandlerClass($this, $argumentPosition); } + /** + * @param \Wootook\Core\DependencyInjection\Registry $registry + * @return MethodDefinition + */ public function setRegistry(DependencyInjection\Registry $registry) { $this->_registry = $registry; @@ -84,91 +92,100 @@ class MethodDefinition return $this; } + /** + * @return null|\Wootook\Core\DependencyInjection\Registry + */ public function getRegistry() { return $this->_registry; } + /** + * @param string|int $argumentPosition + * @param mixed $argumentValue + * @return MethodDefinition + * @throws \Wootook\Core\Exception\DependencyInjection\InvalidArgumentException + */ public function bindArgumentValue($argumentPosition, $argumentValue) { - if (is_numeric($argumentPosition)) { - $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'); - } + $this->getArgumentDefinition($argumentPosition)->bindValue($argumentValue); return $this; } + /** + * @param string|int $argumentPosition + * @param mixed $argumentVariable + * @return MethodDefinition + * @throws \Wootook\Core\Exception\DependencyInjection\InvalidArgumentException + */ public function bindArgumentVariable($argumentPosition, &$argumentVariable) { - if (is_numeric($argumentPosition)) { - 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'); - } + $this->getArgumentDefinition($argumentPosition)->bindVariable($argumentVariable); 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) { throw new CoreException\DependencyInjection\RuntimeException('No registry available'); } - if (is_numeric($argumentPosition)) { - $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'); - } + $this->getArgumentDefinition($argumentPosition)->bindRegistryEntry($registryKey); return $this; } + /** + * @param int|string $argumentPosition + * @return \Wootook\Core\DependencyInjection\Definition\ArgumentDefinition + * @throws \Wootook\Core\Exception\DependencyInjection\InvalidArgumentException + */ public function getArgumentDefinition($argumentPosition) { - if (is_numeric($argumentPosition)) { - if (!isset($this->_arguments[$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_string($argumentPosition) && isset($this->_argumentIndex[$argumentPosition])) { + $argumentPosition = $this->_argumentIndex[$argumentPosition]; } + + 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() { return $this->_arguments; } + /** + * @return \ReflectionMethod + */ public function getReflector() { return $this->_reflector; } + /** + * @param \ReflectionMethod $reflector + * @return MethodDefinition + */ public function setReflector(\ReflectionMethod $reflector) { $this->_reflector = $reflector; @@ -184,14 +201,21 @@ class MethodDefinition return $this; } + /** + * @param $argumentPosition + * @return \ReflectionParameter + * @throws \Wootook\Core\Exception\DependencyInjection\InvalidArgumentException + */ public function getArgumentReflector($argumentPosition) { - if (is_numeric($argumentPosition)) { - return $this->_argumentReflectors[$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_string($argumentPosition) && isset($this->_argumentIndex[$argumentPosition])) { + $argumentPosition = $this->_argumentIndex[$argumentPosition]; } + + if (!is_int($argumentPosition) || !isset($this->_argumentReflectors[$argumentPosition])) { + throw new CoreException\DependencyInjection\InvalidArgumentException('Argument not found.'); + } + + return $this->_argumentReflectors[$argumentPosition]; } } diff --git a/src/application/modules/WootookCore/test/bootstrap.php b/src/application/modules/WootookCore/test/bootstrap.php index 067d936..858d9f2 100644 --- a/src/application/modules/WootookCore/test/bootstrap.php +++ b/src/application/modules/WootookCore/test/bootstrap.php @@ -11,4 +11,3 @@ spl_autoload_register(function ($class) { return require $map[$class]; }); -require dirname(dirname(dirname(__DIR__))) . '/code/core/Wootook.php'; diff --git a/src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Condition/ConditionTest.php b/src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Condition/ConditionTest.php index 21cc0c7..771d872 100644 --- a/src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Condition/ConditionTest.php +++ b/src/application/modules/WootookCore/test/php/WootookUnit/Core/Database/Sql/Dml/Condition/ConditionTest.php @@ -123,9 +123,9 @@ class ConditionTest $conditionMock = $this->buildMock(); $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->assertSame($placeholderMock, $result[0]); } @@ -135,25 +135,27 @@ class ConditionTest $conditionMock = $this->buildMock(); $placeholderMock = $this->getMockForAbstractClass('Wootook\\Core\\Database\\Sql\\Placeholder\\Placeholder'); - $this->callNonPublicMethod($conditionMock, '_addPlaceholder', array($placeholderMock)); - $this->callNonPublicMethod($conditionMock, '_addPlaceholder', array($placeholderMock)); - $this->callNonPublicMethod($conditionMock, '_clearPlaceholders'); + $conditionMock->addPlaceholder($placeholderMock); + $conditionMock->addPlaceholder($placeholderMock); + $conditionMock->clearPlaceholders(); $expected = array(); - $this->assertEquals($expected, $this->callNonPublicMethod($conditionMock, '_getAllPlaceholders')); + $this->assertEquals($expected, $conditionMock->getAllPlaceholders()); } public function testPlaceholderCallTrigger_beforePrepare() { + /** @var \Wootook\Core\Database\Sql\Dml\Condition\Condition $conditionMock */ $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') ->with($this->_statementMock) ; - $this->callNonPublicMethod($conditionMock, '_addPlaceholder', array($placeholderMock)); + $conditionMock->addPlaceholder($placeholderMock); $conditionMock->beforePrepare($this->_statementMock); } @@ -161,14 +163,15 @@ class ConditionTest public function testPlaceholderCallTrigger_afterPrepare() { $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') ->with($this->_statementMock) ; - $this->callNonPublicMethod($conditionMock, '_addPlaceholder', array($placeholderMock)); + $conditionMock->addPlaceholder($placeholderMock); $conditionMock->afterPrepare($this->_statementMock); } @@ -176,14 +179,15 @@ class ConditionTest public function testPlaceholderCallTrigger_beforeExecute() { $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') ->with($this->_statementMock) ; - $this->callNonPublicMethod($conditionMock, '_addPlaceholder', array($placeholderMock)); + $conditionMock->addPlaceholder($placeholderMock); $conditionMock->beforeExecute($this->_statementMock); } @@ -191,14 +195,15 @@ class ConditionTest public function testPlaceholderCallTrigger_afterExecute() { $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') ->with($this->_statementMock) ; - $this->callNonPublicMethod($conditionMock, '_addPlaceholder', array($placeholderMock)); + $conditionMock->addPlaceholder($placeholderMock); $conditionMock->afterExecute($this->_statementMock); } diff --git a/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/Definition/MethodDefinitionTest.php b/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/Definition/MethodDefinitionTest.php index a4dab1e..3eca6b5 100644 --- a/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/Definition/MethodDefinitionTest.php +++ b/src/application/modules/WootookCore/test/php/WootookUnit/Core/DependencyInjection/Definition/MethodDefinitionTest.php @@ -3,6 +3,7 @@ namespace WootookUnit\Core\DependencyInjection\Definition; use Wootook\Core\Config, + Wootook\Core\DependencyInjection, Wootook\Core\DependencyInjection\Definition; class MethodDefinitionTest extends \PHPUnit_Framework_TestCase @@ -42,9 +43,31 @@ class MethodDefinitionTest extends \PHPUnit_Framework_TestCase $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() { - $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()) ->method('getReflector') @@ -58,7 +81,7 @@ class MethodDefinitionTest extends \PHPUnit_Framework_TestCase 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()) ->method('getReflector') @@ -71,43 +94,237 @@ class MethodDefinitionTest extends \PHPUnit_Framework_TestCase $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); - $this->assertEquals(36, $definition->getConstructorArgument(0)); - } - - 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)) + $classDefinitionMock->expects($this->once()) + ->method('getReflector') + ->will($this->returnValue(new \ReflectionClass(__CLASS__))) ; - $definition->setRegistry($registry); - $definition->bindConstructorArgumentRegistry(0, 'my_object'); + $definition = new Definition\MethodDefinition($classDefinitionMock, __FUNCTION__); + $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); } - */ } diff --git a/src/application/modules/WootookCore/test/phpunit.xml b/src/application/modules/WootookCore/test/phpunit.xml index 612b9f2..c05f63b 100644 --- a/src/application/modules/WootookCore/test/phpunit.xml +++ b/src/application/modules/WootookCore/test/phpunit.xml @@ -1,7 +1,7 @@ - ./php/WootookTest/Core + ./php/WootookUnit/Core + + + + ../src/Wootook/Core + + + + + + +