You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
192 lines
6.6 KiB
192 lines
6.6 KiB
<?= "<?php\n" ?>
|
|
<?php
|
|
function getStaticValue($tipo){
|
|
switch($tipo){
|
|
case 'integer': return 1;break;
|
|
case 'text': return "'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'";break;
|
|
case 'string': return "'Lorem Ipsum'";break;
|
|
case 'boolean': return true;break;
|
|
case 'datetime': return "new \DateTime()"; break;
|
|
case 'array': return "array()"; break;
|
|
default: return "new \\$tipo()";
|
|
}
|
|
}
|
|
function dashesToCamelCase($string, $capitalizeFirstCharacter = false)
|
|
{
|
|
if(strpos($string, '_')!==false){
|
|
$str = str_replace('_', '', ucwords($string, '_'));
|
|
}else{
|
|
$str = str_replace('.', '', ucwords($string, '.'));
|
|
}
|
|
if (!$capitalizeFirstCharacter) {
|
|
$str = lcfirst($str);
|
|
}
|
|
|
|
return $str;
|
|
}
|
|
?>
|
|
namespace <?= $namespace; ?>;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
|
use Doctrine\ORM\Tools\SchemaTool;
|
|
use App\Entity\<?= $originClass ?>;
|
|
<?php
|
|
foreach($classes as $class){?>
|
|
use <?= $class ?>;
|
|
<?php
|
|
}
|
|
foreach($classesArray as $class){?>
|
|
use <?= $class ?>;
|
|
<?php
|
|
}?>
|
|
/**
|
|
* @covers \App\Entity\<?= $originClass ?>
|
|
*/
|
|
class <?= $class_name ?> extends KernelTestCase
|
|
{
|
|
|
|
/**
|
|
* @var Doctrine\ORM\EntityManager
|
|
*/
|
|
protected $entityManager;
|
|
|
|
|
|
public function setUp(): void
|
|
{
|
|
// Boot the AppKernel in the test environment and with the debug.
|
|
self::bootKernel();
|
|
|
|
// Store the container and the entity manager in test case properties
|
|
$this->entityManager = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
|
|
|
|
parent::setUp();
|
|
}
|
|
/**
|
|
<?php foreach($properties as $property){
|
|
if($property=='id') continue;
|
|
if(!empty($classes[$property])) continue;
|
|
if(!empty($classesArray[$property])) continue;
|
|
|
|
?>
|
|
<?php } ?>
|
|
*/
|
|
public function testCreate<?= $class_name ?>()
|
|
{<?php
|
|
//dependantClasses must be recursive
|
|
foreach($dependantClasses as $class=>$deps){
|
|
$variablename=explode('\\',$class)?>
|
|
$<?= strtolower(end($variablename)) ?>= new \<?= $class ?>();
|
|
<?php
|
|
//Create dependant classes
|
|
foreach($deps['properties'] as $property){
|
|
//Ignore autonumeric
|
|
if($property=='id') continue;
|
|
if(empty($deps['tipos'][$property])) continue;
|
|
if(!empty($deps['clasesArray'][$property])){
|
|
$propertyrep=$property;
|
|
if(substr($property,-2)=='ia'){
|
|
$propertyrep=substr($property,0,-2).'ium';
|
|
}
|
|
?>
|
|
$<?= strtolower(end($variablename)) ?>->add<?= dashesToCamelCase($propertyrep,true) ?>(<?= getStaticValue(($deps['tipos'][$property])?$deps['tipos'][$property]:null)?>);
|
|
<?php
|
|
}else{
|
|
?>
|
|
$<?= strtolower(end($variablename)) ?>->set<?= dashesToCamelCase($property,true) ?>(<?= getStaticValue(($deps['tipos'][$property])?$deps['tipos'][$property]:null)?>);
|
|
<?php }
|
|
} ?>
|
|
$this->entityManager->persist($<?= strtolower(end($variablename)) ?>);
|
|
<?php }?>
|
|
$class= new <?= $originClass ?>();
|
|
<?php
|
|
//Create dependant classes
|
|
foreach($properties as $property){
|
|
//Ignore autonumeric
|
|
if($property=='id') continue;
|
|
if(empty($types[$property])) continue;
|
|
if(!empty($classesArray[$property])){
|
|
$propertyrep=$property;
|
|
if(substr($property,-2)=='ia'){
|
|
$propertyrep=substr($property,0,-2).'ium';
|
|
}
|
|
$varname=explode('\\', $types[$property]);
|
|
?>
|
|
$class->add<?= dashesToCamelCase($propertyrep,true) ?>($<?= ($types[$property])? strtolower(end($varname)) :null ?>);
|
|
<?php
|
|
}else{
|
|
?>
|
|
$class->set<?= dashesToCamelCase($property,true) ?>(<?= getStaticValue(($types[$property])?$types[$property]:null)?>);
|
|
<?php }
|
|
} ?>
|
|
$this->entityManager->persist($class);
|
|
$this->entityManager->flush();
|
|
$this->assertIsInt($class->getId());
|
|
return $class->getId();
|
|
}
|
|
/**
|
|
* @depends testCreate<?= $class_name ?>
|
|
<?php foreach($properties as $property){
|
|
if($property=='id') continue;
|
|
if(!empty($classes[$property])) continue;
|
|
if(!empty($classesArray[$property])) continue;
|
|
?>
|
|
<?php } ?>
|
|
*/
|
|
public function testRead<?= $class_name ?>($id)
|
|
{
|
|
$class=$this->entityManager->getRepository('App:<?= $originClass ?>')
|
|
->findOneById($id);
|
|
$this->assertIsObject($class);
|
|
return $class;
|
|
}
|
|
/**
|
|
* @depends testRead<?= $class_name ?>
|
|
<?php foreach($properties as $property){
|
|
if($property=='id') continue;
|
|
if(!empty($classes[$property])) continue;
|
|
if(!empty($classesArray[$property])) continue;
|
|
|
|
?>
|
|
<?php } ?>
|
|
*/
|
|
public function testUpdate<?= $class_name ?>($class)
|
|
{
|
|
<?php
|
|
foreach($properties as $property) {
|
|
//Ignore autonumeric
|
|
if ($property == 'id') continue;
|
|
if (empty($types[$property])) continue;
|
|
if (!empty($classesArray[$property])) {
|
|
$propertyrep = $property;
|
|
if (substr($property, -2) == 'ia') {
|
|
$propertyrep = substr($property, 0, -2) . 'ium';
|
|
}
|
|
?>
|
|
$class->add<?= ucfirst($propertyrep) ?>(<?= getStaticValue(($types[$property]) ? $types[$property] : null) ?>);
|
|
<?php
|
|
} else {
|
|
?>
|
|
$class->set<?= ucfirst($property) ?>(<?= getStaticValue(($types[$property]) ? $types[$property] : null) ?>);
|
|
<?php
|
|
}
|
|
}?>
|
|
$this->entityManager->persist($class);
|
|
$this->entityManager->flush();
|
|
$this->assertIsInt($class->getId());
|
|
return $class->getId();
|
|
}
|
|
/**
|
|
* @depends testUpdate<?= $class_name ?>
|
|
*/
|
|
public function testDelete<?= $class_name ?>($id)
|
|
{
|
|
$class = $this->entityManager->getReference('App:<?= $originClass ?>', $id);
|
|
|
|
// Remove it and flush
|
|
$this->entityManager->remove($class);
|
|
$this->entityManager->flush();
|
|
$class= $this->getRepository('App:<?= $originClass ?>')->findOneById($id);
|
|
$this->assetTrue(empty($class));
|
|
}
|
|
|
|
}
|