IsIdenticalConstraint.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /*
  3. * This file is part of PHP CS Fixer.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. namespace PhpCsFixer\Tests\Test;
  12. use PhpCsFixer\PhpunitConstraintIsIdenticalString\Constraint\IsIdenticalString;
  13. use PHPUnit\Framework\Constraint\IsIdentical as PhpUnitIsIdentical;
  14. /**
  15. * @internal
  16. *
  17. * @todo Remove me when usages will end up in dedicated package.
  18. */
  19. trait IsIdenticalConstraint
  20. {
  21. /**
  22. * @todo Remove me when this class will end up in dedicated package.
  23. *
  24. * @param string $expected
  25. *
  26. * @return IsIdenticalString|\PHPUnit_Framework_Constraint_IsIdentical|PhpUnitIsIdentical
  27. */
  28. private static function createIsIdenticalStringConstraint($expected)
  29. {
  30. $candidate = self::getIsIdenticalStringConstraintClassName();
  31. return new $candidate($expected);
  32. }
  33. /**
  34. * @return string
  35. */
  36. private static function getIsIdenticalStringConstraintClassName()
  37. {
  38. foreach ([
  39. IsIdenticalString::class,
  40. PhpUnitIsIdentical::class,
  41. 'PHPUnit_Framework_Constraint_IsIdentical',
  42. ] as $className) {
  43. if (class_exists($className)) {
  44. return $className;
  45. }
  46. }
  47. throw new \RuntimeException('PHPUnit not installed?!');
  48. }
  49. }