Skip to content

Commit

Permalink
fix space chars in request
Browse files Browse the repository at this point in the history
  • Loading branch information
clementtalleu committed Jul 2, 2024
1 parent 23ed17b commit bda2526
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Om/Repository/AbstractObjectRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ protected function convertSpecial(array|string &$criteria): void
}

$criteria[$property] = str_replace([':'], ['\:'], $value);
$criteria[$property] = str_replace([' '], ['\ '], $criteria[$property]);
}
}

Expand Down
15 changes: 15 additions & 0 deletions tests/Fixtures/Hash/DummyHashWithSpaceChars.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Talleu\RedisOm\Tests\Fixtures\Hash;

use Talleu\RedisOm\Om\Mapping as RedisOm;
use Talleu\RedisOm\Tests\Fixtures\AbstractDummy;

#[RedisOm\Entity]
class DummyHashWithSpaceChars extends AbstractDummy
{
#[RedisOm\Property(index: true)]
public ?string $spaceChars = 'With space';
}
2 changes: 1 addition & 1 deletion tests/Fixtures/Json/DummyJsonWithSpaceChars.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
class DummyJsonWithSpaceChars extends AbstractDummy
{
#[RedisOm\Property(index: true)]
public ?string $spaceChars = 'null';
public ?string $spaceChars = 'With space';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace Talleu\RedisOm\Tests\Functionnal\Om\Repository\HashModel;

use Talleu\RedisOm\Om\RedisObjectManager;
use Talleu\RedisOm\Tests\Fixtures\Hash\DummyHashWithSpaceChars;
use Talleu\RedisOm\Tests\RedisAbstractTestCase;

final class HashSpaceCharsRepositoryTest extends RedisAbstractTestCase
{
public function testFindOneBySpace()
{
static::emptyRedis();
static::generateIndex();
static::loadRedisFixtures(DummyHashWithSpaceChars::class);

$objectManager = new RedisObjectManager();
$repository = $objectManager->getRepository(DummyHashWithSpaceChars::class);

// Update 1 object to set unknown to not null
/** @var DummyHashWithSpaceChars $object */
$object = $repository->findOneBy(['spaceChars' => 'With space']);
$this->assertEquals($object->spaceChars, 'With space');
}

public function testFindBySpace()
{
static::emptyRedis();
static::generateIndex();
static::loadRedisFixtures(DummyHashWithSpaceChars::class);

$objectManager = new RedisObjectManager();
$repository = $objectManager->getRepository(DummyHashWithSpaceChars::class);

// Update 1 object to set unknown to not null
/** @var DummyHashWithSpaceChars[] $collection */
$collection = $repository->findBy(['spaceChars' => 'With space']);
foreach ($collection as $object){
$this->assertEquals($object->spaceChars, 'With space');
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace Talleu\RedisOm\Tests\Functionnal\Om\Repository\JsonModel;

use Talleu\RedisOm\Om\RedisObjectManager;
use Talleu\RedisOm\Tests\Fixtures\Json\DummyJsonWithSpaceChars;
use Talleu\RedisOm\Tests\RedisAbstractTestCase;

final class JsonSpaceCharsRepositoryTest extends RedisAbstractTestCase
{
public function testFindOneBySpace()
{
static::emptyRedis();
static::generateIndex();
static::loadRedisFixtures(DummyJsonWithSpaceChars::class);

$objectManager = new RedisObjectManager();
$repository = $objectManager->getRepository(DummyJsonWithSpaceChars::class);

// Update 1 object to set unknown to not null
/** @var DummyJsonWithSpaceChars $object */
$object = $repository->findOneBy(['spaceChars' => 'With space']);
$this->assertEquals($object->spaceChars, 'With space');
}

public function testFindBySpace()
{
static::emptyRedis();
static::generateIndex();
static::loadRedisFixtures(DummyJsonWithSpaceChars::class);

$objectManager = new RedisObjectManager();
$repository = $objectManager->getRepository(DummyJsonWithSpaceChars::class);

// Update 1 object to set unknown to not null
/** @var DummyJsonWithSpaceChars[] $collection */
$collection = $repository->findBy(['spaceChars' => 'With space']);
foreach ($collection as $object){
$this->assertEquals($object->spaceChars, 'With space');
}
}
}

0 comments on commit bda2526

Please sign in to comment.