NameGeneratorSpec.php 1.9 KB

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