From 19bc28e85cfcc029c465472dfc67a4855b74fc0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcelo=20Ara=C3=BAjo?= Date: Tue, 15 Sep 2015 15:53:41 -0300 Subject: [PATCH 1/4] use IsInt Validator instead of deprecated Int --- src/Rox/Model/AbstractModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Rox/Model/AbstractModel.php b/src/Rox/Model/AbstractModel.php index 8dd97ef..3f1de54 100755 --- a/src/Rox/Model/AbstractModel.php +++ b/src/Rox/Model/AbstractModel.php @@ -13,7 +13,7 @@ * @author Marcelo Araújo */ abstract class AbstractModel { - const INT = 'Zend\I18n\Validator\Int'; + const INT = 'Zend\I18n\Validator\IsInt'; const ALPHA = 'Zend\I18n\Validator\Alpha'; const EMAIL = 'Zend\Validator\EmailAddress'; const ALPHA_NUM = 'Zend\I18n\Validator\Alnum'; From 0c2b449a0ba24f1116c776fbe616069148ea55e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcelo=20Ara=C3=BAjo?= Date: Tue, 15 Sep 2015 16:32:45 -0300 Subject: [PATCH 2/4] use hydrator direct to model object, gateway role doesn't allow this to manipulate data --- src/Rox/Gateway/RoxGateway.php | 29 +-- src/Rox/Model/AbstractModel.php | 311 +++++++++++++++++++------------- 2 files changed, 185 insertions(+), 155 deletions(-) diff --git a/src/Rox/Gateway/RoxGateway.php b/src/Rox/Gateway/RoxGateway.php index 7d05fee..625f2b7 100755 --- a/src/Rox/Gateway/RoxGateway.php +++ b/src/Rox/Gateway/RoxGateway.php @@ -3,15 +3,12 @@ namespace Rox\Gateway; use Doctrine\Common\Inflector\Inflector; -use Rox\Hydrator\MagicMethods; -use Zend\Stdlib\Hydrator\HydratorInterface; use Rox\Model\AbstractModel; class RoxGateway { protected $model; protected $db; - protected $hydrator; protected $name; protected $reflectionClass; /** @@ -21,23 +18,14 @@ class RoxGateway { * @param Zend\Stdlib\Hydrator\HydratorInterface $hydrator */ - public function __construct($db, AbstractModel $model = null, HydratorInterface $hydrator = null) + public function __construct($db, AbstractModel $model = null) { $this->db = $db; $this->reflectionClass = new \ReflectionClass(get_class($this)); $this->name = $this->reflectionClass->getShortName(); $this->setModel($model); - $this->setHydrator($hydrator); } - /** - * - * @param array $data - */ - public function filterData(array $data){ - $model = $this->hydrator->hydrate($data, $this->model); - return $this->hydrator->extract($model); - } public function setModel($model){ if($model){ $this->model = $model; @@ -54,19 +42,4 @@ public function getModelName() { $name = $this->reflectionClass->getShortName(); return $inflector->singularize($name); } - public function setHydrator($hydrator){ - if($hydrator){ - $this->hydrator = $hydrator; - } else { - $this->hydrator = new MagicMethods(); - } - } - /** - * Proxy for Rox\Model\AbstractModel::getInputFilter() - * @return Zend\InputFilter\InputFilter - */ - public function getInputFilter($fields = null) - { - return $this->model->getInputFilter($fields); - } } \ No newline at end of file diff --git a/src/Rox/Model/AbstractModel.php b/src/Rox/Model/AbstractModel.php index 3f1de54..268c6cf 100755 --- a/src/Rox/Model/AbstractModel.php +++ b/src/Rox/Model/AbstractModel.php @@ -1,141 +1,198 @@ fields ['_id'] = null; - $currentClass = get_class ( $this ); - $refl = new \ReflectionClass ( $currentClass ); - $this->name = $refl->getShortName (); - } - public function getName() { - return $this->name; - } - public function getFields() { - return array_keys ( $this->fields ); - } - public function isIgnorable($key) { - return isset ( $this->fields [$key] ['ignore'] ) ? $this->fields [$key] ['ignore'] : false; - } - public function setInputFilter(InputFilterInterface $inputFilter) { - throw new \Exception ( "Not used" ); - } - public function __get($key) { - if (isset ( $this->fields [$key] )) { - if (isset ( $this->fields [$key] ['value'] )) { - /* - * if(is_array($this->fields[$key]['value'])){ $obj = new \ArrayObject($this->fields[$key]['value']); return $obj; }else{ return $this->fields[$key]['value']; } - */ - return $this->fields [$key] ['value']; - } elseif (isset ( $this->fields [$key] ['default'] )) { - return $this->fields [$key] ['default']; - } - } - return null; - } - - /** - * TODO this $key === '_id' is for mongo, refactor - * - * @param unknown $key - * @param unknown $value - */ - public function __set($key, $value) { - if (isset ( $this->fields [$key] ) || $key === '_id' || isset ( $this->fields ['dynamic'] )) { - /* - * if(isset($this->fields[$key]['embedded']) && !isset($this->fields[$key]['value'])){ $this->fields[$key]['value'] = new $this->fields[$key]['embedded']; }else{ $this->fields[$key]['value'] = $value; } - */ - if (isset ( $value ) /*&& ! empty ( $value )*/) { - $this->fields [$key] ['value'] = $value; - } elseif (isset ( $this->fields [$key] ['default'] )) { - $this->fields [$key] ['value'] = $this->fields [$key] ['default']; - } - } - } - /* - * TODO implement filters TODO how about files? TODO use recursivity for fieldsets - */ - public function getInputFilter($fields = null) { - // 'Prices' => ['fieldset' => ['Financing' => [[self::ALPHA_NUM, true], 24, false]]] - if (! $this->inputFilter) { - $inputFilter = new InputFilter (); - foreach ( $this->fields as $name => $options ) { - if (! $fields || in_array ( $name, $fields )) { - if (! empty ( $options ) && ! isset ( $options ['skip_validation'] )) { - if (isset ( $options ['fieldset'] )) { - $fieldset = new InputFilter ( $name ); - foreach ( $options ['fieldset'] as $field => $opt ) { - $fieldset->add ( $this->getFilter ( $opt, $field ) ); - } - $inputFilter->add ( $fieldset, $name ); - } else { - $inputFilter->add ( $this->getFilter ( $options, $name ) ); - } - } - } - } - $this->inputFilter = $inputFilter; - } - return $this->inputFilter; - } - public function getFilter($options, $name) { - $input = new Input ( $name ); - $inputValidators = $input->getValidatorChain (); - $inputFilters = $input->getFilterChain (); - - $type = isset ( $options [self::TYPE] ) ? $options [self::TYPE] : null; - if ($type) { - if (is_array ( $type )) { - $inputValidators->attach ( new $type [0] ( $type [1] ) ); - } else { - $inputValidators->attach ( new $type () ); - } - } - $length = isset ( $options [self::LENGTH] ) ? $options [self::LENGTH] : null; - if ($length) { - if (! is_array ( $length )) { - $length = [ - 0 => $length, - 1 => $length - ]; - } - $inputValidators->attach ( new StringLength ( [ - 'encoding' => 'UTF-8', - 'min' => $length [0], - 'max' => $length [1] - ] ) ); - } - $required = isset ( $options [self::REQUIRED] ) ? $options [self::REQUIRED] : null; - if ($required) { - $input->setRequired ( true ); - } else { - $input->setRequired ( false ); - } - return $input; - } +abstract class AbstractModel +{ + + const INT = 'Zend\I18n\Validator\IsInt'; + + const ALPHA = 'Zend\I18n\Validator\Alpha'; + + const EMAIL = 'Zend\Validator\EmailAddress'; + + const ALPHA_NUM = 'Zend\I18n\Validator\Alnum'; + + const IDENTICAL = 'Zend\Validator\Identical'; + + const POST_CODE = 'Zend\I18n\Validator\PostCode'; + + const FLOAT = 'Zend\I18n\Validator\Float'; + + const URI = 'Zend\Validator\Uri'; + + const TYPE = 0; + + const LENGTH = 1; + + const REQUIRED = 2; + + protected $inputFilter; + + protected $fields; + + protected $hydrator; + + protected $name; + + public function __construct(HydratorInterface $hydrator = null) + { + $this->fields['_id'] = null; + $currentClass = get_class($this); + $refl = new \ReflectionClass($currentClass); + $this->name = $refl->getShortName(); + $this->setHydrator($hydrator); + } + + public function getName() + { + return $this->name; + } + + public function getFields() + { + return array_keys($this->fields); + } + + public function isIgnorable($key) + { + return isset($this->fields[$key]['ignore']) ? $this->fields[$key]['ignore'] : false; + } + + public function setInputFilter(InputFilterInterface $inputFilter) + { + throw new \Exception("Not used"); + } + + public function setHydrator($hydrator) + { + if ($hydrator) { + $this->hydrator = $hydrator; + } else { + $this->hydrator = new MagicMethods(); + } + } + + /** + * + * @param array $data + */ + public function exchangeArray(array $data){ + $this->hydrator->hydrate($data, $this); + } + + public function getArrayCopy() + { + return $this->hydrator->extract($this); + } + + public function __get($key) + { + if (isset($this->fields[$key])) { + if (isset($this->fields[$key]['value'])) { + /* + * if(is_array($this->fields[$key]['value'])){ $obj = new \ArrayObject($this->fields[$key]['value']); return $obj; }else{ return $this->fields[$key]['value']; } + */ + return $this->fields[$key]['value']; + } elseif (isset($this->fields[$key]['default'])) { + return $this->fields[$key]['default']; + } + } + return null; + } + + /** + * TODO this $key === '_id' is for mongo, refactor + * + * @param unknown $key + * @param unknown $value + */ + public function __set($key, $value) + { + if (isset($this->fields[$key]) || $key === '_id' || isset($this->fields['dynamic'])) { + /* + * if(isset($this->fields[$key]['embedded']) && !isset($this->fields[$key]['value'])){ $this->fields[$key]['value'] = new $this->fields[$key]['embedded']; }else{ $this->fields[$key]['value'] = $value; } + */ + if (isset($value) /*&& ! empty ( $value )*/) { + $this->fields[$key]['value'] = $value; + } elseif (isset($this->fields[$key]['default'])) { + $this->fields[$key]['value'] = $this->fields[$key]['default']; + } + } + } + + /* + * TODO implement filters TODO how about files? TODO use recursivity for fieldsets + */ + public function getInputFilter($fields = null) + { + // 'Prices' => ['fieldset' => ['Financing' => [[self::ALPHA_NUM, true], 24, false]]] + if (! $this->inputFilter) { + $inputFilter = new InputFilter(); + foreach ($this->fields as $name => $options) { + if (! $fields || in_array($name, $fields)) { + if (! empty($options) && ! isset($options['skip_validation'])) { + if (isset($options['fieldset'])) { + $fieldset = new InputFilter($name); + foreach ($options['fieldset'] as $field => $opt) { + $fieldset->add($this->getFilter($opt, $field)); + } + $inputFilter->add($fieldset, $name); + } else { + $inputFilter->add($this->getFilter($options, $name)); + } + } + } + } + $this->inputFilter = $inputFilter; + } + return $this->inputFilter; + } + + public function getFilter($options, $name) + { + $input = new Input($name); + $inputValidators = $input->getValidatorChain(); + $inputFilters = $input->getFilterChain(); + $type = isset($options[self::TYPE]) ? $options[self::TYPE] : null; + if ($type) { + if (is_array($type)) { + $inputValidators->attach(new $type[0]($type[1])); + } else { + $inputValidators->attach(new $type()); + } + } + $length = isset($options[self::LENGTH]) ? $options[self::LENGTH] : null; + if ($length) { + if (! is_array($length)) { + $length = [ + 0 => $length, + 1 => $length + ]; + } + $inputValidators->attach(new StringLength([ + 'encoding' => 'UTF-8', + 'min' => $length[0], + 'max' => $length[1] + ])); + } + $required = isset($options[self::REQUIRED]) ? $options[self::REQUIRED] : null; + if ($required) { + $input->setRequired(true); + } else { + $input->setRequired(false); + } + return $input; + } } \ No newline at end of file From a684ccbb8f3014d0bdc1b2b37cbae3e47a213498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcelo=20Ara=C3=BAjo?= Date: Tue, 15 Sep 2015 16:42:24 -0300 Subject: [PATCH 3/4] adjust gateway/model code identation to PSR-2 pattern --- src/Rox/Gateway/MongoDb/AbstractGateway.php | 198 ++++++++++++-------- src/Rox/Gateway/RoxGateway.php | 82 ++++---- src/Rox/Model/AbstractModel.php | 5 + 3 files changed, 167 insertions(+), 118 deletions(-) diff --git a/src/Rox/Gateway/MongoDb/AbstractGateway.php b/src/Rox/Gateway/MongoDb/AbstractGateway.php index e533f0e..06ae776 100755 --- a/src/Rox/Gateway/MongoDb/AbstractGateway.php +++ b/src/Rox/Gateway/MongoDb/AbstractGateway.php @@ -8,132 +8,165 @@ /** * Use this class to implement collection especific methods - * @todo Review docs and transactions checking success and thow exceptions in negative cases + * + * TODO Review docs and transactions checking success and thow exceptions in negative cases * TODO implements a interface for common methods * @author Marcelo Araújo */ class AbstractGateway extends RoxGateway { - /** - * - * @param mixed $id - * @param string $module - * @param string $collection - * @return array - */ - public function getReference($id, $module, $collection){ - $className = "$module\Gateway\MongoDb\\$collection"; - $gateway = new $className($this->db); - return $gateway->findById($id); - } - /** - * - * @param array $documents - * @param int $id - * @return array|NULL - */ - public function getSubDocument($documents, $id) { - foreach ($documents as $document) { - if($document['_id'] == $id){ - return $document; - } - } - return null; - } + /** - * + * + * @param mixed $id + * @param string $module + * @param string $collection + * @return array + */ + public function getReference($id, $module, $collection) + { + $className = "$module\Gateway\MongoDb\\$collection"; + $gateway = new $className($this->db); + return $gateway->findById($id); + } + + /** + * + * @param array $documents + * @param int $id + * @return array|NULL + */ + public function getSubDocument($documents, $id) + { + foreach ($documents as $document) { + if ($document['_id'] == $id) { + return $document; + } + } + return null; + } + + /** + * * @param \MongoCursor $cursor * @return \PhlyMongo\HydratingMongoCursor */ - public function hydrateCollection(\MongoCursor $cursor){ - return new HydratingMongoCursor( - $cursor, - $this->hydrator, - $this->model - ); + public function hydrateCollection(\MongoCursor $cursor) + { + return new HydratingMongoCursor($cursor, $this->model->getHydrator(), $this->model); } + /** + * * @return \MongoCollection */ - public function getCollection(){ - return $this->db->{$this->name}; + public function getCollection() + { + return $this->getCollection(); } + /** * Find all documents from especific colection + * * @return \Zend\Paginator\Paginator */ - public function findAll($criteria = [], $sort = null){ - $cursor = $this->db->{$this->name}->find($criteria); - if($sort){ - $cursor->sort($sort); - } - $adapter = new MongoPaginatorAdapter(new HydratingMongoCursor( - $cursor, - $this->hydrator, - $this->model - )); - return new Paginator($adapter); + public function findAll($criteria = [], $sort = null) + { + $cursor = $this->getCollection()->find($criteria); + if ($sort) { + $cursor->sort($sort); + } + $adapter = new MongoPaginatorAdapter(new HydratingMongoCursor($cursor, $this->model->getHydrator(), $this->model)); + return new Paginator($adapter); } + /** * * @param array $criteria * @return array */ - public function count($criteria = []){ - return $this->db->{$this->name}->count($criteria); + public function count($criteria = []) + { + return $this->getCollection()->count($criteria); } + /** - * + * * @param array $criteria * @return array */ - public function findCurrent($criteria = []){ - return $this->db->{$this->name}->findOne($criteria); + public function findCurrent($criteria = []) + { + return $this->getCollection()->findOne($criteria); } + /** + * * @param string $label * @return array An associative array with [value => label] format */ - public function getAssocArray($criteria = [], $label = 'name'){ - $assoc = []; - $data = $this->db->{$this->name}->find($criteria,['_id', $label])->sort([$label => 1]); - foreach ($data as $record){ - $assoc[$record['_id']->{'$id'}] = $record[$label]; - } - return $assoc; + public function getAssocArray($criteria = [], $label = 'name') + { + $assoc = []; + $data = $this->getCollection() + ->find($criteria, [ + '_id', + $label + ]) + ->sort([ + $label => 1 + ]); + foreach ($data as $record) { + $assoc[$record['_id']->{'$id'}] = $record[$label]; + } + return $assoc; } + /** * Find and return a document by its mongoId - * @param mixed $id of document + * + * @param mixed $id + * of document * @return array */ - public function findById($id){ - return $this->db->{$this->name}->findOne(['_id' => $this->getMongoId($id)]); + public function findById($id) + { + return $this->getCollection()->findOne([ + '_id' => $this->getMongoId($id) + ]); } + /** - * @param array $data with _id + * + * @param array $data + * with _id * @return mixed */ - public function update(array $data){ - $data = $this->filterData($data); - $id = $this->getMongoId($data['_id']); - unset($data['_id']); - return $this->getCollection()->update(['_id' => $id], ['$set' => $data]); + public function update(array $data) + { + $id = $this->getMongoId($data['_id']); + unset($data['_id']); + return $this->getCollection()->update([ + '_id' => $id + ], [ + '$set' => $data + ]); } + /** + * * @param array $data * @return mixed */ - public function save(array $data){ - $data = $this->filterData($data); - if(!$data['_id']){ - unset($data['_id']); - } else { - $data['_id'] = $this->getMongoId($data['_id']); - } - - $this->db->{$this->name}->save($data); - return $data; + public function save(array $data) + { + if (! $data['_id']) { + unset($data['_id']); + } else { + $data['_id'] = $this->getMongoId($data['_id']); + } + $this->getCollection()->save($data); + return $data; } /** @@ -153,11 +186,16 @@ public function getMongoId($id, $field = 'unknown') throw new \Exception("Parâmetro inválido: $field"); } } + /** + * * @param mixed $id * @return mixed */ - public function delete($id){ - return $this->db->{$this->name}->remove(['_id' => $this->getMongoId($id)]); + public function delete($id) + { + return $this->getCollection()->remove([ + '_id' => $this->getMongoId($id) + ]); } } \ No newline at end of file diff --git a/src/Rox/Gateway/RoxGateway.php b/src/Rox/Gateway/RoxGateway.php index 625f2b7..9cd8875 100755 --- a/src/Rox/Gateway/RoxGateway.php +++ b/src/Rox/Gateway/RoxGateway.php @@ -1,45 +1,51 @@ db = $db; - $this->reflectionClass = new \ReflectionClass(get_class($this)); - $this->name = $this->reflectionClass->getShortName(); - $this->setModel($model); - - } - public function setModel($model){ - if($model){ - $this->model = $model; - } else { - $modelName = $this->getModelName(); - $namespace = $this->reflectionClass->getNamespaceName(); - $modelNamespace = substr($namespace, 0, strpos($namespace,"\\")); - $modelClassName = sprintf('\%s\Model\%s',$modelNamespace, $modelName); - $this->model = new $modelClassName; - } - } - public function getModelName() { - $inflector = new Inflector(); - $name = $this->reflectionClass->getShortName(); - return $inflector->singularize($name); - } +class RoxGateway +{ + + protected $model; + + protected $db; + + protected $name; + + protected $reflectionClass; + + /** + * + * @param mixed $db + * @param Rox\Model\AbstractModel $model + * @param Zend\Stdlib\Hydrator\HydratorInterface $hydrator + */ + public function __construct($db, AbstractModel $model = null) + { + $this->db = $db; + $this->reflectionClass = new \ReflectionClass(get_class($this)); + $this->name = $this->reflectionClass->getShortName(); + $this->setModel($model); + } + + public function setModel($model) + { + if ($model) { + $this->model = $model; + } else { + $modelName = $this->getModelName(); + $namespace = $this->reflectionClass->getNamespaceName(); + $modelNamespace = substr($namespace, 0, strpos($namespace, "\\")); + $modelClassName = sprintf('\%s\Model\%s', $modelNamespace, $modelName); + $this->model = new $modelClassName(); + } + } + + public function getModelName() + { + $inflector = new Inflector(); + $name = $this->reflectionClass->getShortName(); + return $inflector->singularize($name); + } } \ No newline at end of file diff --git a/src/Rox/Model/AbstractModel.php b/src/Rox/Model/AbstractModel.php index 268c6cf..bdd322d 100755 --- a/src/Rox/Model/AbstractModel.php +++ b/src/Rox/Model/AbstractModel.php @@ -84,6 +84,11 @@ public function setHydrator($hydrator) } } + public function getHydrator() + { + return $this->hydrator; + } + /** * * @param array $data From 3a1378140af983588635d1ac961850ec5d5f5138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcelo=20Ara=C3=BAjo?= Date: Wed, 16 Sep 2015 14:28:04 -0300 Subject: [PATCH 4/4] bootstrap for unit tests --- src/Rox/Gateway/MongoDb/AbstractGateway.php | 2 +- tests/Bootstrap.php | 98 ++++++++++++++++ tests/Rox/Framework/TestCase.php | 28 ----- tests/Rox/SampleTest.php | 19 ---- .../Gateway/MongoDb/AbstractGatwayTest.php | 23 ++++ ...uration.php.dist => TestConfiguration.php} | 2 +- tests/bootstrap.php | 106 ------------------ tests/phpunit.xml | 4 +- 8 files changed, 125 insertions(+), 157 deletions(-) create mode 100755 tests/Bootstrap.php delete mode 100755 tests/Rox/Framework/TestCase.php delete mode 100755 tests/Rox/SampleTest.php create mode 100755 tests/RoxTest/Gateway/MongoDb/AbstractGatwayTest.php rename tests/{TestConfiguration.php.dist => TestConfiguration.php} (93%) delete mode 100755 tests/bootstrap.php diff --git a/src/Rox/Gateway/MongoDb/AbstractGateway.php b/src/Rox/Gateway/MongoDb/AbstractGateway.php index 06ae776..acfcfab 100755 --- a/src/Rox/Gateway/MongoDb/AbstractGateway.php +++ b/src/Rox/Gateway/MongoDb/AbstractGateway.php @@ -62,7 +62,7 @@ public function hydrateCollection(\MongoCursor $cursor) */ public function getCollection() { - return $this->getCollection(); + return $this->db->{$this->name}; } /** diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php new file mode 100755 index 0000000..f79ac4a --- /dev/null +++ b/tests/Bootstrap.php @@ -0,0 +1,98 @@ + array( + 'module_paths' => $zf2ModulePaths, + ), + 'modules' => array( + 'Rox' + ) + ); + + $serviceManager = new ServiceManager(new ServiceManagerConfig()); + $serviceManager->setService('ApplicationConfig', $config); + $serviceManager->get('ModuleManager')->loadModules(); + static::$serviceManager = $serviceManager; + } + + public static function chroot() + { + $rootPath = dirname(static::findParentPath('module')); + chdir($rootPath); + } + + public static function getServiceManager() + { + return static::$serviceManager; + } + + protected static function initAutoloader() + { + $vendorPath = static::findParentPath('vendor'); + + if (file_exists($vendorPath.'/autoload.php')) { + include $vendorPath.'/autoload.php'; + } + + if (! class_exists('Zend\Loader\AutoloaderFactory')) { + throw new RuntimeException( + 'Unable to load ZF2. Run `php composer.phar install`' + ); + } + + AutoloaderFactory::factory(array( + 'Zend\Loader\StandardAutoloader' => array( + 'autoregister_zf' => true, + 'namespaces' => array( + __NAMESPACE__ => __DIR__ . '/' . __NAMESPACE__, + ), + ), + )); + } + + protected static function findParentPath($path) + { + $dir = __DIR__; + $previousDir = '.'; + while (!is_dir($dir . '/' . $path)) { + $dir = dirname($dir); + if ($previousDir === $dir) { + return false; + } + $previousDir = $dir; + } + return $dir . '/' . $path; + } +} + +Bootstrap::init(); +Bootstrap::chroot(); \ No newline at end of file diff --git a/tests/Rox/Framework/TestCase.php b/tests/Rox/Framework/TestCase.php deleted file mode 100755 index 5ac9b55..0000000 --- a/tests/Rox/Framework/TestCase.php +++ /dev/null @@ -1,28 +0,0 @@ -assertInstanceOf('Zend\Di\LocatorInterface', $this->getLocator()); - } -} diff --git a/tests/RoxTest/Gateway/MongoDb/AbstractGatwayTest.php b/tests/RoxTest/Gateway/MongoDb/AbstractGatwayTest.php new file mode 100755 index 0000000..86ae6b9 --- /dev/null +++ b/tests/RoxTest/Gateway/MongoDb/AbstractGatwayTest.php @@ -0,0 +1,23 @@ +getMockForAbstractClass('Rox\Model\AbstractModel'); + $obj = $this->getMockForAbstractClass('Rox\Gateway\MongoDb\AbstractGateway',[new \MongoClient(), $modelMock]); + $this->assertInstanceOf('\MongoDB', $obj->getCollection()); + } +} diff --git a/tests/TestConfiguration.php.dist b/tests/TestConfiguration.php similarity index 93% rename from tests/TestConfiguration.php.dist rename to tests/TestConfiguration.php index 7f1d893..1419f67 100755 --- a/tests/TestConfiguration.php.dist +++ b/tests/TestConfiguration.php @@ -20,7 +20,7 @@ * Never commit plaintext passwords to the source code repository. */ -define('ZF2_PATH', realpath(__DIR__ . '/../../../vendor/zendframework/zendframework/library/')); +define('ZF2_PATH', realpath(__DIR__ . '/../../../zendframework/zendframework/library/')); /** * The bootstrap supports several more options, however most modules will diff --git a/tests/bootstrap.php b/tests/bootstrap.php deleted file mode 100755 index 802b715..0000000 --- a/tests/bootstrap.php +++ /dev/null @@ -1,106 +0,0 @@ - array( - StandardAutoloader::AUTOREGISTER_ZF => true, - StandardAutoloader::ACT_AS_FALLBACK => false, - StandardAutoloader::LOAD_NS => $additionalNamespaces, - ) - ) -); - -// The module name is obtained using directory name or constant -$moduleName = pathinfo($rootPath, PATHINFO_BASENAME); -if (defined('MODULE_NAME')) { - $moduleName = MODULE_NAME; -} - -// A locator will be set to this class if available -$moduleTestCaseClassname = '\\'.$moduleName.'Test\\Framework\\TestCase'; - -// This module's path plus additionally defined paths are used $modulePaths -$modulePaths = array(dirname($rootPath)); -if (isset($additionalModulePaths)) { - $modulePaths = array_merge($modulePaths, $additionalModulePaths); -} - -// Load this module and defined dependencies -$modules = array($moduleName); -if (isset($moduleDependencies)) { - $modules = array_merge($modules, $moduleDependencies); -} - - -$listenerOptions = new Zend\ModuleManager\Listener\ListenerOptions(array('module_paths' => $modulePaths)); -$defaultListeners = new Zend\ModuleManager\Listener\DefaultListenerAggregate($listenerOptions); -$sharedEvents = new Zend\EventManager\SharedEventManager(); -$moduleManager = new \Zend\ModuleManager\ModuleManager($modules); -$moduleManager->getEventManager()->setSharedManager($sharedEvents); -$moduleManager->getEventManager()->attachAggregate($defaultListeners); -$moduleManager->loadModules(); - -if (method_exists($moduleTestCaseClassname, 'setLocator')) { - $config = $defaultListeners->getConfigListener()->getMergedConfig(); - - $di = new \Zend\Di\Di; - $di->instanceManager()->addTypePreference('Zend\Di\LocatorInterface', $di); - - if (isset($config['di'])) { - $diConfig = new \Zend\Di\Config($config['di']); - $diConfig->configure($di); - } - - $routerDiConfig = new \Zend\Di\Config( - array( - 'definition' => array( - 'class' => array( - 'Zend\Mvc\Router\RouteStackInterface' => array( - 'instantiator' => array( - 'Zend\Mvc\Router\Http\TreeRouteStack', - 'factory' - ), - ), - ), - ), - ) - ); - $routerDiConfig->configure($di); - - call_user_func_array($moduleTestCaseClassname.'::setLocator', array($di)); -} - -// When this is in global scope, PHPUnit catches exception: -// Exception: Zend\Stdlib\PriorityQueue::serialize() must return a string or NULL -unset($moduleManager, $sharedEvents); diff --git a/tests/phpunit.xml b/tests/phpunit.xml index ef934fa..7d3d8a7 100755 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -1,7 +1,7 @@ - + - ./ + ./RoxTest