added tags for timesheets (#604)
This commit is contained in:
68
tests/DataFixtures/TagFixtures.php
Normal file
68
tests/DataFixtures/TagFixtures.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\DataFixtures;
|
||||
|
||||
use App\Entity\Tag;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
|
||||
/**
|
||||
* Defines the sample data to load in during controller tests.
|
||||
*/
|
||||
class TagFixtures extends Fixture
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $tagArray = [];
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getTagArray()
|
||||
{
|
||||
return $this->tagArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $tagArray
|
||||
* @return TagFixtures
|
||||
*/
|
||||
public function setTagArray(array $tagArray)
|
||||
{
|
||||
$this->tagArray = $tagArray;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
foreach ($this->getTagArray() as $tagName) {
|
||||
$entry = $this->createTagEntry($tagName);
|
||||
$manager->persist($entry);
|
||||
}
|
||||
$manager->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $tagName
|
||||
* @return Tag
|
||||
*/
|
||||
protected function createTagEntry($tagName)
|
||||
{
|
||||
$tagObject = new Tag();
|
||||
$tagObject->setName($tagName);
|
||||
|
||||
return $tagObject;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user