repair Activity Aggregator Tests

This commit is contained in:
Mathieu Jaumotte 2022-09-29 19:10:37 +02:00
parent 8d1160d093
commit 2b8fe462ea
2 changed files with 22 additions and 36 deletions

View File

@ -11,8 +11,10 @@ declare(strict_types=1);
namespace Chill\ActivityBundle\Tests\Export\Aggregator; namespace Chill\ActivityBundle\Tests\Export\Aggregator;
use Chill\ActivityBundle\Export\Aggregator\PersonAggregators\ActivityTypeAggregator; use Chill\ActivityBundle\Export\Aggregator\ActivityTypeAggregator;
use Chill\MainBundle\Test\Export\AbstractAggregatorTest; use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
use Doctrine\ORM\EntityManagerInterface;
use Prophecy\PhpUnit\ProphecyTrait;
/** /**
* Add tests for ActivityTypeAggregator. * Add tests for ActivityTypeAggregator.
@ -22,23 +24,22 @@ use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
*/ */
final class ActivityTypeAggregatorTest extends AbstractAggregatorTest final class ActivityTypeAggregatorTest extends AbstractAggregatorTest
{ {
use ProphecyTrait;
private ActivityTypeAggregator $aggregator; private ActivityTypeAggregator $aggregator;
protected function setUp(): void protected function setUp(): void
{ {
self::bootKernel(); self::bootKernel();
$container = self::$kernel->getContainer(); $this->aggregator = self::$container->get('chill.activity.export.type_aggregator');
$this->aggregator = $container->get('chill.activity.export.type_aggregator'); $request = $this->prophesize()
->willExtend(\Symfony\Component\HttpFoundation\Request::class);
// add a fake request with a default locale (used in translatable string)
$prophet = new \Prophecy\Prophet();
$request = $prophet->prophesize();
$request->willExtend(\Symfony\Component\HttpFoundation\Request::class);
$request->getLocale()->willReturn('fr'); $request->getLocale()->willReturn('fr');
$container->get('request_stack') self::$container->get('request_stack')
->push($request->reveal()); ->push($request->reveal());
} }
@ -60,8 +61,7 @@ final class ActivityTypeAggregatorTest extends AbstractAggregatorTest
self::bootKernel(); self::bootKernel();
} }
$em = self::$kernel->getContainer() $em = self::$container->get(EntityManagerInterface::class);
->get('doctrine.orm.entity_manager');
return [ return [
$em->createQueryBuilder() $em->createQueryBuilder()
@ -70,12 +70,7 @@ final class ActivityTypeAggregatorTest extends AbstractAggregatorTest
$em->createQueryBuilder() $em->createQueryBuilder()
->select('count(activity.id)') ->select('count(activity.id)')
->from('ChillActivityBundle:Activity', 'activity') ->from('ChillActivityBundle:Activity', 'activity')
->join('activity.reasons', 'reasons'), ->join('activity.activityType', 'acttype'),
$em->createQueryBuilder()
->select('count(activity.id)')
->from('ChillActivityBundle:Activity', 'activity')
->join('activity.reasons', 'reasons')
->join('reasons.category', 'category'),
]; ];
} }
} }

View File

@ -13,6 +13,8 @@ namespace Chill\ActivityBundle\Tests\Export\Aggregator;
use Chill\ActivityBundle\Export\Aggregator\ActivityUserAggregator; use Chill\ActivityBundle\Export\Aggregator\ActivityUserAggregator;
use Chill\MainBundle\Test\Export\AbstractAggregatorTest; use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
use Doctrine\ORM\EntityManagerInterface;
use Prophecy\PhpUnit\ProphecyTrait;
/** /**
* Add tests for ActivityUsernAggregator. * Add tests for ActivityUsernAggregator.
@ -22,23 +24,22 @@ use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
*/ */
final class ActivityUserAggregatorTest extends AbstractAggregatorTest final class ActivityUserAggregatorTest extends AbstractAggregatorTest
{ {
use ProphecyTrait;
private ActivityUserAggregator $aggregator; private ActivityUserAggregator $aggregator;
protected function setUp(): void protected function setUp(): void
{ {
self::bootKernel(); self::bootKernel();
$container = self::$kernel->getContainer(); $this->aggregator = self::$container->get('chill.activity.export.user_aggregator');
$this->aggregator = $container->get('chill.activity.export.user_aggregator'); $request = $this->prophesize()
->willExtend(\Symfony\Component\HttpFoundation\Request::class);
// add a fake request with a default locale (used in translatable string)
$prophet = new \Prophecy\Prophet();
$request = $prophet->prophesize();
$request->willExtend(\Symfony\Component\HttpFoundation\Request::class);
$request->getLocale()->willReturn('fr'); $request->getLocale()->willReturn('fr');
$container->get('request_stack') self::$container->get('request_stack')
->push($request->reveal()); ->push($request->reveal());
} }
@ -47,35 +48,25 @@ final class ActivityUserAggregatorTest extends AbstractAggregatorTest
return $this->aggregator; return $this->aggregator;
} }
public function getFormData() public function getFormData(): array
{ {
return [ return [
[], [],
]; ];
} }
public function getQueryBuilders() public function getQueryBuilders(): array
{ {
if (null === self::$kernel) { if (null === self::$kernel) {
self::bootKernel(); self::bootKernel();
} }
$em = self::$kernel->getContainer() $em = self::$container->get(EntityManagerInterface::class);
->get('doctrine.orm.entity_manager');
return [ return [
$em->createQueryBuilder() $em->createQueryBuilder()
->select('count(activity.id)') ->select('count(activity.id)')
->from('ChillActivityBundle:Activity', 'activity'), ->from('ChillActivityBundle:Activity', 'activity'),
$em->createQueryBuilder()
->select('count(activity.id)')
->from('ChillActivityBundle:Activity', 'activity')
->join('activity.reasons', 'reasons'),
$em->createQueryBuilder()
->select('count(activity.id)')
->from('ChillActivityBundle:Activity', 'activity')
->join('activity.reasons', 'reasons')
->join('reasons.category', 'category'),
]; ];
} }
} }