cs: Fix code style (safe rules only).

This commit is contained in:
Pol Dellaiera
2021-11-23 14:06:38 +01:00
parent 149d7ce991
commit 8f96a1121d
1223 changed files with 65199 additions and 64625 deletions

View File

@@ -1,29 +1,19 @@
<?php
/*
* Chill is a suite of a modules, Chill is a software for social workers
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Tests\Search;
/**
* Description of AbstractSearch
* Description of AbstractSearch.
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
* @internal
* @coversNothing
*/
class AbstractSearchTest extends \PHPUnit\Framework\TestCase
{
@@ -31,22 +21,21 @@ class AbstractSearchTest extends \PHPUnit\Framework\TestCase
* @var \Chill\MainBundle\Search\AbstractSearch
*/
private $stub;
public function setUp()
{
$this->stub = $this->getMockForAbstractClass('Chill\MainBundle\Search\AbstractSearch');
}
public function testParseDateRegular()
{
$date = $this->stub->parseDate('2014-05-01');
$this->assertEquals('2014', $date->format('Y'));
$this->assertEquals('05', $date->format('m'));
$this->assertEquals('01', $date->format('d'));
}
public function testRecompose()
{
$this->markTestSkipped();

View File

@@ -1,12 +1,39 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Search;
use Chill\MainBundle\Search\SearchApiQuery;
use PHPUnit\Framework\TestCase;
use function is_string;
/**
* @internal
* @coversNothing
*/
class SearchApiQueryTest extends TestCase
{
public function testBuildParams()
{
$q = new SearchApiQuery();
$q
->addSelectClause('bada', ['one', 'two'])
->addSelectClause('boum', ['three', 'four'])
->setWhereClauses('mywhere', ['six', 'seven']);
$params = $q->buildParameters();
$this->assertEquals(['six', 'seven'], $q->buildParameters(true));
$this->assertEquals(['one', 'two', 'three', 'four', 'six', 'seven'], $q->buildParameters());
}
public function testMultipleWhereClauses()
{
$q = new SearchApiQuery();
@@ -14,9 +41,8 @@ class SearchApiQueryTest extends TestCase
->setSelectKey('bim')
->setSelectPertinence('?', ['gamma'])
->setFromClause('badaboum')
->andWhereClause('foo', [ 'alpha' ])
->andWhereClause('bar', [ 'beta' ])
;
->andWhereClause('foo', ['alpha'])
->andWhereClause('bar', ['beta']);
$query = $q->buildQuery();
@@ -35,27 +61,9 @@ class SearchApiQueryTest extends TestCase
$q->setSelectJsonbMetadata('boum')
->setSelectKey('bim')
->setSelectPertinence('1')
->setFromClause('badaboum')
;
->setFromClause('badaboum');
$this->assertTrue(\is_string($q->buildQuery()));
$this->assertTrue(is_string($q->buildQuery()));
$this->assertEquals([], $q->buildParameters());
}
public function testBuildParams()
{
$q = new SearchApiQuery();
$q
->addSelectClause('bada', [ 'one', 'two' ])
->addSelectClause('boum', ['three', 'four'])
->setWhereClauses('mywhere', [ 'six', 'seven'])
;
$params = $q->buildParameters();
$this->assertEquals(['six', 'seven'], $q->buildParameters(true));
$this->assertEquals(['one', 'two', 'three', 'four', 'six', 'seven'], $q->buildParameters());
}
}

View File

@@ -1,34 +1,25 @@
<?php
/*
/**
* Chill is a software for social workers
*
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Test\Search;
use Chill\MainBundle\Search\SearchProvider;
use Chill\MainBundle\Search\SearchInterface;
use Chill\MainBundle\Search\SearchProvider;
use PHPUnit\Framework\TestCase;
/**
* @internal
* @coversNothing
*/
class SearchProviderTest extends TestCase
{
/**
*
* @var SearchProvider
*/
private $search;
@@ -39,85 +30,14 @@ class SearchProviderTest extends TestCase
//add a default service
$this->addSearchService(
$this->createDefaultSearchService('I am default', 10), 'default'
);
$this->createDefaultSearchService('I am default', 10),
'default'
);
//add a domain service
$this->addSearchService(
$this->createNonDefaultDomainSearchService('I am domain bar', 20, FALSE), 'bar'
);
}
/**
* @expectedException \Chill\MainBundle\Search\UnknowSearchNameException
*/
public function testInvalidSearchName()
{
$this->search->getByName("invalid name");
}
public function testSimplePattern()
{
$terms = $this->p("@person birthdate:2014-01-02 name:\"my name\" is not my name");
$this->assertEquals(array(
'_domain' => 'person',
'birthdate' => '2014-01-02',
'_default' => 'is not my name',
'name' => 'my name'
), $terms);
}
public function testWithoutDomain()
{
$terms = $this->p('foo:bar residual');
$this->assertEquals(array(
'_domain' => null,
'foo' => 'bar',
'_default' => 'residual'
), $terms);
}
public function testWithoutDefault()
{
$terms = $this->p('@person foo:bar');
$this->assertEquals(array(
'_domain' => 'person',
'foo' => 'bar',
'_default' => ''
), $terms);
}
public function testCapitalLetters()
{
$terms = $this->p('Foo:Bar LOL marCi @PERSON');
$this->assertEquals(array(
'_domain' => 'person',
'_default' => 'lol marci',
'foo' => 'bar'
), $terms);
}
/**
* @expectedException Chill\MainBundle\Search\ParsingException
*/
public function testMultipleDomainError()
{
$term = $this->p("@person @report");
}
public function testDoubleParenthesis()
{
$terms = $this->p('@papamobile name:"my beautiful name" residual surname:"i love techno"');
$this->assertEquals(array(
'_domain' => 'papamobile',
'name' => 'my beautiful name',
'_default' => 'residual',
'surname' => 'i love techno'
), $terms);
$this->createNonDefaultDomainSearchService('I am domain bar', 20, false),
'bar'
);
}
public function testAccentued()
@@ -126,10 +46,10 @@ class SearchProviderTest extends TestCase
$terms = $this->p('manço bélier aztèque à saloù ê');
$this->assertEquals(array(
'_domain' => NULL,
'_default' => 'manco belier azteque a salou e'
), $terms);
$this->assertEquals([
'_domain' => null,
'_default' => 'manco belier azteque a salou e',
], $terms);
}
public function testAccentuedCapitals()
@@ -138,47 +58,65 @@ class SearchProviderTest extends TestCase
$terms = $this->p('MANÉÀ oÛ lÎ À');
$this->assertEquals(array(
'_domain' => null,
'_default' => 'manea ou li a'
), $terms);
}
public function testTrimInParenthesis()
{
$terms = $this->p('foo:"bar "');
$this->assertEquals(array(
'_domain' => null,
'foo' => 'bar',
'_default' => ''
), $terms);
}
public function testTrimInDefault()
{
$terms = $this->p(' foo bar ');
$this->assertEquals(array(
'_domain' => null,
'_default' => 'foo bar'
), $terms);
$this->assertEquals([
'_domain' => null,
'_default' => 'manea ou li a',
], $terms);
}
public function testArgumentNameWithTrait()
{
$terms = $this->p('date-from:2016-05-04');
$this->assertEquals(array(
$this->assertEquals([
'_domain' => null,
'date-from' => '2016-05-04',
'_default' => ''
), $terms);
'_default' => '',
], $terms);
}
public function testCapitalLetters()
{
$terms = $this->p('Foo:Bar LOL marCi @PERSON');
$this->assertEquals([
'_domain' => 'person',
'_default' => 'lol marci',
'foo' => 'bar',
], $terms);
}
public function testDoubleParenthesis()
{
$terms = $this->p('@papamobile name:"my beautiful name" residual surname:"i love techno"');
$this->assertEquals([
'_domain' => 'papamobile',
'name' => 'my beautiful name',
'_default' => 'residual',
'surname' => 'i love techno',
], $terms);
}
/**
* @expectedException \Chill\MainBundle\Search\UnknowSearchNameException
*/
public function testInvalidSearchName()
{
$this->search->getByName('invalid name');
}
/**
* @expectedException \Chill\MainBundle\Search\ParsingException
*/
public function testMultipleDomainError()
{
$term = $this->p('@person @report');
}
/**
* Test the behaviour when no domain is provided in the search pattern :
* the default search should be enabled
* the default search should be enabled.
*/
public function testSearchResultDefault()
{
@@ -186,9 +124,24 @@ class SearchProviderTest extends TestCase
//$this->markTestSkipped();
$this->assertEquals(array(
"I am default"
), $response);
$this->assertEquals([
'I am default',
], $response);
}
public function testSearchResultDomainSearch()
{
//add a search service which will be supported
$this->addSearchService(
$this->createNonDefaultDomainSearchService('I am domain foo', 100, true),
'foo'
);
$response = $this->search->getSearchResults('@foo default search');
$this->assertEquals([
'I am domain foo',
], $response);
}
/**
@@ -199,35 +152,19 @@ class SearchProviderTest extends TestCase
$response = $this->search->getSearchResults('@unknow domain');
//$this->markTestSkipped();
}
public function testSearchResultDomainSearch()
{
//add a search service which will be supported
$this->addSearchService(
$this->createNonDefaultDomainSearchService("I am domain foo", 100, TRUE), 'foo'
);
$response = $this->search->getSearchResults('@foo default search');
$this->assertEquals(array(
"I am domain foo"
), $response);
}
public function testSearchWithinSpecificSearchName()
{
//add a search service which will be supported
$this->addSearchService(
$this->createNonDefaultDomainSearchService("I am domain foo", 100, TRUE), 'foo'
);
$this->createNonDefaultDomainSearchService('I am domain foo', 100, true),
'foo'
);
$response = $this->search->getResultByName('@foo search', 'foo');
$this->assertEquals('I am domain foo', $response);
}
/**
@@ -236,52 +173,94 @@ class SearchProviderTest extends TestCase
public function testSearchWithinSpecificSearchNameInConflictWithSupport()
{
$response = $this->search->getResultByName('@foo default search', 'bar');
}
/**
* shortcut for executing parse method
*
* @param unknown $pattern
* @return string[]
*/
private function p($pattern)
public function testSimplePattern()
{
return $this->search->parse($pattern);
$terms = $this->p('@person birthdate:2014-01-02 name:"my name" is not my name');
$this->assertEquals([
'_domain' => 'person',
'birthdate' => '2014-01-02',
'_default' => 'is not my name',
'name' => 'my name',
], $terms);
}
public function testTrimInDefault()
{
$terms = $this->p(' foo bar ');
$this->assertEquals([
'_domain' => null,
'_default' => 'foo bar',
], $terms);
}
public function testTrimInParenthesis()
{
$terms = $this->p('foo:"bar "');
$this->assertEquals([
'_domain' => null,
'foo' => 'bar',
'_default' => '',
], $terms);
}
public function testWithoutDefault()
{
$terms = $this->p('@person foo:bar');
$this->assertEquals([
'_domain' => 'person',
'foo' => 'bar',
'_default' => '',
], $terms);
}
public function testWithoutDomain()
{
$terms = $this->p('foo:bar residual');
$this->assertEquals([
'_domain' => null,
'foo' => 'bar',
'_default' => 'residual',
], $terms);
}
/**
* Add a search service to the chill.main.search_provider
* Add a search service to the chill.main.search_provider.
*
* Useful for mocking the SearchInterface
*
* @param SearchInterface $search
* @param string $name
*/
private function addSearchService(SearchInterface $search, $name)
private function addSearchService(SearchInterface $search, $name)
{
$this->search
->addSearchService($search, $name);
->addSearchService($search, $name);
}
private function createDefaultSearchService($result, $order)
{
$mock = $this
->getMockForAbstractClass('Chill\MainBundle\Search\AbstractSearch');
->getMockForAbstractClass('Chill\MainBundle\Search\AbstractSearch');
//set the mock as default
$mock->expects($this->any())
->method('isActiveByDefault')
->will($this->returnValue(TRUE));
->method('isActiveByDefault')
->will($this->returnValue(true));
$mock->expects($this->any())
->method('getOrder')
->will($this->returnValue($order));
->method('getOrder')
->will($this->returnValue($order));
//set the return value
$mock->expects($this->any())
->method('renderResult')
->will($this->returnValue($result));
->method('renderResult')
->will($this->returnValue($result));
return $mock;
}
@@ -289,26 +268,38 @@ class SearchProviderTest extends TestCase
private function createNonDefaultDomainSearchService($result, $order, $domain)
{
$mock = $this
->getMockForAbstractClass('Chill\MainBundle\Search\AbstractSearch');
->getMockForAbstractClass('Chill\MainBundle\Search\AbstractSearch');
//set the mock as default
$mock->expects($this->any())
->method('isActiveByDefault')
->will($this->returnValue(FALSE));
->method('isActiveByDefault')
->will($this->returnValue(false));
$mock->expects($this->any())
->method('getOrder')
->will($this->returnValue($order));
->method('getOrder')
->will($this->returnValue($order));
$mock->expects($this->any())
->method('supports')
->will($this->returnValue($domain));
->method('supports')
->will($this->returnValue($domain));
//set the return value
$mock->expects($this->any())
->method('renderResult')
->will($this->returnValue($result));
->method('renderResult')
->will($this->returnValue($result));
return $mock;
}
/**
* shortcut for executing parse method.
*
* @param unknown $pattern
*
* @return string[]
*/
private function p($pattern)
{
return $this->search->parse($pattern);
}
}

View File

@@ -1,12 +1,41 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Search\Utils;
use Chill\MainBundle\Search\Utils\ExtractDateFromPattern;
use DateTimeImmutable;
use PHPUnit\Framework\TestCase;
use function array_map;
/**
* @internal
* @coversNothing
*/
class ExtractDateFromPatternTest extends TestCase
{
public function provideSubjects()
{
yield ['15/06/1981', '', 1, '1981-06-15'];
yield ['15/06/1981 30/12/1987', '', 2, '1981-06-15', '1987-12-30'];
yield ['diallo 15/06/1981', 'diallo', 1, '1981-06-15'];
yield ['diallo 31/03/1981', 'diallo', 1, '1981-03-31'];
yield ['diallo 15-06-1981', 'diallo', 1, '1981-06-15'];
yield ['diallo 1981-12-08', 'diallo', 1, '1981-12-08'];
yield ['diallo', 'diallo', 0];
}
/**
* @dataProvider provideSubjects
@@ -18,28 +47,17 @@ class ExtractDateFromPatternTest extends TestCase
$this->assertCount($count, $result->getFound());
$this->assertEquals($filtered, $result->getFilteredSubject());
$this->assertContainsOnlyInstancesOf(\DateTimeImmutable::class, $result->getFound());
$this->assertContainsOnlyInstancesOf(DateTimeImmutable::class, $result->getFound());
$dates = \array_map(
function (\DateTimeImmutable $d) {
$dates = array_map(
function (DateTimeImmutable $d) {
return $d->format('Y-m-d');
}, $result->getFound()
},
$result->getFound()
);
foreach ($datesSearched as $date) {
$this->assertContains($date, $dates);
}
}
public function provideSubjects()
{
yield ["15/06/1981", "", 1, '1981-06-15'];
yield ["15/06/1981 30/12/1987", "", 2, '1981-06-15', '1987-12-30'];
yield ["diallo 15/06/1981", "diallo", 1, '1981-06-15'];
yield ["diallo 31/03/1981", "diallo", 1, '1981-03-31'];
yield ["diallo 15-06-1981", "diallo", 1, '1981-06-15'];
yield ["diallo 1981-12-08", "diallo", 1, '1981-12-08'];
yield ["diallo", "diallo", 0];
}
}

View File

@@ -1,14 +1,46 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Search\Utils;
use Chill\MainBundle\Search\Utils\ExtractPhonenumberFromPattern;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
/**
* @internal
* @coversNothing
*/
class ExtractPhonenumberFromPatternTest extends KernelTestCase
{
public function provideData()
{
yield ['Diallo', 0, [], 'Diallo', 'no phonenumber'];
yield ['Diallo 15/06/2021', 0, [], 'Diallo 15/06/2021', 'no phonenumber and a date'];
yield ['Diallo 0486 123 456', 1, ['+32486123456'], 'Diallo', 'a phonenumber and a name'];
yield ['Diallo 123 456', 1, ['123456'], 'Diallo', 'a number and a name, without leadiing 0'];
yield ['123 456', 1, ['123456'], '', 'only phonenumber'];
yield ['0123 456', 1, ['+32123456'], '', 'only phonenumber with a leading 0'];
}
/**
* @dataProvider provideData
*
* @param mixed $subject
* @param mixed $expectedCount
* @param mixed $expected
* @param mixed $filteredSubject
* @param mixed $msg
*/
public function testExtract($subject, $expectedCount, $expected, $filteredSubject, $msg)
{
@@ -19,15 +51,4 @@ class ExtractPhonenumberFromPatternTest extends KernelTestCase
$this->assertEquals($filteredSubject, $result->getFilteredSubject());
$this->assertEquals($expected, $result->getFound());
}
public function provideData()
{
yield ['Diallo', 0, [], 'Diallo', "no phonenumber"];
yield ['Diallo 15/06/2021', 0, [], 'Diallo 15/06/2021', "no phonenumber and a date"];
yield ['Diallo 0486 123 456', 1, ['+32486123456'], 'Diallo', "a phonenumber and a name"];
yield ['Diallo 123 456', 1, ['123456'], 'Diallo', "a number and a name, without leadiing 0"];
yield ['123 456', 1, ['123456'], '', "only phonenumber"];
yield ['0123 456', 1, ['+32123456'], '', "only phonenumber with a leading 0"];
}
}