Skip to content

Commit b584e57

Browse files
author
Mikołaj Misiurewicz
authored
Merge pull request #150 from usemarkup/feat/needle-update-price-ranges
Range queries upgrade + solr debug panel upgrade + code validation
2 parents 203607b + dd62c05 commit b584e57

File tree

322 files changed

+662
-184
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

322 files changed

+662
-184
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ before_script:
2525
config-rm xdebug.ini; fi
2626

2727
script:
28-
- vendor/bin/phpstan.phar analyse -c phpstan.neon --level 7 .
29-
- vendor/phpunit/phpunit/phpunit
28+
- make all
3029
# If master branch deploy a release providing everything else passes on the deploy matrix
3130
- if [ "$deploy" = "true" ] && [ "$TRAVIS_BRANCH" = "master" ]; then nvm install --lts && nvm alias default lts
3231
&& npm install --ignore-scripts && ./node_modules/.bin/semantic-release --no-ci; fi

Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.PHONY: all
2+
default: all;
3+
4+
analysis:
5+
vendor/bin/phpstan.phar analyse -c phpstan.neon ./src --level 7
6+
7+
unit:
8+
vendor/bin/phpunit --no-coverage
9+
10+
standards:
11+
vendor/bin/phpcs -p --colors --standard=ruleset.xml ./src
12+
13+
mess:
14+
vendor/bin/phpmd ./src text phpmd.xml
15+
16+
all: analysis unit standards mess

README.md

Lines changed: 11 additions & 1 deletion
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Context;
5+
6+
use Markup\NeedleBundle\Attribute\AttributeProviderInterface;
7+
use Markup\NeedleBundle\Attribute\SpecializationContextHashInterface;
8+
use Markup\NeedleBundle\Context\ContextFilterFactory;
9+
use Markup\NeedleBundle\Facet\RangeFacetField;
10+
use Markup\NeedleBundle\Filter\FilterValueInterface;
11+
use Markup\NeedleBundle\Filter\RangeFilterValue;
12+
use Markup\NeedleBundle\Filter\UnionFilterValue;
13+
use PHPUnit\Framework\TestCase;
14+
15+
class ContextFilterFactoryTest extends TestCase
16+
{
17+
/**
18+
* @dataProvider rangeUnionDataProvider
19+
*
20+
* @param float $rangeSize
21+
* @param mixed $filterValue
22+
* @param FilterValueInterface|null $expectedFilterValue
23+
* @param bool $throwsException
24+
*/
25+
public function testRangeUnion(
26+
$filterValue,
27+
float $rangeSize,
28+
?FilterValueInterface $expectedFilterValue,
29+
bool $throwsException
30+
): void {
31+
$attributeMock = $this->createMock(RangeFacetField::class);
32+
$attributeMock->method('getRangeSize')->willReturn($rangeSize);
33+
34+
$attributeProviderMock = $this->createMock(AttributeProviderInterface::class);
35+
$attributeProviderMock->method('getAttributeByName')->willReturn($attributeMock);
36+
37+
$specializationContextHashMock = $this->createMock(SpecializationContextHashInterface::class);
38+
39+
$factory = new ContextFilterFactory($attributeProviderMock);
40+
if ($throwsException) {
41+
$this->expectException(\RuntimeException::class);
42+
}
43+
$result = $factory->create('', $filterValue, $specializationContextHashMock);
44+
if (!$result) {
45+
$this->assertSame($expectedFilterValue, $result);
46+
} else {
47+
$this->assertEquals($expectedFilterValue, $result->getFilterValue());
48+
}
49+
}
50+
51+
public function rangeUnionDataProvider(): array
52+
{
53+
return [
54+
'two simple values' => [
55+
['50', '150'],
56+
50,
57+
new UnionFilterValue([
58+
new RangeFilterValue(50, 99.99),
59+
new RangeFilterValue(150, 199.99),
60+
]),
61+
false,
62+
],
63+
'multiple overlapping values not in order' => [
64+
['87.51', '42.84', '150.01'],
65+
50.5,
66+
new UnionFilterValue([
67+
new RangeFilterValue(87.51, 138),
68+
new RangeFilterValue(42.84, 93.33),
69+
new RangeFilterValue(150.01, 200.5),
70+
]),
71+
false,
72+
],
73+
'one value' => [
74+
['75'],
75+
2.5,
76+
new RangeFilterValue(75, 77.49),
77+
false,
78+
],
79+
'explicit min and max' => [
80+
['min' => 15.2, 'max' => 99.5],
81+
-256,
82+
new RangeFilterValue(15.2, 99.5),
83+
false,
84+
],
85+
'zero values' => [
86+
[],
87+
50,
88+
null,
89+
true,
90+
],
91+
'value not an array' => [
92+
'150',
93+
50,
94+
null,
95+
true,
96+
]
97+
];
98+
}
99+
}

composer.json

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{
22
"name": "markup/needle-bundle",
33
"description": "A Symfony bundle for search. Defines a standard search query builder (including filters and faceting), and integrates with different backends (currently Solr and Elastic).",
4-
"keywords": ["search", "faceting", "solr"],
4+
"keywords": [
5+
"search",
6+
"faceting",
7+
"solr"
8+
],
59
"type": "symfony-bundle",
610
"license": "MIT",
711
"authors": [
@@ -26,7 +30,8 @@
2630
"twig/twig": "~1.12|~2.0",
2731
"markup/json": "^0.1",
2832
"doctrine/collections": "^1.5",
29-
"doctrine/orm": "^2.4"
33+
"doctrine/orm": "^2.4",
34+
"ext-json": "*"
3035
},
3136
"require-dev": {
3237
"phpunit/phpunit": "^7.5",
@@ -47,7 +52,14 @@
4752
}
4853
],
4954
"autoload": {
50-
"psr-4": { "Markup\\NeedleBundle\\": "" }
55+
"psr-4": {
56+
"Markup\\NeedleBundle\\": "src"
57+
}
58+
},
59+
"autoload-dev": {
60+
"psr-4": {
61+
"Markup\\NeedleBundle\\Tests\\": "Tests"
62+
}
5163
},
5264
"extra": {
5365
"branch-alias": {

phpmd.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="needle"
3+
xmlns="http://pmd.sf.net/ruleset/1.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
6+
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
7+
<description>Needle Ruleset</description>
8+
9+
<rule ref="vendor/markup/coding-standard/phpmd.xml">
10+
<exclude name="ElseExpression"/>
11+
<exclude name="CouplingBetweenObjects"/>
12+
<exclude name="CyclomaticComplexity"/>
13+
<exclude name="BooleanGetMethodName"/>
14+
<exclude name="ExcessiveMethodLength"/>
15+
<exclude name="NPathComplexity"/>
16+
<exclude name="LongVariable"/>
17+
</rule>
18+
</ruleset>

phpstan.neon

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
parameters:
22
excludes_analyse:
3-
- %currentWorkingDirectory%/DependencyInjection/Configuration.php
4-
- %currentWorkingDirectory%/Tests/*
5-
- %currentWorkingDirectory%/vendor/*
6-
- %currentWorkingDirectory%/bin/*
3+
- */DependencyInjection/Configuration.php
74
ignoreErrors:
85
- '#Query::addDocuments\(\) expects array#'
9-
- '#Class Symfony\\Component\\DependencyInjection\\ChildDefinition not found#'
10-
- '#Class Symfony\\Component\\DependencyInjection\\DefinitionDecorator not found#'
11-
- '#Access to undefined constant Symfony\\Component\\DependencyInjection\\ContainerInterface::SCOPE_PROTOTYPE#'
126
reportUnmatchedIgnoredErrors: false
137
inferPrivatePropertyTypeFromConstructor: true

phpunit.xml.dist

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,4 @@
88
</testsuite>
99
</testsuites>
1010

11-
<filter>
12-
<whitelist>
13-
<directory>./</directory>
14-
<exclude>
15-
<directory>./Resources</directory>
16-
<directory>./Tests</directory>
17-
<directory>./vendor</directory>
18-
</exclude>
19-
</whitelist>
20-
</filter>
2111
</phpunit>

ruleset.xml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,8 @@
44

55
<config name="ignore_warnings_on_exit" value="true"/>
66

7-
<arg name="tab-width" value="4"/>
8-
<arg name="encoding" value="utf-8"/>
9-
107
<rule ref="vendor/markup/coding-standard/Markup/ruleset.xml"/>
118

12-
<!-- Use Unix newlines -->
13-
<rule ref="Generic.Files.LineEndings">
14-
<properties>
15-
<property name="eolChar" value="\n"/>
16-
</properties>
17-
</rule>
18-
199
<!--Override to disable Fie length checks-->
2010
<rule ref="Generic.Files.LineLength">
2111
<severity>4</severity>
@@ -24,6 +14,7 @@
2414
<rule ref="Markup.Doctrine.EntityManager.EntityManagerFound"/>
2515
<rule ref="Markup.Doctrine.PreventInheritanceOfDoctrine.EntityRepositoryFound"/>
2616

27-
<exclude-pattern>Tests/*</exclude-pattern>
28-
<exclude-pattern>vendor/*</exclude-pattern>
17+
<rule ref="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue.NullabilitySymbolRequired">
18+
<type>warning</type>
19+
</rule>
2920
</ruleset>

Adapter/ElasticResultPromisePagerfantaAdapter.php renamed to src/Adapter/ElasticResultPromisePagerfantaAdapter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __construct(PromiseInterface $resultPromise)
2222
/**
2323
* Returns the number of results.
2424
*
25-
* @return integer The number of results.
25+
* @return int The number of results.
2626
*/
2727
public function getNbResults()
2828
{
@@ -32,8 +32,8 @@ public function getNbResults()
3232
/**
3333
* Returns an slice of the results.
3434
*
35-
* @param integer $offset The offset.
36-
* @param integer $length The length.
35+
* @param int $offset The offset.
36+
* @param int $length The length.
3737
*
3838
* @return array|\Traversable The slice.
3939
*/

0 commit comments

Comments
 (0)