Skip to content

Commit

Permalink
implement Countable on Objects
Browse files Browse the repository at this point in the history
  • Loading branch information
p365labs committed Sep 21, 2017
1 parent 038fc0d commit d6974ec
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 6 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ branches:
env:
- TARGET="70"
- TARGET="71"
- TARGET="72"

before_install:
# check running "docker engine" and "docker-compose" version on travis
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ All notable changes to this project will be documented in this file based on the

- Added `Query\SpanContaining`, `Query\SpanWithin` and `Query\SpanNot` [#1319](https://github.com/ruflin/Elastica/pull/1319)
- Implemented [Pipeline](https://www.elastic.co/guide/en/elasticsearch/reference/current/pipeline.html) and [Processors](https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest-processors.html). [#1373](https://github.com/ruflin/Elastica/pull/1373)
- In PHP 7.2 count() now raises a warning when an invalid parameter is passed. Only arrays and objects implementing the Countable interface should be passed.

### Improvements

Expand Down
36 changes: 36 additions & 0 deletions env/elastica/Docker72
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This image is the base image for the Elastica development and includes all parts which rarely change
# PHP 7 Docker file with Composer installed
FROM php:7.2-rc
MAINTAINER Nicolas Ruflin <spam@ruflin.com>

RUN apt-get update && apt-get install -y \
cloc \
git \
graphviz \
libxslt-dev \
nano \

zip unzip \
wget
# XSL and Graphviz for PhpDocumentor

RUN docker-php-ext-install sockets xsl

RUN rm -r /var/lib/apt/lists/*

## PHP Configuration

RUN echo "memory_limit=1024M" >> /usr/local/etc/php/conf.d/memory-limit.ini
RUN echo "date.timezone=UTC" >> /usr/local/etc/php/conf.d/timezone.ini

# Install and setup composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
ENV COMPOSER_HOME /root/composer

# Add composer bin to the environment
ENV PATH=/root/composer/vendor/bin:$PATH

COPY composer.json /root/composer/

# Install development tools, prefer source removed as automatic fallback now
RUN composer global install
10 changes: 10 additions & 0 deletions lib/Elastica/Param.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,14 @@ public function getParams()
{
return $this->_params;
}
//
// /**
// * @inheritdoc
// *
// * @return int
// */
// public function count()
// {
// return count($this->_params);
// }
}
2 changes: 1 addition & 1 deletion lib/Elastica/Query/AbstractQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
*
* @author Nicolas Ruflin <spam@ruflin.com>
*/
abstract class AbstractQuery extends Param
abstract class AbstractQuery extends Param implements \Countable
{
}
14 changes: 14 additions & 0 deletions lib/Elastica/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,18 @@ public function getJsonBigintConversion()
{
return $this->_jsonBigintConversion;
}

// /**
// * @inheritdoc
// *
// * @return int
// */
// public function count()
// {
// if (null == $this->_response) {
// return 0;
// }
//
// return count($this->_response);
// }
}
2 changes: 1 addition & 1 deletion lib/Elastica/ResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public function getQuery()
*/
public function count()
{
return sizeof($this->_results);
return count($this->_results);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion test/Elastica/Query/GeoPolygonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public function testGeoPoint()

$query = new Query(new MatchAll());
$query->setPostFilter($geoQuery);
$this->assertEquals(1, $type->search($query)->count());
$a = $type->search($query);
var_dump($a);
$this->assertEquals(1, $a->count());

// Both points should be inside
$query = new Query();
Expand Down
2 changes: 1 addition & 1 deletion test/Elastica/QueryBuilder/VersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private function assertVersions(Version $version, array $dsl)
foreach ($version->getSuggesters() as $suggester) {
$this->assertTrue(
method_exists($dsl[2], $suggester),
'suggester "'.$suggester.'" in '.get_class($version).' must be defined in '.get_class($dsl[3])
'suggester "'.$suggester.'" in '.get_class($version).' must be defined in '.get_class($dsl[2])
);
}
}
Expand Down
3 changes: 1 addition & 2 deletions test/Elastica/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ public function testGetDataEmpty()
$this->assertContains('non-existent-type', $error['reason']);
}


$this->assertEquals(0, count($response));
$this->assertNull($response);
}
}

0 comments on commit d6974ec

Please sign in to comment.