Skip to content

Commit

Permalink
Changed required in PR
Browse files Browse the repository at this point in the history
  • Loading branch information
alecszaharia committed Apr 5, 2021
1 parent ef5f4da commit c381c4d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 25 deletions.
15 changes: 2 additions & 13 deletions lib/Doctrine/ORM/Query/Filter/SQLFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,24 +124,13 @@ final public function hasParameter($name)
}

/**
* Return a unique hash base on filter class and his parametters
* Return a unique hash base on filter class and his parameters
*
* @return string
*/
final public function getHash()
{
$parameterCount = count($this->parameters);
$hash = get_class($this).$parameterCount;
foreach ($this->parameters as $name => $param) {
if (is_object($param['value'])) {
$valueHash = spl_object_hash($param['value']);
} else {
$valueHash = $param['value'];
}
$hash .= $name.$param['type'].$valueHash;
}

return $hash;
return self::class.$this;
}

/**
Expand Down
17 changes: 8 additions & 9 deletions tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,27 +223,25 @@ public function testEntityManagerIsFilterEnabled(): void

public function testGetHash() : void
{
$em = $this->getEntityManager();
$em = $this->_getEntityManager();
$this->configureFilters($em);

// Check the filter hash without parameters
$em->getFilters()->enable("locale");
$filter = $em->getFilters()->getFilter("locale");
self::assertEquals('Doctrine\Tests\ORM\Functional\MyLocaleFilter0',$filter->getHash());
self::assertEquals('Doctrine\ORM\Query\Filter\SQLFiltera:0:{}',$filter->getHash());

// Check the filter hash with one parameters
$filter->setParameter('test','string');
self::assertEquals('Doctrine\Tests\ORM\Functional\MyLocaleFilter1test2string',$filter->getHash());
self::assertEquals('Doctrine\ORM\Query\Filter\SQLFiltera:1:{s:4:"test";a:2:{s:5:"value";s:6:"string";s:4:"type";i:2;}}',$filter->getHash());

// Check the filter hash with two parameters
$filter->setParameter('test2','string2');
self::assertEquals('Doctrine\Tests\ORM\Functional\MyLocaleFilter2test2stringtest22string2',$filter->getHash());
self::assertEquals('Doctrine\ORM\Query\Filter\SQLFiltera:2:{s:4:"test";a:2:{s:5:"value";s:6:"string";s:4:"type";i:2;}s:5:"test2";a:2:{s:5:"value";s:7:"string2";s:4:"type";i:2;}}',$filter->getHash());

// Check the filter hash with three parameters one being an object
$stdClass = new \stdClass();
$splHash = spl_object_hash($stdClass);
$filter->setParameter('test3', $stdClass);
self::assertEquals('Doctrine\Tests\ORM\Functional\MyLocaleFilter3test2stringtest22string2test32'.$splHash,$filter->getHash());
// Check the filter hash with an object parameters
$filter->setParameter('test3',(object)['p'=>1]);
self::assertEquals('Doctrine\ORM\Query\Filter\SQLFiltera:3:{s:4:"test";a:2:{s:5:"value";s:6:"string";s:4:"type";i:2;}s:5:"test2";a:2:{s:5:"value";s:7:"string2";s:4:"type";i:2;}s:5:"test3";a:2:{s:5:"value";O:8:"stdClass":1:{s:1:"p";i:1;}s:4:"type";i:2;}}',$filter->getHash());
}


Expand Down Expand Up @@ -302,6 +300,7 @@ public function testSQLFilterGetSetParameter(): void
$filter = new MyLocaleFilter($em);

$filter->setParameter('locale', 'en', DBALType::STRING);

$this->assertEquals("'en'", $filter->getParameter('locale'));
}

Expand Down
6 changes: 3 additions & 3 deletions tests/Doctrine/Tests/ORM/Query/FilterCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ public function testGetHash()
{
$filterCollection = $this->em->getFilters();
$filterCollection->enable('testFilter');
$filterCollection->getFilter('testFilter');
$filterCollection->setParameter('test','string');
$filter = $filterCollection->getFilter('testFilter');
$filter->setParameter('test','string');
$hash = $filterCollection->getHash();

$this->assertEquals("testFilterDoctrine\Tests\ORM\Query\MyFilter1test2string",$hash);
$this->assertEquals('testFilterDoctrine\ORM\Query\Filter\SQLFiltera:1:{s:4:"test";a:2:{s:5:"value";s:6:"string";s:4:"type";i:2;}}',$hash);
}
}

Expand Down

0 comments on commit c381c4d

Please sign in to comment.