LoaderChainTest.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  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 Symfony\Component\Validator\Tests\Mapping\Loader;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Validator\Mapping\ClassMetadata;
  13. use Symfony\Component\Validator\Mapping\Loader\LoaderChain;
  14. class LoaderChainTest extends TestCase
  15. {
  16. public function testAllLoadersAreCalled()
  17. {
  18. $metadata = new ClassMetadata('\stdClass');
  19. $loader1 = $this->getMockBuilder('Symfony\Component\Validator\Mapping\Loader\LoaderInterface')->getMock();
  20. $loader1->expects($this->once())
  21. ->method('loadClassMetadata')
  22. ->with($this->equalTo($metadata));
  23. $loader2 = $this->getMockBuilder('Symfony\Component\Validator\Mapping\Loader\LoaderInterface')->getMock();
  24. $loader2->expects($this->once())
  25. ->method('loadClassMetadata')
  26. ->with($this->equalTo($metadata));
  27. $chain = new LoaderChain(array(
  28. $loader1,
  29. $loader2,
  30. ));
  31. $chain->loadClassMetadata($metadata);
  32. }
  33. public function testReturnsTrueIfAnyLoaderReturnedTrue()
  34. {
  35. $metadata = new ClassMetadata('\stdClass');
  36. $loader1 = $this->getMockBuilder('Symfony\Component\Validator\Mapping\Loader\LoaderInterface')->getMock();
  37. $loader1->expects($this->any())
  38. ->method('loadClassMetadata')
  39. ->will($this->returnValue(true));
  40. $loader2 = $this->getMockBuilder('Symfony\Component\Validator\Mapping\Loader\LoaderInterface')->getMock();
  41. $loader2->expects($this->any())
  42. ->method('loadClassMetadata')
  43. ->will($this->returnValue(false));
  44. $chain = new LoaderChain(array(
  45. $loader1,
  46. $loader2,
  47. ));
  48. $this->assertTrue($chain->loadClassMetadata($metadata));
  49. }
  50. public function testReturnsFalseIfNoLoaderReturnedTrue()
  51. {
  52. $metadata = new ClassMetadata('\stdClass');
  53. $loader1 = $this->getMockBuilder('Symfony\Component\Validator\Mapping\Loader\LoaderInterface')->getMock();
  54. $loader1->expects($this->any())
  55. ->method('loadClassMetadata')
  56. ->will($this->returnValue(false));
  57. $loader2 = $this->getMockBuilder('Symfony\Component\Validator\Mapping\Loader\LoaderInterface')->getMock();
  58. $loader2->expects($this->any())
  59. ->method('loadClassMetadata')
  60. ->will($this->returnValue(false));
  61. $chain = new LoaderChain(array(
  62. $loader1,
  63. $loader2,
  64. ));
  65. $this->assertFalse($chain->loadClassMetadata($metadata));
  66. }
  67. }