ConstraintTraitForV6.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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\Bridge\PhpUnit\Legacy;
  11. use SebastianBergmann\Exporter\Exporter;
  12. /**
  13. * @internal
  14. */
  15. trait ConstraintTraitForV6
  16. {
  17. /**
  18. * @return bool|null
  19. */
  20. public function evaluate($other, $description = '', $returnResult = false)
  21. {
  22. return $this->doEvaluate($other, $description, $returnResult);
  23. }
  24. /**
  25. * @return int
  26. */
  27. public function count()
  28. {
  29. return $this->doCount();
  30. }
  31. /**
  32. * @return string
  33. */
  34. public function toString()
  35. {
  36. return $this->doToString();
  37. }
  38. /**
  39. * @param mixed $other
  40. *
  41. * @return string
  42. */
  43. protected function additionalFailureDescription($other)
  44. {
  45. return $this->doAdditionalFailureDescription($other);
  46. }
  47. /**
  48. * @return Exporter
  49. */
  50. protected function exporter()
  51. {
  52. if (null === $this->exporter) {
  53. $this->exporter = new Exporter();
  54. }
  55. return $this->exporter;
  56. }
  57. /**
  58. * @param mixed $other
  59. *
  60. * @return string
  61. */
  62. protected function failureDescription($other)
  63. {
  64. return $this->doFailureDescription($other);
  65. }
  66. /**
  67. * @param mixed $other
  68. *
  69. * @return bool
  70. */
  71. protected function matches($other)
  72. {
  73. return $this->doMatches($other);
  74. }
  75. private function doAdditionalFailureDescription($other)
  76. {
  77. return '';
  78. }
  79. private function doCount()
  80. {
  81. return 1;
  82. }
  83. private function doEvaluate($other, $description, $returnResult)
  84. {
  85. $success = false;
  86. if ($this->matches($other)) {
  87. $success = true;
  88. }
  89. if ($returnResult) {
  90. return $success;
  91. }
  92. if (!$success) {
  93. $this->fail($other, $description);
  94. }
  95. return null;
  96. }
  97. private function doFailureDescription($other)
  98. {
  99. return $this->exporter()->export($other).' '.$this->toString();
  100. }
  101. private function doMatches($other)
  102. {
  103. return false;
  104. }
  105. private function doToString()
  106. {
  107. return '';
  108. }
  109. }