InlineConstraintTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /*
  3. * This file is part of the Sonata Project 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->assertSame('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->assertSame($closure, $constraint->getClosure());
  36. }
  37. public function testGetTargets()
  38. {
  39. $constraint = new InlineConstraint(array('service' => 'foo', 'method' => 'bar'));
  40. $this->assertSame(InlineConstraint::CLASS_CONSTRAINT, $constraint->getTargets());
  41. }
  42. public function testGetRequiredOptions()
  43. {
  44. $constraint = new InlineConstraint(array('service' => 'foo', 'method' => 'bar'));
  45. $this->assertSame(array('service', 'method'), $constraint->getRequiredOptions());
  46. }
  47. public function testGetMethod()
  48. {
  49. $constraint = new InlineConstraint(array('service' => 'foo', 'method' => 'bar'));
  50. $this->assertSame('bar', $constraint->getMethod());
  51. }
  52. public function testGetService()
  53. {
  54. $constraint = new InlineConstraint(array('service' => 'foo', 'method' => 'bar'));
  55. $this->assertSame('foo', $constraint->getService());
  56. }
  57. }