Function remove on fixture manager does not delete all the fixtures in a db
Opened this issue · 0 comments
rmasclef commented
Hello,
I am trying to load and remove some dataFixtures ...
The fixtures are correctly loaded but are never removed (remove function called in tearDown or tearDownAfterClass function does not seem to work well).
the remove is OK at the end of the last test, but KO after the first one.
I made a little example as you can see the issue by yourself:
The result:
$ phpunit -c app/
PHPUnit 4.8.16 by Sebastian Bergmann and contributors.
Eadd new entries
string(25) "SET_UP : nb_chronos = 2
"
string(39) "TEST_1 : nb_chronos before delete = 2
"
string(38) "TEST_1 : nb_chronos after delete = 1
"
string(22) "====================
"
delete entries
.add new entries
string(25) "SET_UP : nb_chronos = 3
"
string(25) "TEST_2 : nb_chronos = 3
"
delete entries
string(28) "TEAR_DOWN : nb_chronos = 1
"
Time: 1.16 seconds, Memory: 14.00Mb
The config_test.yml:
imports:
- { resource: config_dev.yml }
framework:
test: ~
session:
storage_id: session.storage.mock_file
profiler:
collect: false
web_profiler:
toolbar: false
intercept_redirects: false
swiftmailer:
disable_delivery: true
doctrine:
dbal:
driver: pdo_sqlite
user: test
path: %kernel.cache_dir%/sqlite.db
#memory: true
charset: utf8
h4cc_alice_fixtures:
locale: fr_FR #usefull to generate french fixtures like a french phoneNumber
The Test class:
<?php
namespace Chronos\RestBundle\Tests\Controller;
use h4cc\AliceFixturesBundle\Fixtures\FixtureManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
/**
* Class ChronosControllerTest
* @package Chronos\RestBundle\Tests\Controller
*/
class ChronosControllerTest extends WebTestCase
{
/**
* @var array
*/
private static $fixtures;
/**
* @var FixtureManagerInterface
*/
private static $fixturesManager;
/**
* Loadin�g the fixtures at every Tests
*/
public function setUp()
{
echo "add new entries".PHP_EOL;
$client = static::createClient();
static::$fixturesManager = $client->getContainer()->get('h4cc_alice_fixtures.manager');
static::$fixtures = static::$fixturesManager->loadFiles(
array(__DIR__ . '/../DataFixtures/chronos.yml')
);
static::$fixturesManager->persist(static::$fixtures);
$repo = $client
->getContainer()
->get('doctrine')
->getRepository('ChronosRestBundle:Chronos');
$chronos = $repo->findAll();
var_dump("SET_UP : nb_chronos = ".count($chronos).PHP_EOL);
}
/**
* Remove fixtures after every single test.
*/
public function tearDown()
{
echo "delete entries".PHP_EOL;
$client = static::createClient();
static::$fixturesManager = $client->getContainer()->get('h4cc_alice_fixtures.manager');
static::$fixturesManager->remove(static::$fixtures);
$repo = $client
->getContainer()
->get('doctrine')
->getRepository('ChronosRestBundle:Chronos');
$chronos = $repo->findAll();
var_dump("TEAR_DOWN : nb_chronos = ".count($chronos).PHP_EOL);
}
public function testAddAction()
{
$client = static::createClient();
//get a chronosController
$chronosController = $client->getContainer()->get('chronos.chronos_controller');
// $chronosController->addAction();
$repo = $client
->getContainer()
->get('doctrine')
->getRepository('ChronosRestBundle:Chronos');
$chronos = $repo->findAll();
var_dump("TEST_1 : nb_chronos before delete = ".count($chronos).PHP_EOL);
$em = $client
->getContainer()
->get('doctrine.orm.entity_manager');
$em->remove($chronos[0]);
$em->flush();
$chronos = $repo->findAll();
var_dump("TEST_1 : nb_chronos after delete = ".count($chronos).PHP_EOL);
var_dump("====================".PHP_EOL);
}
public function testEditAction() {
$client = static::createClient();
//get a chronosController
$chronosController = $client->getContainer()->get('chronos.chronos_controller');
// $chronosController->addAction();
$repo = $client
->getContainer()
->get('doctrine')
->getRepository('ChronosRestBundle:Chronos');
$chronos = $repo->findAll();
var_dump("TEST_2 : nb_chronos = ".count($chronos).PHP_EOL);
}
}
The fixtures:
Chronos\RestBundle\Entity\Chronos:
chronos_1:
id: 1
priority: 1
callDestination: 12548
channel: "welcome"
clientPhoneNumber: 0612348598
active: 1
inactiveCause: ""
additionalInformations: ""
recallDate: <dateTimeBetween('now', '+5 days')>
createdAt: <dateTimeBetween('-1 days', 'now')>
updatedAt: <dateTimeBetween($createdAt, 'now')>
preTreatmentSmsDate: null
postTreatmentSmsDate: null
callDestinationType: "agent"
chronos_inactive:
id: 2
priority: 3
callDestination: 12549
channel: "nordnet.fr"
clientPhoneNumber: 0682348654
active: 0
inactiveCause: "nothing to say"
additionalInformations: ""
recallDate: <dateTimeBetween('now', '+5 days')>
createdAt: <dateTimeBetween('-1 days', 'now')>
updatedAt: <dateTimeBetween($createdAt, 'now')>
preTreatmentSmsDate: nuu
postTreatmentSmsDate: ""
callDestinationType: "group"
The Entity:
<?php
namespace Chronos\RestBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Chronos\RestBundle\Validator\Constraints as ChronosAssert;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Chronos
*
* @ORM\Table(name="chronos")
* @ORM\Entity(repositoryClass="Chronos\RestBundle\Entity\Repository\ChronosRepository")
* @ChronosAssert\ChronosConstraint()
*/
class Chronos
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var integer
*
* @ORM\Column(name="priority", type="integer")
* @Assert\NotBlank()
* @Assert\Regex("/^([123])$/")
*/
private $priority;
/**
* @var string
*
* @ORM\Column(name="call_destination", type="string", length=255)
* @Assert\NotBlank()
* @Assert\Type("string")
*/
private $callDestination;
/**
* @var string
*
* @ORM\Column(name="channel", type="string", length=255)
* @Assert\NotBlank()
* @Assert\Type("string")
*/
private $channel;
/**
* @var string
*
* @ORM\Column(name="client_phone_number", type="string")
* @Assert\NotBlank()
* @Assert\Type("string")
* @Assert\Regex("/^(0[1-9])(?:[ _.-]?(\d{2})){4}$/")
*/
private $clientPhoneNumber;
/**
* @var boolean
*
* @ORM\Column(name="is_active", type="boolean")
* @Assert\NotBlank()
* @Assert\Type("bool")
*/
private $active;
/**
* @var string
*
* @ORM\Column(name="inactive_cause", type="string", length=255, nullable=true)
* @Assert\Type("string")
*/
private $inactiveCause;
/**
* @var string
*
* @ORM\Column(name="additionnal_informations", type="json_array", nullable=true)
* @Assert\Type("string")
*/
private $additionalInformations;
/**
* @var \DateTime
*
* @ORM\Column(name="recall_date", type="datetime")
* @Assert\NotBlank()
* @Assert\DateTime()
*/
private $recallDate;
/**
* @var \DateTime
*
* @ORM\Column(name="created_at", type="datetime")
* @Gedmo\Timestampable(on="create")
* @Assert\NotBlank()
* @Assert\DateTime()
*/
private $createdAt;
/**
* @var \DateTime
*
* @ORM\Column(name="updated_at", type="datetime", nullable=true)
* @Gedmo\Timestampable(on="update")
* @Assert\DateTime()
*/
private $updatedAt;
/**
* @var \DateTime
*
* @ORM\Column(name="pre_treatment_sms_date", type="datetime", nullable=true)
* @Assert\DateTime()
*/
private $preTreatmentSmsDate;
/**
* @var \DateTime
*
* @ORM\Column(name="post_treatment_sms_date", type="datetime", nullable=true)
* @Assert\DateTime()
*/
private $postTreatmentSmsDate;
/**
* @var string
*
* @ORM\Column(name="call_destination_type", type="string", length=10)
* @Assert\Regex("#group|agent#")
*/
private $callDestinationType;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set priority
*
* @param integer $priority
*
* @return Chronos
*/
public function setPriority($priority)
{
$this->priority = $priority;
return $this;
}
/**
* Get priority
*
* @return integer
*/
public function getPriority()
{
return $this->priority;
}
/**
* Set callDestination
*
* @param string $callDestination
*
* @return Chronos
*/
public function setCallDestination($callDestination)
{
$this->callDestination = $callDestination;
return $this;
}
/**
* Get callDestination
*
* @return string
*/
public function getCallDestination()
{
return $this->callDestination;
}
/**
* Set channel
*
* @param string $channel
*
* @return Chronos
*/
public function setChannel($channel)
{
$this->channel = $channel;
return $this;
}
/**
* Get channel
*
* @return string
*/
public function getChannel()
{
return $this->channel;
}
/**
* Set clientPhoneNumber
*
* @param integer $clientPhoneNumber
*
* @return Chronos
*/
public function setClientPhoneNumber($clientPhoneNumber)
{
$this->clientPhoneNumber = $clientPhoneNumber;
return $this;
}
/**
* Get clientPhoneNumber
*
* @return integer
*/
public function getClientPhoneNumber()
{
return $this->clientPhoneNumber;
}
/**
* Set active�[D�[D�[D�[D�[D�[DisActive
*
* @param boolean $active
*
* @return Chronos
*/
public function setActive($active)
{
$this->active = $active;
return $this;
}
/**
* Get active�[D�[D�[D�[D�[D�[DisActive
*
* @return boolean
*/
public function getActive()
{
return $this->active;
}
/**
* Set inactiveCause
*
* @param string $inactiveCause
*
* @return Chronos
*/
public function setInactiveCause($inactiveCause)
{
$this->inactiveCause = $inactiveCause;
return $this;
}
/**
* Get inactiveCause
*
* @return string
*/
public function getInactiveCause()
{
return $this->inactiveCause;
}
/**
* Set additionalInformations
*
* @param string $additionalInformations
*
* @return Chronos
*/
public function setAdditionalInformations($additionalInformations)
{
$this->additionalInformations = $additionalInformations;
return $this;
}
/**
* Get additionalInformations
*
* @return string
*/
public function getAdditionalInformations()
{
return $this->additionalInformations;
}
/**
* Set recallDate
*
* @param \DateTime $recallDate
*
* @return Chronos
*/
public function setRecallDate($recallDate)
{
$this->recallDate = $recallDate;
return $this;
}
/**
* Get recallDate
*
* @return \DateTime
*/
public function getRecallDate()
{
return $this->recallDate;
}
/**
* Set createdAt
*
* @param \DateTime $createdAt
*
* @return Chronos
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt
*
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set updatedAt
*
* @param \DateTime $updatedAt
*
* @return Chronos
*/
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* Get updatedAt
*
* @return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* Set preTreatmentSmsDate
*
* @param \DateTime $preTreatmentSmsDate
*
* @return Chronos
*/
public function setPreTreatmentSmsDate($preTreatmentSmsDate)
{
$this->preTreatmentSmsDate = $preTreatmentSmsDate;
return $this;
}
/**
* Get preTreatmentSmsDate
*
* @return \DateTime
*/
public function getPreTreatmentSmsDate()
{
return $this->preTreatmentSmsDate;
}
/**
* Set postTreatmentSmsDate
*
* @param \DateTime $postTreatmentSmsDate
*
* @return Chronos
*/
public function setPostTreatmentSmsDate($postTreatmentSmsDate)
{
$this->postTreatmentSmsDate = $postTreatmentSmsDate;
return $this;
}
/**
* Get postTreatmentSmsDate
*
* @return \DateTime
*/
public function getPostTreatmentSmsDate()
{
return $this->postTreatmentSmsDate;
}
/**
* Set callDestinationType
*
* @param string $callDestinationType
*
* @return Chronos
*/
public function setCallDestinationType($callDestinationType)
{
$this->callDestinationType = $callDestinationType;
return $this;
}
/**
* Get callDestinationType
*
* @return string
*/
public function getCallDestinationType()
{
return $this->callDestinationType;
}
}