-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added validation tests + some ui fix + tweaks
- Loading branch information
Showing
11 changed files
with
349 additions
and
53 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
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,21 @@ | ||
<?php | ||
|
||
namespace Acme\PizzaBundle\Tests\Entity; | ||
|
||
abstract class AbstractEntityTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var \Symfony\Component\Validator\Validator | ||
*/ | ||
static protected $validator; | ||
|
||
public static function setUpBeforeClass() | ||
{ | ||
require_once "{$_SERVER['KERNEL_DIR']}/AppKernel.php"; | ||
|
||
$kernel = new \AppKernel('test', true); | ||
$kernel->boot(); | ||
|
||
self::$validator = $kernel->getContainer()->get('validator'); | ||
} | ||
} |
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,59 @@ | ||
<?php | ||
|
||
namespace Acme\PizzaBundle\Tests\Entity; | ||
|
||
use | ||
Acme\PizzaBundle\Entity\Customer | ||
; | ||
|
||
class CustomerEntityTest extends AbstractEntityTest | ||
{ | ||
public static function provider() | ||
{ | ||
$data = array(); | ||
|
||
$data[] = array( | ||
'properties' => array( | ||
'name' => 'Patricia S. Kemp', | ||
'street' => '3347 Duck Creek Road', | ||
'city' => 'Palo Alto, CA 94306', | ||
'phone' => '650-813-0200', | ||
), | ||
'errors' => array(), | ||
); | ||
|
||
$data[] = array( | ||
'properties' => array(), | ||
'errors' => array( | ||
'name' => 'This value should not be blank', | ||
'street' => 'This value should not be blank', | ||
'city' => 'This value should not be blank', | ||
'phone' => 'This value should not be blank', | ||
), | ||
); | ||
|
||
return $data; | ||
} | ||
|
||
/** | ||
* @dataProvider provider | ||
*/ | ||
public function testValidation(array $properties, array $errors) | ||
{ | ||
$customer = new Customer(); | ||
|
||
foreach ($properties as $property => $value) { | ||
$customer->set($property, $value); | ||
} | ||
|
||
$violations = self::$validator->validate($customer, array('Customer')); | ||
/* @var $violations \Symfony\Component\Validator\ConstraintViolationList */ | ||
|
||
$this->assertEquals(count($errors), count($violations), (string) $violations); | ||
|
||
foreach ($errors as $property => $message) { | ||
$pattern = sprintf('/\.%s:\s+%s$/m', $property, $message); | ||
$this->assertRegExp($pattern, (string) $violations, $violations); | ||
} | ||
} | ||
} |
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,57 @@ | ||
<?php | ||
|
||
namespace Acme\PizzaBundle\Tests\Entity; | ||
|
||
use | ||
Acme\PizzaBundle\Entity\Order, | ||
Acme\PizzaBundle\Entity\Customer, | ||
Doctrine\Common\Collections\ArrayCollection | ||
; | ||
|
||
class OrderEntityTest extends AbstractEntityTest | ||
{ | ||
public static function provider() | ||
{ | ||
$data = array(); | ||
|
||
$data[] = array( | ||
'properties' => array( | ||
'date' => new \DateTime(), | ||
'customer' => new Customer(), | ||
'items' => new ArrayCollection(), | ||
), | ||
'errors' => array(), | ||
); | ||
|
||
$data[] = array( | ||
'properties' => array(), | ||
'errors' => array( | ||
'customer' => 'This value should not be blank', | ||
), | ||
); | ||
|
||
return $data; | ||
} | ||
|
||
/** | ||
* @dataProvider provider | ||
*/ | ||
public function testValidation(array $properties, array $errors) | ||
{ | ||
$order = new Order(); | ||
|
||
foreach ($properties as $property => $value) { | ||
$order->set($property, $value); | ||
} | ||
|
||
$violations = self::$validator->validate($order); | ||
/* @var $violations \Symfony\Component\Validator\ConstraintViolationList */ | ||
|
||
$this->assertEquals(count($errors), count($violations), (string) $violations); | ||
|
||
foreach ($errors as $property => $message) { | ||
$pattern = sprintf('/\.%s:\s+%s$/m', $property, $message); | ||
$this->assertRegExp($pattern, (string) $violations, $violations); | ||
} | ||
} | ||
} |
Oops, something went wrong.