DiscriminatorTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * File DiscriminatorTest.php
  4. *
  5. * @author Edward Pfremmer <epfremme@nerdery.com>
  6. */
  7. namespace Epfremme\Swagger\Tests\Annotations;
  8. use Epfremme\Swagger\Annotations\Discriminator;
  9. /**
  10. * Class DiscriminatorTest
  11. *
  12. * @package Epfremme\Swagger
  13. * @subPackage Tests\Annotations
  14. */
  15. class DiscriminatorTest extends \PHPUnit_Framework_TestCase
  16. {
  17. /**
  18. * @covers Epfremme\Swagger\Annotations\Discriminator::getClass
  19. */
  20. public function testGetClass()
  21. {
  22. $annotation = new Discriminator();
  23. $annotation->default = 'default';
  24. $annotation->field = 'type';
  25. $annotation->map = [
  26. 'default' => 'Default\Class',
  27. 'type_1' => 'Type\One\Class',
  28. ];
  29. $result = $annotation->getClass([
  30. 'type' => 'type_1'
  31. ]);
  32. $this->assertEquals('Type\One\Class', $result);
  33. }
  34. /**
  35. * @covers Epfremme\Swagger\Annotations\Discriminator::getClass
  36. * @covers Epfremme\Swagger\Annotations\Discriminator::getDefault
  37. */
  38. public function testGetClassDefault()
  39. {
  40. $annotation = new Discriminator();
  41. $annotation->default = 'default';
  42. $annotation->field = 'type';
  43. $annotation->map = [
  44. 'default' => 'Default\Class',
  45. 'type_1' => 'Type\One\Class',
  46. ];
  47. $result = $annotation->getClass([
  48. 'type' => 'type_2'
  49. ]);
  50. $this->assertEquals('Default\Class', $result);
  51. }
  52. /**
  53. * @expectedException \Doctrine\Common\Annotations\AnnotationException
  54. */
  55. public function testGetClassException()
  56. {
  57. $annotation = new Discriminator();
  58. $annotation->default = 'unknown';
  59. $annotation->field = 'type';
  60. $annotation->map = [
  61. 'default' => 'Default\Class',
  62. 'type_1' => 'Type\One\Class',
  63. ];
  64. $annotation->getClass([]);
  65. }
  66. }