InlineConstraintTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /*
  3. * This file is part of the Sonata package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sonata\AdminBundle\Test\Validator\Constraints;
  11. use Sonata\AdminBundle\Validator\Constraints\InlineConstraint;
  12. /**
  13. * Test for InlineConstraint
  14. *
  15. * @author Andrej Hudec <pulzarraider@gmail.com>
  16. */
  17. class InlineConstraintTest extends \PHPUnit_Framework_TestCase
  18. {
  19. public function testValidatedBy()
  20. {
  21. $constraint = new InlineConstraint(array('service'=>'foo', 'method'=>'bar'));
  22. $this->assertEquals('sonata.admin.validator.inline', $constraint->validatedBy());
  23. }
  24. public function testIsClosure()
  25. {
  26. $constraint = new InlineConstraint(array('service'=>'foo', 'method'=>'bar'));
  27. $this->assertFalse($constraint->isClosure());
  28. $constraint = new InlineConstraint(array('service'=>'foo', 'method'=>function () {}));
  29. $this->assertTrue($constraint->isClosure());
  30. }
  31. public function testGetClosure()
  32. {
  33. $closure = function () {return 'FOO';};
  34. $constraint = new InlineConstraint(array('service'=>'foo', 'method'=>$closure));
  35. $this->assertEquals($closure, $constraint->getClosure());
  36. }
  37. public function testGetTargets()
  38. {
  39. $constraint = new InlineConstraint(array('service'=>'foo', 'method'=>'bar'));
  40. $this->assertEquals(InlineConstraint::CLASS_CONSTRAINT, $constraint->getTargets());
  41. }
  42. public function testGetRequiredOptions()
  43. {
  44. $constraint = new InlineConstraint(array('service'=>'foo', 'method'=>'bar'));
  45. $this->assertEquals(array('service', 'method'), $constraint->getRequiredOptions());
  46. }
  47. public function testGetMethod()
  48. {
  49. $constraint = new InlineConstraint(array('service'=>'foo', 'method'=>'bar'));
  50. $this->assertEquals('bar', $constraint->getMethod());
  51. }
  52. public function testGetService()
  53. {
  54. $constraint = new InlineConstraint(array('service'=>'foo', 'method'=>'bar'));
  55. $this->assertEquals('foo', $constraint->getService());
  56. }
  57. }