This repository has been archived by the owner on Aug 3, 2023. It is now read-only.
forked from saidul/DirectBundle
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Unit tests & additions to russian documentation
- Loading branch information
Showing
11 changed files
with
531 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
namespace Ext\DirectBundle\Controller; | ||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
use Ext\DirectBundle\Response\Response; | ||
use Ext\DirectBundle\Response\FormError; | ||
use Ext\DirectBundle\Response\ValidatorError; | ||
use Ext\DirectBundle\Entity\Test; | ||
use Ext\DirectBundle\Form\Type\TestType; | ||
|
||
class ForTestingController extends Controller | ||
{ | ||
|
||
public function testArrayResponseAction($_data) | ||
{ | ||
return $_data; | ||
} | ||
|
||
public function testObjectResponseAction($_data) | ||
{ | ||
return $this->get('ext_direct')->createResponse(new Response(), $_data); | ||
} | ||
|
||
public function testResponseWithConfiguredReaderAction($_data) | ||
{ | ||
return $this->get('ext_direct') | ||
->createResponse(new Response(), $_data) | ||
->setSuccess(true) | ||
->setTotal(100); | ||
} | ||
|
||
public function testFormHandlerResponseAction($_data) | ||
{ | ||
return $this->get('ext_direct') | ||
->createResponse(new Response(), $_data) | ||
->setSuccess(true); | ||
} | ||
|
||
public function testFormValidationResponseAction($_data) | ||
{ | ||
$Entity = new Test(); | ||
|
||
$form = $this->createForm(new TestType(), $Entity); | ||
$_data = array_intersect_key($_data, $form->getChildren()); | ||
$form->bind($_data); | ||
|
||
if($form->isValid()) | ||
{ | ||
return $this->get('ext_direct') | ||
->createResponse(new Response()) | ||
->setSuccess(true); | ||
} else { | ||
return $this->get('ext_direct') | ||
->createResponse(new FormError(), $form); | ||
} | ||
} | ||
|
||
public function testFormEntityValidationResponseAction($_data) | ||
{ | ||
$Entity = new Test(); | ||
|
||
$form = $this->createForm(new TestType(), $Entity); | ||
$_data = array_intersect_key($_data, $form->getChildren()); | ||
$form->bind($_data); | ||
|
||
$errors = $this->get('validator')->validate($Entity); | ||
|
||
if(count($errors) === 0) | ||
{ | ||
return $this->get('ext_direct') | ||
->createResponse(new Response()) | ||
->setSuccess(true); | ||
} else { | ||
return $this->get('ext_direct') | ||
->createResponse(new ValidatorError(), $errors); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Ext\DirectBundle\Entity; | ||
|
||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
class Test | ||
{ | ||
private $id; | ||
|
||
/** | ||
* @Assert\NotBlank() | ||
*/ | ||
private $name; | ||
|
||
/** | ||
* @Assert\NotBlank() | ||
* @Assert\Min(0) | ||
* @Assert\Max(100) | ||
*/ | ||
private $count; | ||
|
||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function setName($name) | ||
{ | ||
$this->name = $name; | ||
} | ||
|
||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function setCount($count) | ||
{ | ||
$this->count = $count; | ||
} | ||
|
||
public function getCount() | ||
{ | ||
return $this->count; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Ext\DirectBundle\Form\Type; | ||
|
||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\FormBuilder; | ||
|
||
class TestType extends AbstractType | ||
{ | ||
|
||
public function buildForm(FormBuilder $builder, array $options) | ||
{ | ||
$builder->add('name'); | ||
$builder->add('count'); | ||
} | ||
|
||
public function getName() | ||
{ | ||
return 'TestType'; | ||
} | ||
|
||
public function getDefaultOptions(array $options) | ||
{ | ||
return array( | ||
'data_class' => 'Ext\DirectBundle\Entity\Test', | ||
'csrf_protection' => false | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
namespace Ext\DirectBundle\Tests; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
use Ext\DirectBundle\Api\Api; | ||
|
||
require_once __DIR__.'../../../../../../app/AppKernel.php'; | ||
|
||
class ControllerTest extends WebTestCase | ||
{ | ||
|
||
protected static $kernel; | ||
protected static $container; | ||
/** | ||
* @var \Doctrine\ORM\EntityManager | ||
*/ | ||
private $em; | ||
|
||
public function __construct() { | ||
self::$kernel = new \AppKernel('test', true); | ||
self::$kernel->boot(); | ||
self::$container = self::$kernel->getContainer(); | ||
$this->em = self::$container ->get('doctrine.orm.entity_manager'); | ||
} | ||
|
||
/** | ||
* Enter description here ... | ||
* @return \Doctrine\ORM\EntityManager | ||
*/ | ||
protected function getEntityManager () | ||
{ | ||
return $this->em; | ||
} | ||
|
||
public function get($serviceId) | ||
{ | ||
return self::$container->get($serviceId); | ||
} | ||
|
||
} |
Oops, something went wrong.