Skip to content
This repository has been archived by the owner on Aug 9, 2022. It is now read-only.

Commit

Permalink
#2 Add ParameterManager service
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieu-ducrot committed Jul 1, 2021
1 parent d17823e commit 20ab986
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 1 deletion.
10 changes: 10 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@ services:
Smart\ParameterBundle\Provider\ParameterProvider:
public: false
alias: smart_parameter.parameter_provider

smart_parameter.parameter_manager:
class: Smart\ParameterBundle\Manager\ParameterManager
public: true
arguments:
- '@Doctrine\ORM\EntityManagerInterface'

Smart\ParameterBundle\Manager\ParameterManager:
public: false
alias: smart_parameter.parameter_manager
28 changes: 28 additions & 0 deletions src/Manager/ParameterManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Smart\ParameterBundle\Manager;

use Doctrine\ORM\EntityManagerInterface;
use Smart\ParameterBundle\Entity\Parameter;

/**
* @author Mathieu Ducrot <[email protected]>
*/
class ParameterManager
{
private EntityManagerInterface $entityManager;

public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}

/**
* Create the Parameter
*/
public function create(Parameter $parameter): void
{
$this->entityManager->persist($parameter);
$this->entityManager->flush();
}
}
3 changes: 3 additions & 0 deletions tests/AbstractWebTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public function setUp(): void
parent::setUp();

self::bootKernel();

// Empty load to guarantee that the base will always be available
$this->loadFixtureFiles([]);
}

protected function getFixtureDir(): string
Expand Down
40 changes: 40 additions & 0 deletions tests/Manager/ParameterManagerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Smart\ParameterBundle\Tests\Manager;

use Doctrine\ORM\EntityManagerInterface;
use Smart\ParameterBundle\Entity\Parameter;
use Smart\ParameterBundle\Manager\ParameterManager;
use Smart\ParameterBundle\Tests\AbstractWebTestCase;

/**
* @author Mathieu Ducrot <[email protected]>
*
* vendor/bin/phpunit tests/Manager/ParameterManagerTest.php
*/
class ParameterManagerTest extends AbstractWebTestCase
{
private ?ParameterManager $parameterManager;
private ?EntityManagerInterface $entityManager;

public function setUp(): void
{
parent::setUp();

$container = self::$container;
$this->parameterManager = $container->get(ParameterManager::class);
$this->entityManager = $container->get(EntityManagerInterface::class);
}

public function testCrate(): void
{
$parameter = new Parameter();
$parameter->setCode('test');
$parameter->setValue('value');

$repository = $this->entityManager->getRepository(Parameter::class);
$nbParameter = $repository->count([]);
$this->parameterManager->create($parameter);
$this->assertSame($nbParameter + 1, $repository->count([]));
}
}
1 change: 0 additions & 1 deletion tests/Provider/ParameterProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public function testGetNotFoundException(): void
$this->expectException(EntityNotFoundException::class);
$this->expectExceptionMessage('The parameter with code "not_found" was not found.');

$this->loadFixtureFiles([]);
$this->provider->getValue("not_found");
}

Expand Down

0 comments on commit 20ab986

Please sign in to comment.