ObjectTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /*
  3. * This file is part of the phpunit-mock-objects package.
  4. *
  5. * (c) Sebastian Bergmann <sebastian@phpunit.de>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. use PHPUnit\Framework\TestCase;
  11. class Framework_MockObject_Invocation_ObjectTest extends TestCase
  12. {
  13. public function testConstructorRequiresClassAndMethodAndParametersAndObject()
  14. {
  15. $this->assertInstanceOf(
  16. PHPUnit_Framework_MockObject_Invocation_Object::class,
  17. new PHPUnit_Framework_MockObject_Invocation_Object(
  18. 'FooClass',
  19. 'FooMethod',
  20. ['an_argument'],
  21. 'ReturnType',
  22. new stdClass
  23. )
  24. );
  25. }
  26. public function testAllowToGetClassNameSetInConstructor()
  27. {
  28. $invocation = new PHPUnit_Framework_MockObject_Invocation_Object(
  29. 'FooClass',
  30. 'FooMethod',
  31. ['an_argument'],
  32. 'ReturnType',
  33. new stdClass
  34. );
  35. $this->assertSame('FooClass', $invocation->className);
  36. }
  37. public function testAllowToGetMethodNameSetInConstructor()
  38. {
  39. $invocation = new PHPUnit_Framework_MockObject_Invocation_Object(
  40. 'FooClass',
  41. 'FooMethod',
  42. ['an_argument'],
  43. 'ReturnType',
  44. new stdClass
  45. );
  46. $this->assertSame('FooMethod', $invocation->methodName);
  47. }
  48. public function testAllowToGetObjectSetInConstructor()
  49. {
  50. $expectedObject = new stdClass;
  51. $invocation = new PHPUnit_Framework_MockObject_Invocation_Object(
  52. 'FooClass',
  53. 'FooMethod',
  54. ['an_argument'],
  55. 'ReturnType',
  56. $expectedObject
  57. );
  58. $this->assertSame($expectedObject, $invocation->object);
  59. }
  60. public function testAllowToGetMethodParametersSetInConstructor()
  61. {
  62. $expectedParameters = [
  63. 'foo', 5, ['a', 'b'], new stdClass, null, false
  64. ];
  65. $invocation = new PHPUnit_Framework_MockObject_Invocation_Object(
  66. 'FooClass',
  67. 'FooMethod',
  68. $expectedParameters,
  69. 'ReturnType',
  70. new stdClass
  71. );
  72. $this->assertSame($expectedParameters, $invocation->parameters);
  73. }
  74. public function testConstructorAllowToSetFlagCloneObjectsInParameters()
  75. {
  76. $parameters = [new stdClass];
  77. $cloneObjects = true;
  78. $invocation = new PHPUnit_Framework_MockObject_Invocation_Object(
  79. 'FooClass',
  80. 'FooMethod',
  81. $parameters,
  82. 'ReturnType',
  83. new stdClass,
  84. $cloneObjects
  85. );
  86. $this->assertEquals($parameters, $invocation->parameters);
  87. $this->assertNotSame($parameters, $invocation->parameters);
  88. }
  89. public function testAllowToGetReturnTypeSetInConstructor()
  90. {
  91. $expectedReturnType = 'string';
  92. $invocation = new PHPUnit_Framework_MockObject_Invocation_Object(
  93. 'FooClass',
  94. 'FooMethod',
  95. ['an_argument'],
  96. $expectedReturnType,
  97. new stdClass
  98. );
  99. $this->assertSame($expectedReturnType, $invocation->returnType);
  100. }
  101. }