mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-15 09:30:58 +00:00
[Behat] Fixed bugs revealed by faster tests and production-like environment
This commit is contained in:
parent
2d77727453
commit
a5d7e3a6bb
3 changed files with 29 additions and 18 deletions
|
|
@ -475,7 +475,7 @@ abstract class DefaultContext extends RawMinkContext implements Context, KernelA
|
|||
for ($i = 0; $i < $limit; ++$i) {
|
||||
$payload = $callback();
|
||||
|
||||
if (false !== $payload && null !== $payload) {
|
||||
if (!empty($payload)) {
|
||||
return $payload;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -78,7 +78,11 @@ class FixtureContext extends DefaultContext
|
|||
$type = str_replace(' ', '_', trim($type));
|
||||
|
||||
$object = $this->waitFor(function () use ($type, $data) {
|
||||
return $this->findOneByName($type, $data['name']);
|
||||
try {
|
||||
return $this->findOneByName($type, $data['name']);
|
||||
} catch (\InvalidArgumentException $exception) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
foreach ($data as $property => $value) {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
namespace Sylius\Bundle\SearchBundle\Behat;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Sylius\Bundle\ResourceBundle\Behat\DefaultContext;
|
||||
use Sylius\Bundle\SearchBundle\Command\IndexCommand;
|
||||
use Symfony\Component\Console\Input\ArgvInput;
|
||||
|
|
@ -53,22 +54,26 @@ class SearchContext extends DefaultContext
|
|||
/**
|
||||
* @Given /^I should find an indexed entry for "([^""]*)"$/
|
||||
*/
|
||||
public function iCreateAndIndex($id)
|
||||
public function iShouldFindAnIndexedEntry($id)
|
||||
{
|
||||
/** @var EntityManagerInterface $em */
|
||||
$em = $this->getContainer()->get('doctrine')->getManager();
|
||||
|
||||
$queryBuilder = $em->createQueryBuilder();
|
||||
$queryBuilder
|
||||
$query = $queryBuilder
|
||||
->select('u')
|
||||
->from('Sylius\Bundle\SearchBundle\Model\SearchIndex', 'u')
|
||||
->where('u.value LIKE :id')
|
||||
->setParameter('id', '%'.$id.'%')
|
||||
->getQuery()
|
||||
;
|
||||
|
||||
$result = $queryBuilder->getQuery()->getResult();
|
||||
if (!$result) {
|
||||
throw new \Exception(
|
||||
"The entry does not exist in the index"
|
||||
);
|
||||
$result = $this->waitFor(function () use ($query) {
|
||||
return $query->getResult();
|
||||
});
|
||||
|
||||
if (empty($result)) {
|
||||
throw new \Exception("The entry does not exist in the index");
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
@ -77,24 +82,26 @@ class SearchContext extends DefaultContext
|
|||
/**
|
||||
* @Given /^I should not find an indexed entry for "([^""]*)"$/
|
||||
*/
|
||||
public function iDeleteAnIndex($id)
|
||||
public function iShouldNotFindAnIndexedEntry($id)
|
||||
{
|
||||
/** @var EntityManagerInterface $em */
|
||||
$em = $this->getContainer()->get('doctrine')->getManager();
|
||||
|
||||
$queryBuilder = $em->createQueryBuilder();
|
||||
$queryBuilder
|
||||
$query = $queryBuilder
|
||||
->select('u')
|
||||
->from('Sylius\Bundle\SearchBundle\Model\SearchIndex', 'u')
|
||||
->where('u.value LIKE :id')
|
||||
->setParameter('id', '%'.$id.'%')
|
||||
->getQuery()
|
||||
;
|
||||
|
||||
$result = $queryBuilder->getQuery()->getResult();
|
||||
if (!empty($result)) {
|
||||
throw new \Exception(
|
||||
"The entry does exist in the index"
|
||||
);
|
||||
try {
|
||||
$this->waitFor(function () use ($query) {
|
||||
return 0 === count($query->getResult()) ? true : false;
|
||||
});
|
||||
} catch (\RuntimeException $exception) {
|
||||
throw new \Exception("The entry does exist in the index", 0, $exception);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue