ObjectStateTokenSpec.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace spec\Prophecy\Argument\Token;
  3. use PhpSpec\ObjectBehavior;
  4. class ObjectStateTokenSpec extends ObjectBehavior
  5. {
  6. function let()
  7. {
  8. $this->beConstructedWith('getName', 'stdClass');
  9. }
  10. function it_implements_TokenInterface()
  11. {
  12. $this->shouldBeAnInstanceOf('Prophecy\Argument\Token\TokenInterface');
  13. }
  14. function it_is_not_last()
  15. {
  16. $this->shouldNotBeLast();
  17. }
  18. function it_scores_8_if_argument_object_has_specific_method_state(\ReflectionClass $reflection)
  19. {
  20. $reflection->getName()->willReturn('stdClass');
  21. $this->scoreArgument($reflection)->shouldReturn(8);
  22. }
  23. function it_scores_8_if_argument_object_has_specific_property_state(\stdClass $class)
  24. {
  25. $class->getName = 'stdClass';
  26. $this->scoreArgument($class)->shouldReturn(8);
  27. }
  28. function it_does_not_score_if_argument_method_state_does_not_match()
  29. {
  30. $value = new ObjectStateTokenFixtureB('ABC');
  31. $value2 = new ObjectStateTokenFixtureB('CBA');
  32. $this->beConstructedWith('getSelf', $value);
  33. $this->scoreArgument($value2)->shouldReturn(false);
  34. }
  35. function it_does_not_score_if_argument_property_state_does_not_match(\stdClass $class)
  36. {
  37. $class->getName = 'SplFileInfo';
  38. $this->scoreArgument($class)->shouldReturn(false);
  39. }
  40. function it_does_not_score_if_argument_object_does_not_have_method_or_property(ObjectStateTokenFixtureA $class)
  41. {
  42. $this->scoreArgument($class)->shouldReturn(false);
  43. }
  44. function it_does_not_score_if_argument_is_not_object()
  45. {
  46. $this->scoreArgument(42)->shouldReturn(false);
  47. }
  48. function it_has_simple_string_representation()
  49. {
  50. $this->__toString()->shouldReturn('state(getName(), "stdClass")');
  51. }
  52. }
  53. class ObjectStateTokenFixtureA
  54. {
  55. public $errors;
  56. }
  57. class ObjectStateTokenFixtureB extends ObjectStateTokenFixtureA
  58. {
  59. public $errors;
  60. public $value = null;
  61. public function __construct($value)
  62. {
  63. $this->value = $value;
  64. }
  65. public function getSelf()
  66. {
  67. return $this;
  68. }
  69. }