ObjectTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. class Framework_MockObject_Invocation_ObjectTest extends PHPUnit_Framework_TestCase
  3. {
  4. public function testConstructorRequiresClassAndMethodAndParametersAndObject()
  5. {
  6. $this->assertInstanceOf(
  7. PHPUnit_Framework_MockObject_Invocation_Object::class,
  8. new PHPUnit_Framework_MockObject_Invocation_Object(
  9. 'FooClass',
  10. 'FooMethod',
  11. ['an_argument'],
  12. 'ReturnType',
  13. new stdClass
  14. )
  15. );
  16. }
  17. public function testAllowToGetClassNameSetInConstructor()
  18. {
  19. $invocation = new PHPUnit_Framework_MockObject_Invocation_Object(
  20. 'FooClass',
  21. 'FooMethod',
  22. ['an_argument'],
  23. 'ReturnType',
  24. new stdClass
  25. );
  26. $this->assertSame('FooClass', $invocation->className);
  27. }
  28. public function testAllowToGetMethodNameSetInConstructor()
  29. {
  30. $invocation = new PHPUnit_Framework_MockObject_Invocation_Object(
  31. 'FooClass',
  32. 'FooMethod',
  33. ['an_argument'],
  34. 'ReturnType',
  35. new stdClass
  36. );
  37. $this->assertSame('FooMethod', $invocation->methodName);
  38. }
  39. public function testAllowToGetObjectSetInConstructor()
  40. {
  41. $expectedObject = new stdClass;
  42. $invocation = new PHPUnit_Framework_MockObject_Invocation_Object(
  43. 'FooClass',
  44. 'FooMethod',
  45. ['an_argument'],
  46. 'ReturnType',
  47. $expectedObject
  48. );
  49. $this->assertSame($expectedObject, $invocation->object);
  50. }
  51. public function testAllowToGetMethodParametersSetInConstructor()
  52. {
  53. $expectedParameters = [
  54. 'foo', 5, ['a', 'b'], new stdClass, null, false
  55. ];
  56. $invocation = new PHPUnit_Framework_MockObject_Invocation_Object(
  57. 'FooClass',
  58. 'FooMethod',
  59. $expectedParameters,
  60. 'ReturnType',
  61. new stdClass
  62. );
  63. $this->assertSame($expectedParameters, $invocation->parameters);
  64. }
  65. public function testConstructorAllowToSetFlagCloneObjectsInParameters()
  66. {
  67. $parameters = [new stdClass];
  68. $cloneObjects = true;
  69. $invocation = new PHPUnit_Framework_MockObject_Invocation_Object(
  70. 'FooClass',
  71. 'FooMethod',
  72. $parameters,
  73. 'ReturnType',
  74. new stdClass,
  75. $cloneObjects
  76. );
  77. $this->assertEquals($parameters, $invocation->parameters);
  78. $this->assertNotSame($parameters, $invocation->parameters);
  79. }
  80. public function testAllowToGetReturnTypeSetInConstructor()
  81. {
  82. $expectedReturnType = 'string';
  83. $invocation = new PHPUnit_Framework_MockObject_Invocation_Object(
  84. 'FooClass',
  85. 'FooMethod',
  86. ['an_argument'],
  87. $expectedReturnType,
  88. new stdClass
  89. );
  90. $this->assertSame($expectedReturnType, $invocation->returnType);
  91. }
  92. }