Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravan Scafi committed Oct 18, 2018
2 parents 1d42c54 + b46fafd commit cc3eafe
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ language: php
php:
- 7.0
- 7.1
- 7.2

before_install:
- pecl install mongodb
- if [[ $TRAVIS_PHP_VERSION != 7.2 ]]; then pecl install mongodb; fi
- echo "extension = mongodb.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini

before_script:
Expand Down
19 changes: 5 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
sniff:
vendor/bin/phpcs ./src --standard='./coding_standard.xml' -n
docker-compose run --rm php vendor/bin/phpcs ./src --standard='./coding_standard.xml' -n

phpunit:
vendor/bin/phpunit
docker-compose run --rm php vendor/bin/phpunit

coverage:
vendor/bin/phpunit --coverage-html ./.coverage

MKDOCS := $(shell mkdocs -V)
docker-compose run --rm php vendor/bin/phpunit --coverage-html ./.coverage

mkdocs:
ifndef MKDOCS
pip install mkdocs
endif
mkdocs build --clean

SAMI := $(shell vendor/bin/sami.php -V)
docker-compose run --rm mkdocs mkdocs build --clean

mkapi:
ifdef SAMI
vendor/bin/sami.php update sami.php; exit 0
endif
docker-compose run --rm php vendor/bin/sami.php update sami.php
1 change: 1 addition & 0 deletions docker-compose.override.yml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version: '3'
25 changes: 25 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: '3'

services:
php:
image: leroymerlinbr/php
depends_on:
- db
volumes:
- .:/var/www/html

db:
image: mongo:4.0
command: mongod --smallfiles
volumes:
- db:/data/db
- .:/var/www/html

mkdocs:
image: polinux/mkdocs
volumes:
- .:/workdir/mkdocs

volumes:
db:
driver: local
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repo_url: https://github.com/leroy-merlin-br/mongolid

theme: readthedocs

pages:
nav:
- 'Home': 'index.md'
- 'Basics': 'basics.md'
- 'Relationships': 'relationships.md'
Expand Down
19 changes: 19 additions & 0 deletions src/Mongolid/Cursor/Cursor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Mongolid\Cursor;

use IteratorIterator;
use MongoDB\Driver\ReadPreference;
use Serializable;
use Traversable;
use MongoDB\Collection;
Expand Down Expand Up @@ -147,6 +148,24 @@ public function disableTimeout(bool $flag = true)
return $this;
}

/**
* This describes how the Cursor route the future read operations to the members of a replica set.
*
* @see http://php.net/manual/pt_BR/class.mongodb-driver-readpreference.php
*
* @param int $mode preference mode that the Cursor will use
*
* @see ReadPreference::class To get a glance of the constants available
*
* @return $this
*/
public function setReadPreference(int $mode)
{
$this->params[1]['readPreference'] = new ReadPreference($mode);

return $this;
}

/**
* Counts the number of results for this cursor.
*
Expand Down
14 changes: 14 additions & 0 deletions tests/Mongolid/Cursor/CursorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Mockery as m;
use MongoDB\Collection;
use MongoDB\Driver\Exception\LogicException;
use MongoDB\Driver\ReadPreference;
use Mongolid\ActiveRecord;
use Mongolid\Connection\Connection;
use Mongolid\Connection\Pool;
Expand Down Expand Up @@ -82,6 +83,19 @@ public function testShouldSetNoCursorTimeoutToTrue()
);
}

public function testShouldSetReadPreferenceParameterAccordingly()
{
// Arrange
$cursor = $this->getCursor();
$mode = ReadPreference::RP_SECONDARY;
$cursor->setReadPreference($mode);
$readPreferenceParameter = $this->getProtected($cursor, 'params')[1]['readPreference'];

// Assert
$this->assertInstanceOf(ReadPreference::class, $readPreferenceParameter);
$this->assertSame($readPreferenceParameter->getMode(), $mode);
}

public function testShouldCountDocuments()
{
// Arrange
Expand Down

0 comments on commit cc3eafe

Please sign in to comment.