Skip to content

Commit

Permalink
Merge pull request #751 from phalcon/3.1.x
Browse files Browse the repository at this point in the history
3.1.1
  • Loading branch information
sergeyklay authored Mar 28, 2017
2 parents 25e0696 + 9ccde9b commit 3f39a27
Show file tree
Hide file tree
Showing 16 changed files with 656 additions and 44 deletions.
7 changes: 0 additions & 7 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ Hello!
* Type: bug fix | new feature | code quality | documentation
* Link to issue:

This pull request affects the following components: **(please check boxes)**

* [ ] Library
* [ ] Code Style
* [ ] Documentation
* [ ] Testing

**In raising this pull request, I confirm the following (please check boxes):**

- [ ] I have read and understood the [Contributing Guidelines](https://github.com/phalcon/incubator/blob/master/CONTRIBUTING.md)?
Expand Down
26 changes: 4 additions & 22 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Phalcon Framework
#
# Copyright (c) 2011-2016 Phalcon Team (https://www.phalconphp.com)
# Copyright (c) 2011-2017 Phalcon Team (https://www.phalconphp.com)
#
# This source file is subject to the New BSD License that is bundled
# with this package in the file LICENSE.txt.
Expand All @@ -17,11 +17,7 @@ sudo: required
php:
- 5.5
- 5.6

matrix:
include:
- php: 7.0
env: ZEND_BACKEND="--backend=ZendEngine3"
- 7.0

services:
- memcached
Expand All @@ -37,44 +33,33 @@ cache:
ccache: true
timeout: 691200
directories:
- .temp
- vendor
- $HOME/.ccache
- $HOME/.composer/cache

env:
global:
- ZEND_DONT_UNLOAD_MODULES=1
- CC="ccache gcc"
- PATH="$PATH:~/bin"
- PHALCON_VERSION="v3.0.4"
- PHALCON_VERSION="v3.1.1"

before_install:
- phpenv config-rm xdebug.ini || true
- sudo ln -s /home/travis/.phpenv/versions/$(phpenv version-name)/bin/phpize /usr/bin/
- sudo ln -s /home/travis/.phpenv/versions/$(phpenv version-name)/bin/php-config /usr/bin/
- export PHP_MAJOR="$(echo $TRAVIS_PHP_VERSION | cut -d '.' -f 1,2)"
- if [[ ! -z "${GH_TOKEN}" ]]; then composer config github-oauth.github.com ${GH_TOKEN}; echo "Configured Github token"; fi;
# Install dev-dependencies
- travis_retry composer install --prefer-dist --no-interaction --ignore-platform-reqs
- travis_retry composer require "phalcon/zephir:dev-master" --ignore-platform-reqs
- travis_retry composer require duncan3dc/fork-helper:$(if [[ "${PHP_MAJOR:0:1}" = "7" ]]; then echo "^2.0"; else echo "^1.0"; fi) --ignore-platform-reqs

install:
- ( bash tests/_ci/install_zephir.sh )
- ( bash tests/_ci/install_prereqs_$PHP_MAJOR.sh )
# See https://github.com/aerospike/aerospike-client-php/issues/127
- '[[ "${PHP_MAJOR:0:1}" == "7" ]] || bash ${TRAVIS_BUILD_DIR}/tests/_ci/install_aerospike.sh'
- git clone -q --depth=1 https://github.com/phalcon/cphalcon.git -b ${PHALCON_VERSION} >/dev/null 2>&1
- ln -s ${TRAVIS_BUILD_DIR}/.temp ${TRAVIS_BUILD_DIR}/cphalcon/.temp
- ( cd cphalcon; zephir fullclean && zephir generate $ZEND_BACKEND )
- ( cd cphalcon/ext; export CFLAGS="-g3 -O1 -std=gnu90 -Wall -DZEPHIR_RELEASE=1"; /usr/bin/phpize &> /dev/null && ./configure --silent --enable-phalcon &> /dev/null && make --silent -j"$(getconf _NPROCESSORS_ONLN)" &> /dev/null && make --silent install )
- (cd cphalcon/build; bash ./install --phpize $(phpenv which phpize) --php-config $(phpenv which php-config))
- phpenv config-add ${TRAVIS_BUILD_DIR}/tests/_ci/redis.ini
- phpenv config-add ${TRAVIS_BUILD_DIR}/tests/_ci/phalcon.ini
# Debug
- php -m
- pecl list
- ipcs -m

before_script:
- stty cols 160
Expand All @@ -91,9 +76,6 @@ script:
- vendor/bin/codecept build
- vendor/bin/codecept run -v

after_failure:
- ipcs -m

notifications:
email:
recipients:
Expand Down
2 changes: 1 addition & 1 deletion Library/Phalcon/Mailer/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ protected function createEmbedViaData($data, $name = null)
*/
protected function normalizeEmail($email)
{
if (is_array($email)) {
if (is_array($email) || $email instanceof \Traversable) {
$emails = [];

foreach ($email as $k => $v) {
Expand Down
21 changes: 20 additions & 1 deletion Library/Phalcon/Mvc/MongoCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public function save()

if (false === $exists) {
$this->_id = $status->getInsertedId();
$this->_dirtyState = self::DIRTY_STATE_PERSISTENT;
}
}

Expand Down Expand Up @@ -225,6 +226,10 @@ protected static function _getResultset($params, CollectionInterface $collection
$base = $collection;
}

if ($base instanceof PhalconCollection) {
$base->setDirtyState(PhalconCollection::DIRTY_STATE_PERSISTENT);
}

$source = $collection->getSource();

if (empty($source)) {
Expand Down Expand Up @@ -388,6 +393,7 @@ public function delete()
$success = true;

$this->fireEvent("afterDelete");
$this->_dirtyState = self::DIRTY_STATE_DETACHED;
}

return $success;
Expand All @@ -407,6 +413,10 @@ protected function _exists($collection)
return false;
}

if (!$this->_dirtyState) {
return true;
}

if (is_object($id)) {
$mongoId = $id;
} else {
Expand All @@ -423,7 +433,15 @@ protected function _exists($collection)
/**
* Perform the count using the function provided by the driver
*/
return $collection->count(["_id"=>$mongoId])>0;
$exists = $collection->count(["_id" => $mongoId]) > 0;

if ($exists) {
$this->_dirtyState = self::DIRTY_STATE_PERSISTENT;
} else {
$this->_dirtyState = self::DIRTY_STATE_TRANSIENT;
}

return $exists;
}

/**
Expand Down Expand Up @@ -505,6 +523,7 @@ public function create()
$result = $collection->insert($data, ['writeConcern' => new WriteConcern(1)]);
if ($result instanceof InsertOneResult && $result->getInsertedId()) {
$success = true;
$this->_dirtyState = self::DIRTY_STATE_PERSISTENT;
$this->_id = $result->getInsertedId();
}

Expand Down
4 changes: 2 additions & 2 deletions Library/Phalcon/Validation/Validator/CardNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use Phalcon\Validation;
use Phalcon\Validation\Message;
use Phalcon\Validation\Validator;
use Phalcon\Validation\Exception;
use Phalcon\Validation\Exception as ValidationException;

/**
* Phalcon\Mvc\Model\Validator\CardNumber
Expand Down Expand Up @@ -75,7 +75,7 @@ public function validate(Validation $validation, $attribute)
$result = ($issuer == 4);
break;
default:
throw new Exception('Incorrect type specifier');
throw new ValidationException('Incorrect type specifier');
}

if (false === $result) {
Expand Down
4 changes: 2 additions & 2 deletions Library/Phalcon/Validation/Validator/ConfirmationOf.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

use Phalcon\Validation;
use Phalcon\Validation\Validator;
use Phalcon\Validation\Exception;
use Phalcon\Validation\Exception as ValidationException;

/**
* Validates confirmation of other field value
Expand Down Expand Up @@ -50,7 +50,7 @@ class ConfirmationOf extends Validator
public function validate(Validation $validation, $attribute)
{
if (!$this->hasOption('origField')) {
throw new Exception('Original field must be set');
throw new ValidationException('Original field must be set');
}

$allowEmpty = $this->getOption('allowEmpty');
Expand Down
4 changes: 2 additions & 2 deletions Library/Phalcon/Validation/Validator/Decimal.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Phalcon\Validation;
use Phalcon\Validation\Message;
use Phalcon\Validation\Validator;
use Phalcon\Validation\Exception;
use Phalcon\Validation\Exception as ValidationException;

/**
* Phalcon\Validation\Validator\Decimal
Expand Down Expand Up @@ -47,7 +47,7 @@ public function validate(Validation $validation, $attribute)
}

if (false === $this->hasOption('places')) {
throw new Exception('A number of decimal places must be set');
throw new ValidationException('A number of decimal places must be set');
}

if ($this->hasOption('digits')) {
Expand Down
4 changes: 2 additions & 2 deletions Library/Phalcon/Validation/Validator/MongoId.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use Phalcon\Validation;
use Phalcon\Validation\Validator;
use Phalcon\Validation\Message;
use Phalcon\Validation\Exception;
use Phalcon\Validation\Exception as ValidationException;

/**
* MongoId validator
Expand All @@ -41,7 +41,7 @@ class MongoId extends Validator
public function validate(Validation $validation, $attribute)
{
if (!extension_loaded('mongo')) {
throw new Exception('Mongo extension is not available');
throw new ValidationException('Mongo extension is not available');
}

$value = $validation->getValue($attribute);
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Then create the `composer.json` file as follows:
```json
{
"require": {
"phalcon/incubator": "^3.0"
"phalcon/incubator": "^3.1"
}
}
```
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"type": "library",
"description": "Adapters, prototypes or functionality that can be potentially incorporated to the C-framework.",
"keywords": ["framework", "phalcon", "incubator"],
"homepage": "http://phalconphp.com",
"homepage": "https://phalconphp.com",
"license": "BSD-3-Clause",
"authors": [
{
"name": "Phalcon Team",
"email": "[email protected]",
"homepage": "http://phalconphp.com/en/team"
"homepage": "https://phalconphp.com/en/team"
},
{
"name": "Contributors",
Expand All @@ -23,13 +23,13 @@
},
"require": {
"php": ">=5.5",
"ext-phalcon": "^3.0",
"ext-phalcon": "^3.1",
"swiftmailer/swiftmailer": "~5.2"
},
"require-dev": {
"phpdocumentor/reflection-docblock": "2.0.4",
"phpunit/phpunit": "^4.8",
"squizlabs/php_codesniffer": "^2.7",
"squizlabs/php_codesniffer": "^2.8",
"codeception/codeception": "^2.2",
"codeception/mockery-module": "^0.2",
"codeception/aerospike-module": "^1.0",
Expand Down
25 changes: 25 additions & 0 deletions tests/_data/collections/Robots.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Phalcon\Test\Collections;

use Phalcon\Mvc\MongoCollection;

/**
* Robots Collection
*
* @method static Robots[] find(array $parameters = null)
* @method static Robots findFirst(array $parameters = null)
*
* @property \MongoId _id
* @property string name
* @property string type
* @property int year
* @property string datetime
* @property string deleted
* @property string text
*
* @package Phalcon\Test\Collections
*/
class Robots extends MongoCollection
{
}
33 changes: 33 additions & 0 deletions tests/_data/collections/Users.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Phalcon\Test\Collections;

use Phalcon\Mvc\MongoCollection;
use Phalcon\Validation;
use Phalcon\Validation\Validator\Email;
use Phalcon\Validation\Validator\ExclusionIn;
use Phalcon\Validation\Validator\InclusionIn;
use Phalcon\Validation\Validator\PresenceOf;
use Phalcon\Validation\Validator\Regex;
use Phalcon\Validation\Validator\StringLength;
use Phalcon\Validation\Validator\Uniqueness;

class Users extends MongoCollection
{
public function validation()
{
$validator = new Validation();
$validator
->add('created_at', new PresenceOf())

->add('email', new StringLength(['min' => '7', 'max' => '50']))
->add('email', new Email())
->add('email', new Uniqueness())

->add('status', new ExclusionIn(['domain' => ['P', 'I', 'w']]))
->add('status', new InclusionIn(['domain' => ['A', 'y', 'Z']]))
->add('status', new Regex(['pattern' => '/[A-Z]/']));

return $this->validate($validator);
}
}
38 changes: 38 additions & 0 deletions tests/_support/Helper/CollectionTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Helper;

use Codeception\Actor;
use Phalcon\Mvc\Collection\Manager;
use Phalcon\Db\Adapter\MongoDB\Client;
use Phalcon\Di;

/**
* Collection Initializer
*
* @package Helper
*/
trait CollectionTrait
{
/**
* Executed before each test
*/
protected function setupMongo(Actor $I)
{
if (!extension_loaded('mongodb')) {
$I->markTestSkipped('mongodb extension not loaded');
}

Di::reset();

$di = new Di();
$di->set('mongo', function() {
$dsn = 'mongodb://' . env('TEST_MONGODB_HOST', '127.0.0.1') . ':' . env('TEST_MONGODB_PORT', 27017);
$mongo = new Client($dsn);

return $mongo->selectDatabase(env('TEST_MONGODB_NAME', 'incubator'));
});

$di->set('collectionManager', Manager::class);
}
}
Loading

0 comments on commit 3f39a27

Please sign in to comment.