Commit 59062708 authored by borisson_'s avatar borisson_ Committed by borisson_

Issue #2912392 by borisson_: Result count shouldn't be nullable

parent 5025ba0b
......@@ -34,9 +34,9 @@ class Result implements ResultInterface {
/**
* The facet count.
*
* @var int|null
* @var int
*/
protected $count = NULL;
protected $count = 0;
/**
* The Url object.
......@@ -68,8 +68,8 @@ class Result implements ResultInterface {
* The raw value.
* @param mixed $display_value
* The formatted value.
* @param int|null $count
* The amount of items or NULL.
* @param int $count
* The amount of items.
*/
public function __construct(FacetInterface $facet, $raw_value, $display_value, $count) {
$this->facet = $facet;
......@@ -103,7 +103,7 @@ class Result implements ResultInterface {
* {@inheritdoc}
*/
public function setCount($count) {
$this->count = $count;
$this->count = (int) $count;
}
/**
......
......@@ -36,16 +36,16 @@ interface ResultInterface {
/**
* Returns the count for the result.
*
* @return int|null
* The amount of items for the result or NULL.
* @return int
* The amount of items for the result.
*/
public function getCount();
/**
* Sets the count for the result.
*
* @param int|null $count
* The amount of items for the result or NULL.
* @param int $count
* The amount of items for the result.
*/
public function setCount($count);
......
<?php
namespace Drupal\Tests\facets\Unit\Result;
use Drupal\Core\Url;
use Drupal\facets\Entity\Facet;
use Drupal\facets\Result\Result;
use Drupal\Tests\UnitTestCase;
/**
* Class ResultTest.
*
* @group facets
*/
class ResultTest extends UnitTestCase {
/**
* Test facet creation.
*/
public function testCreation() {
$facet = new Facet(['id' => 'foo'], 'facets_facet');
$result = new Result($facet, 11, 'Eleven', '3.11');
$this->assertInstanceOf(Result::class, $result);
$this->assertSame(11, $result->getRawValue());
$this->assertSame('Eleven', $result->getDisplayValue());
$this->assertSame(3, $result->getCount());
$this->assertSame($facet, $result->getFacet());
}
/**
* Tests getters.
*/
public function testGetters() {
$facet = new Facet(['id' => 'foo'], 'facets_facet');
$result = new Result($facet, 11, 'Eleven', 3);
$result->setCount(11.2);
$this->assertSame(11, $result->getCount());
$result->setDisplayValue('Foo');
$this->assertSame('Foo', $result->getDisplayValue());
$url = new Url('foo');
$result->setUrl($url);
$this->assertSame($url, $result->getUrl());
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment