chill-bundles/src/Bundle/ChillMainBundle/Test/PrepareCenterTrait.php
Julien Fastré 0081146a78
Change non-static class-level variables and methods to static in tests's data providers
The update modifies several test classes within the "chill-project" to change non-static class-level variables and methods to static ones. This change has been made to improve readability, performance, and to eliminate unnecessary instantiation of class objects in test scenarios. Also, flush and clear actions on the entity manager are moved to individual data providers.
2024-02-19 15:38:28 +01:00

44 lines
977 B
PHP

<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Test;
use Chill\MainBundle\Entity\Center;
/**
* A trait to prepare center.
*
* **Usage :** You must set up trait with `setUpTrait` before use
* and use tearDownTrait after usage.
*
* @codeCoverageIgnore
*/
trait PrepareCenterTrait
{
private $centerProphet;
/**
* prepare a mocked center, with and id and name given.
*/
protected static function prepareCenter(int $id, string $name): Center
{
$center = new Center();
$center->setName($name);
$reflectionClass = new \ReflectionClass($center);
$reflectionId = $reflectionClass->getProperty('id');
$reflectionId->setAccessible(true);
$reflectionId->setValue($center, $id);
return $center;
}
}