No Description

NameGeneratorSpec.php 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace spec\Prophecy\Doubler;
  3. use PhpSpec\ObjectBehavior;
  4. class NameGeneratorSpec extends ObjectBehavior
  5. {
  6. /**
  7. * @param \ReflectionClass $class
  8. */
  9. function its_name_generates_name_based_on_simple_class_reflection($class)
  10. {
  11. $class->getName()->willReturn('stdClass');
  12. $this->name($class, array())->shouldStartWith('Double\stdClass\\');
  13. }
  14. /**
  15. * @param \ReflectionClass $class
  16. */
  17. function its_name_generates_name_based_on_namespaced_class_reflection($class)
  18. {
  19. $class->getName()->willReturn('Some\Custom\Class');
  20. $this->name($class, array())->shouldStartWith('Double\Some\Custom\Class\P');
  21. }
  22. /**
  23. * @param \ReflectionClass $interface1
  24. * @param \ReflectionClass $interface2
  25. */
  26. function its_name_generates_name_based_on_interface_shortnames($interface1, $interface2)
  27. {
  28. $interface1->getShortName()->willReturn('HandlerInterface');
  29. $interface2->getShortName()->willReturn('LoaderInterface');
  30. $this->name(null, array($interface1, $interface2))->shouldStartWith(
  31. 'Double\HandlerInterface\LoaderInterface\P'
  32. );
  33. }
  34. function it_generates_proper_name_for_no_class_and_interfaces_list()
  35. {
  36. $this->name(null, array())->shouldStartWith('Double\stdClass\P');
  37. }
  38. /**
  39. * @param \ReflectionClass $class
  40. * @param \ReflectionClass $interface1
  41. * @param \ReflectionClass $interface2
  42. */
  43. function its_name_generates_name_based_only_on_class_if_its_available(
  44. $class, $interface1, $interface2
  45. )
  46. {
  47. $class->getName()->willReturn('Some\Custom\Class');
  48. $interface1->getShortName()->willReturn('HandlerInterface');
  49. $interface2->getShortName()->willReturn('LoaderInterface');
  50. $this->name($class, array($interface1, $interface2))->shouldStartWith(
  51. 'Double\Some\Custom\Class\P'
  52. );
  53. }
  54. public function getMatchers()
  55. {
  56. return array(
  57. 'startWith' => function ($subject, $string) {
  58. return 0 === strpos($subject, $string);
  59. },
  60. );
  61. }
  62. }