diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index bf4fdcc44..f47b32c67 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -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)? diff --git a/.travis.yml b/.travis.yml index 2a639d033..b1ad1fbea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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. @@ -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 @@ -37,17 +33,13 @@ 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 @@ -55,26 +47,19 @@ before_install: - 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 @@ -91,9 +76,6 @@ script: - vendor/bin/codecept build - vendor/bin/codecept run -v -after_failure: - - ipcs -m - notifications: email: recipients: diff --git a/Library/Phalcon/Mailer/Message.php b/Library/Phalcon/Mailer/Message.php index 9a07fab79..f50c7e69e 100644 --- a/Library/Phalcon/Mailer/Message.php +++ b/Library/Phalcon/Mailer/Message.php @@ -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) { diff --git a/Library/Phalcon/Mvc/MongoCollection.php b/Library/Phalcon/Mvc/MongoCollection.php index fe6afc942..6859da69c 100644 --- a/Library/Phalcon/Mvc/MongoCollection.php +++ b/Library/Phalcon/Mvc/MongoCollection.php @@ -136,6 +136,7 @@ public function save() if (false === $exists) { $this->_id = $status->getInsertedId(); + $this->_dirtyState = self::DIRTY_STATE_PERSISTENT; } } @@ -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)) { @@ -388,6 +393,7 @@ public function delete() $success = true; $this->fireEvent("afterDelete"); + $this->_dirtyState = self::DIRTY_STATE_DETACHED; } return $success; @@ -407,6 +413,10 @@ protected function _exists($collection) return false; } + if (!$this->_dirtyState) { + return true; + } + if (is_object($id)) { $mongoId = $id; } else { @@ -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; } /** @@ -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(); } diff --git a/Library/Phalcon/Validation/Validator/CardNumber.php b/Library/Phalcon/Validation/Validator/CardNumber.php index 5cc70877f..d31837279 100644 --- a/Library/Phalcon/Validation/Validator/CardNumber.php +++ b/Library/Phalcon/Validation/Validator/CardNumber.php @@ -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 @@ -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) { diff --git a/Library/Phalcon/Validation/Validator/ConfirmationOf.php b/Library/Phalcon/Validation/Validator/ConfirmationOf.php index 9f1d5083c..d015ea917 100644 --- a/Library/Phalcon/Validation/Validator/ConfirmationOf.php +++ b/Library/Phalcon/Validation/Validator/ConfirmationOf.php @@ -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 @@ -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'); diff --git a/Library/Phalcon/Validation/Validator/Decimal.php b/Library/Phalcon/Validation/Validator/Decimal.php index 8dc27077d..6f6ba589b 100644 --- a/Library/Phalcon/Validation/Validator/Decimal.php +++ b/Library/Phalcon/Validation/Validator/Decimal.php @@ -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 @@ -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')) { diff --git a/Library/Phalcon/Validation/Validator/MongoId.php b/Library/Phalcon/Validation/Validator/MongoId.php index ea2689554..f59483743 100644 --- a/Library/Phalcon/Validation/Validator/MongoId.php +++ b/Library/Phalcon/Validation/Validator/MongoId.php @@ -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 @@ -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); diff --git a/README.md b/README.md index 98188212f..36135105e 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Then create the `composer.json` file as follows: ```json { "require": { - "phalcon/incubator": "^3.0" + "phalcon/incubator": "^3.1" } } ``` diff --git a/composer.json b/composer.json index 88dd39715..7456509a2 100644 --- a/composer.json +++ b/composer.json @@ -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": "team@phalconphp.com", - "homepage": "http://phalconphp.com/en/team" + "homepage": "https://phalconphp.com/en/team" }, { "name": "Contributors", @@ -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", diff --git a/tests/_data/collections/Robots.php b/tests/_data/collections/Robots.php new file mode 100644 index 000000000..1ca9d13f9 --- /dev/null +++ b/tests/_data/collections/Robots.php @@ -0,0 +1,25 @@ +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); + } +} \ No newline at end of file diff --git a/tests/_support/Helper/CollectionTrait.php b/tests/_support/Helper/CollectionTrait.php new file mode 100644 index 000000000..ae43da327 --- /dev/null +++ b/tests/_support/Helper/CollectionTrait.php @@ -0,0 +1,38 @@ +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); + } +} diff --git a/tests/unit/Mvc/Collection/Helpers/UniquenessTrait.php b/tests/unit/Mvc/Collection/Helpers/UniquenessTrait.php new file mode 100644 index 000000000..97b479c5a --- /dev/null +++ b/tests/unit/Mvc/Collection/Helpers/UniquenessTrait.php @@ -0,0 +1,204 @@ +add('type', new Uniqueness()); + $messages = $validation->validate(null, $this->robot); + $I->assertCount(0, $messages); + $I->assertTrue($this->robot->save()); + $messages = $validation->validate(null, $this->robot); + $I->assertCount(0, $messages); + $messages = $validation->validate(null, $this->anotherRobot); + $I->assertCount(0, $messages); + $messages = $validation->validate(null, $this->deletedRobot); + $I->assertCount(1, $messages); + } + + private function testSingleFieldConvert(UnitTester $I) + { + $validation = new Validation(); + $validation->add( + 'type', + new Uniqueness( + [ + 'convert' => function (array $values) { + $values['type'] = 'hydraulic'; // mechanical -> hydraulic + return $values; + }, + ] + ) + ); + $messages = $validation->validate(null, $this->deletedRobot); + $I->assertCount(0, $messages); + } + + private function testSingleFieldWithNull(UnitTester $I) + { + $validation = new Validation(); + $validation->add('deleted', new Uniqueness()); + $messages = $validation->validate(null, $this->robot); + $I->assertCount(0, $messages); + $messages = $validation->validate(null, $this->anotherRobot); + $I->assertCount(1, $messages); + $messages = $validation->validate(null, $this->deletedRobot); + $I->assertCount(0, $messages); + } + + private function testMultipleFields(UnitTester $I) + { + $validation = new Validation(); + $validation->add(['name', 'type'], new Uniqueness()); + $messages = $validation->validate(null, $this->robot); + $I->assertCount(0, $messages); + $messages = $validation->validate(null, $this->anotherRobot); + $I->assertCount(0, $messages); + $messages = $validation->validate(null, $this->deletedRobot); + $I->assertCount(1, $messages); + } + + private function testMultipleFieldsConvert(UnitTester $I) + { + $validation = new Validation(); + $validation->add( + ['name', 'type'], + new Uniqueness( + [ + 'convert' => function (array $values) { + $values['type'] = 'hydraulic'; // mechanical -> hydraulic + return $values; + }, + ] + ) + ); + $messages = $validation->validate(null, $this->deletedRobot); + $I->assertCount(0, $messages); + } + + private function testMultipleFieldsWithNull(UnitTester $I) + { + $validation = new Validation(); + $validation->add(['type', 'deleted'], new Uniqueness()); + $messages = $validation->validate(null, $this->robot); + $I->assertCount(0, $messages); + $messages = $validation->validate(null, $this->anotherRobot); + $I->assertCount(0, $messages); + $messages = $validation->validate(null, $this->deletedRobot); + $I->assertCount(0, $messages); + $this->deletedRobot->deleted = null; + $messages = $validation->validate(null, $this->deletedRobot); + $I->assertCount(1, $messages); + $this->deletedRobot->deleted = (new DateTime())->format('Y-m-d H:i:s'); + } + + private function testExceptSingleFieldSingleExcept(UnitTester $I) + { + $validation = new Validation(); + $validation->add( + 'year', + new Uniqueness( + [ + 'except' => 1972, + ] + ) + ); + $messages = $validation->validate(null, $this->robot); + $I->assertCount(0, $messages); + $I->assertTrue($this->anotherRobot->save()); + $messages = $validation->validate(null, $this->deletedRobot); + $I->assertCount(1, $messages); + } + + private function testExceptSingleFieldMultipleExcept(UnitTester $I) + { + $validation = new Validation(); + $validation->add( + 'year', + new Uniqueness( + [ + 'except' => [1972, 1952], + ] + ) + ); + $messages = $validation->validate(null, $this->robot); + $I->assertCount(0, $messages); + $messages = $validation->validate(null, $this->anotherRobot); + $I->assertCount(0, $messages); + } + + private function testExceptMultipleFieldSingleExcept(UnitTester $I) + { + $validation = new Validation(); + $validation->add( + ['type', 'year'], + new Uniqueness( + [ + 'except' => [ + 'type' => 'hydraulic', + 'year' => 1952, + ], + ] + ) + ); + $messages = $validation->validate(null, $this->deletedRobot); + $I->assertCount(0, $messages); + $this->deletedRobot->type = 'mechanical'; + $this->deletedRobot->year = 1972; + $messages = $validation->validate(null, $this->deletedRobot); + $I->assertCount(1, $messages); + $this->deletedRobot->type = 'hydraulic'; + $this->deletedRobot->year = 1952; + } + + private function testExceptMultipleFieldMultipleExcept(UnitTester $I) + { + $validation = new Validation(); + $validation->add( + ['year', 'type'], + new Uniqueness( + [ + 'except' => [ + 'year' => [1942, 1972], + 'type' => ['hydraulic', 'cyborg'], + ], + ] + ) + ); + $messages = $validation->validate(null, $this->robot); + $I->assertCount(0, $messages); + $messages = $validation->validate(null, $this->anotherRobot); + $I->assertCount(0, $messages); + } + + private function testConvertArrayReturnsArray(UnitTester $I) + { + $validation = new Validation(); + $validation->add( + 'type', + new Uniqueness( + [ + 'convert' => function (array $values) { + ($values); + + return null; + }, + ] + ) + ); + try { + $validation->validate(null, $this->robot); + $I->assertTrue(false); + } catch (\Exception $e) { + $I->assertTrue(true); + } + } +} \ No newline at end of file diff --git a/tests/unit/Mvc/Collection/Helpers/ValidationBase.php b/tests/unit/Mvc/Collection/Helpers/ValidationBase.php new file mode 100644 index 000000000..769a87828 --- /dev/null +++ b/tests/unit/Mvc/Collection/Helpers/ValidationBase.php @@ -0,0 +1,210 @@ +email = 'fuego@hotmail.com'; + $collection->created_at = (new DateTime())->format('Y-m-d H:i:s'); + $collection->status = 'A'; + $I->assertTrue($collection->save()); + } + + protected function presenceOf(UnitTester $I) + { + $collection = new Users(); + $collection->email = 'diego@hotmail.com'; + $collection->created_at = null; + $collection->status = 'A'; + $I->assertFalse($collection->save()); + + $expected = [ + Message::__set_state( + [ + '_message' => 'Field created_at is required', + '_field' => 'created_at', + '_type' => 'PresenceOf', + '_code' => 0, + ] + ), + ]; + + $I->assertEquals($expected, $collection->getMessages()); + } + + protected function email(UnitTester $I) + { + $collection = new Users(); + $collection->email = 'fuego?='; + $collection->created_at = (new DateTime())->format('Y-m-d H:i:s'); + $collection->status = 'A'; + $I->assertFalse($collection->save()); + + $expected = [ + Message::__set_state( + [ + '_message' => 'Field email must be an email address', + '_field' => 'email', + '_type' => 'Email', + '_code' => 0, + ] + ), + ]; + + $I->assertEquals($expected, $collection->getMessages()); + } + + protected function exclusionIn(UnitTester $I) + { + $collection = new Users(); + $collection->email = 'serghei@hotmail.com'; + $collection->created_at = (new DateTime())->format('Y-m-d H:i:s'); + $collection->status = 'P'; + $I->assertFalse($collection->save()); + + $expected = [ + Message::__set_state( + [ + '_message' => 'Field status must not be a part of list: P, I, w', + '_field' => 'status', + '_type' => 'ExclusionIn', + '_code' => 0, + ] + ), + Message::__set_state( + [ + '_message' => 'Field status must be a part of list: A, y, Z', + '_field' => 'status', + '_type' => 'InclusionIn', + '_code' => 0, + ] + ), + ]; + + $I->assertEquals($expected, $collection->getMessages()); + } + + protected function inclusionIn(UnitTester $I) + { + $collection = new Users(); + $collection->email = 'serghei@hotmail.com'; + $collection->created_at = (new DateTime())->format('Y-m-d H:i:s'); + $collection->status = 'R'; + $I->assertFalse($collection->save()); + + $expected = [ + Message::__set_state( + [ + '_message' => 'Field status must be a part of list: A, y, Z', + '_field' => 'status', + '_type' => 'InclusionIn', + '_code' => 0, + ] + ), + ]; + + $I->assertEquals($expected, $collection->getMessages()); + } + + protected function uniqueness1(UnitTester $I) + { + $collection = new Users(); + $collection->email = 'jurigag@hotmail.com'; + $collection->created_at = (new DateTime())->format('Y-m-d H:i:s'); + $collection->status = 'A'; + $I->assertTrue($collection->save()); + + $collection = new Users(); + $collection->email = 'jurigag@hotmail.com'; + $collection->created_at = (new DateTime())->format('Y-m-d H:i:s'); + $collection->status = 'A'; + $I->assertFalse($collection->save()); + + $expected = [ + Message::__set_state( + [ + '_message' => 'Field email must be unique', + '_field' => 'email', + '_type' => 'Uniqueness', + '_code' => 0, + ] + ), + ]; + + $I->assertEquals($expected, $collection->getMessages()); + } + + protected function regex(UnitTester $I) + { + $collection = new Users(); + $collection->email = 'andres@hotmail.com'; + $collection->created_at = (new DateTime())->format('Y-m-d H:i:s'); + $collection->status = 'y'; + $I->assertFalse($collection->save()); + + $expected = [ + Message::__set_state( + [ + '_message' => 'Field status does not match the required format', + '_field' => 'status', + '_type' => 'Regex', + '_code' => 0, + ] + ), + ]; + + $I->assertEquals($expected, $collection->getMessages()); + } + + protected function tooLong(UnitTester $I) + { + $collection = new Users(); + $collection->email = str_repeat('a', 50).'@hotmail.com'; + $collection->created_at = (new DateTime())->format('Y-m-d H:i:s'); + $collection->status = 'A'; + $I->assertFalse($collection->save()); + + $expected = [ + Message::__set_state( + [ + '_message' => 'Field email must not exceed 50 characters long', + '_field' => 'email', + '_type' => 'TooLong', + '_code' => 0, + ] + ), + ]; + + $I->assertEquals($expected, $collection->getMessages()); + } + + protected function tooShort(UnitTester $I) + { + $collection = new Users(); + $collection->email = 'a@b.c'; + $collection->created_at = (new DateTime())->format('Y-m-d H:i:s'); + $collection->status = 'A'; + $I->assertFalse($collection->save()); + + $expected = [ + Message::__set_state( + [ + '_message' => 'Field email must be at least 7 characters long', + '_field' => 'email', + '_type' => 'TooShort', + '_code' => 0, + ] + ), + ]; + + $I->assertEquals($expected, $collection->getMessages()); + } +} diff --git a/tests/unit/Mvc/Collection/ValidationCest.php b/tests/unit/Mvc/Collection/ValidationCest.php new file mode 100644 index 000000000..672ff8bd0 --- /dev/null +++ b/tests/unit/Mvc/Collection/ValidationCest.php @@ -0,0 +1,108 @@ + + * @package Phalcon\Test\Mvc\Collection + * @group Db + * + * The contents of this file are subject to the New BSD License that is + * bundled with this package in the file LICENSE.txt + * + * If you did not receive a copy of the license and are unable to obtain it + * through the world-wide-web, please send an email to license@phalconphp.com + * so that we can send you a copy immediately. + */ +class ValidationCest extends ValidationBase +{ + /** + * @var Robots + */ + private $robot; + + /** + * @var Robots + */ + private $anotherRobot; + + /** + * @var Robots + */ + private $deletedRobot; + + use CollectionTrait; + use UniquenessTrait; + + public function mongo(UnitTester $I) + { + $I->wantToTest("Collection validation"); + + $this->setupMongo($I); + + $this->success($I); + $this->presenceOf($I); + $this->email($I); + $this->exclusionIn($I); + $this->inclusionIn($I); + $this->uniqueness1($I); + $this->regex($I); + $this->tooLong($I); + $this->tooShort($I); + } + + public function mongoUniqueness(UnitTester $I) + { + $I->wantToTest("Collection Uniqueness validation"); + + $this->setupMongo($I); + + $this->robot = new Robots(); + $this->robot->name = 'Robotina'; + $this->robot->type = 'mechanical'; + $this->robot->year = 1972; + $this->robot->datetime = (new DateTime())->format('Y-m-d H:i:s'); + $this->robot->deleted = null; + $this->robot->text = 'text'; + + $this->anotherRobot = new Robots(); + $this->anotherRobot->name = 'Robotina'; + $this->anotherRobot->type = 'hydraulic'; + $this->anotherRobot->year = 1952; + $this->anotherRobot->datetime = (new DateTime())->format('Y-m-d H:i:s'); + $this->anotherRobot->deleted = null; + $this->anotherRobot->text = 'text'; + + $this->deletedRobot = new Robots(); + $this->deletedRobot->name = 'Robotina'; + $this->deletedRobot->type = 'mechanical'; + $this->deletedRobot->year = 1952; + $this->deletedRobot->datetime = (new DateTime())->format('Y-m-d H:i:s'); + $this->deletedRobot->deleted = (new DateTime())->format('Y-m-d H:i:s'); + $this->deletedRobot->text = 'text'; + + $this->testSingleField($I); + $this->testSingleFieldConvert($I); + $this->testSingleFieldWithNull($I); + $this->testMultipleFields($I); + $this->testMultipleFieldsConvert($I); + $this->testMultipleFieldsWithNull($I); + $this->testExceptSingleFieldSingleExcept($I); + $this->testExceptSingleFieldMultipleExcept($I); + $this->testExceptMultipleFieldSingleExcept($I); + $this->testExceptMultipleFieldMultipleExcept($I); + $this->testConvertArrayReturnsArray($I); + } +} \ No newline at end of file