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;
use Chill\ActivityBundle\Export\Aggregator\PersonAggregators\ActivityTypeAggregator;
use Chill\ActivityBundle\Export\Aggregator\ActivityTypeAggregator;
use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
use Doctrine\ORM\EntityManagerInterface;
use Prophecy\PhpUnit\ProphecyTrait;
/**
* Add tests for ActivityTypeAggregator.
@ -22,23 +24,22 @@ use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
*/
final class ActivityTypeAggregatorTest extends AbstractAggregatorTest
{
use ProphecyTrait;
private ActivityTypeAggregator $aggregator;
protected function setUp(): void
{
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');
$container->get('request_stack')
self::$container->get('request_stack')
->push($request->reveal());
}
@ -60,8 +61,7 @@ final class ActivityTypeAggregatorTest extends AbstractAggregatorTest
self::bootKernel();
}
$em = self::$kernel->getContainer()
->get('doctrine.orm.entity_manager');
$em = self::$container->get(EntityManagerInterface::class);
return [
$em->createQueryBuilder()
@ -70,12 +70,7 @@ final class ActivityTypeAggregatorTest extends AbstractAggregatorTest
$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'),
->join('activity.activityType', 'acttype'),
];
}
}

View File

@ -13,6 +13,8 @@ namespace Chill\ActivityBundle\Tests\Export\Aggregator;
use Chill\ActivityBundle\Export\Aggregator\ActivityUserAggregator;
use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
use Doctrine\ORM\EntityManagerInterface;
use Prophecy\PhpUnit\ProphecyTrait;
/**
* Add tests for ActivityUsernAggregator.
@ -22,23 +24,22 @@ use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
*/
final class ActivityUserAggregatorTest extends AbstractAggregatorTest
{
use ProphecyTrait;
private ActivityUserAggregator $aggregator;
protected function setUp(): void
{
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');
$container->get('request_stack')
self::$container->get('request_stack')
->push($request->reveal());
}
@ -47,35 +48,25 @@ final class ActivityUserAggregatorTest extends AbstractAggregatorTest
return $this->aggregator;
}
public function getFormData()
public function getFormData(): array
{
return [
[],
];
}
public function getQueryBuilders()
public function getQueryBuilders(): array
{
if (null === self::$kernel) {
self::bootKernel();
}
$em = self::$kernel->getContainer()
->get('doctrine.orm.entity_manager');
$em = self::$container->get(EntityManagerInterface::class);
return [
$em->createQueryBuilder()
->select('count(activity.id)')
->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'),
];
}
}